nodebb-plugin-ezoic-infinite 1.5.43 → 1.5.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +17 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.5.43",
3
+ "version": "1.5.44",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -117,6 +117,7 @@ function mutationHasRelevantAddedNodes(mutations) {
117
117
  pageKey: null,
118
118
  cfg: null,
119
119
 
120
+ navSeq: 0,
120
121
  // Full lists (never consumed) + cursors for round-robin reuse
121
122
  allTopics: [],
122
123
  allPosts: [],
@@ -266,6 +267,7 @@ function mutationHasRelevantAddedNodes(mutations) {
266
267
 
267
268
  ez.showAds = function (...args) {
268
269
  if (isBlocked()) return;
270
+ if (seq !== state.navSeq) return;
269
271
 
270
272
  let ids = [];
271
273
  if (args.length === 1 && Array.isArray(args[0])) ids = args[0];
@@ -762,6 +764,7 @@ function drainQueue() {
762
764
  function startShow(id) {
763
765
  if (!id || isBlocked()) return;
764
766
 
767
+ const seq = state.navSeq;
765
768
  state.inflight++;
766
769
  let released = false;
767
770
  const release = () => {
@@ -799,6 +802,7 @@ function startShow(id) {
799
802
  const doShow = () => {
800
803
  // Re-check right before showing: the placeholder can disappear between
801
804
  // scheduling and execution (ajaxify/infinite scroll DOM churn).
805
+ if (seq !== state.navSeq) { try { clearTimeout(hardTimer); } catch (e) {} release(); return; }
802
806
  const phNow = document.getElementById(domId);
803
807
  if (!phNow || !phNow.isConnected) {
804
808
  try { clearTimeout(hardTimer); } catch (e) {}
@@ -812,7 +816,13 @@ function startShow(id) {
812
816
  }
813
817
  } catch (e) {}
814
818
 
815
- try { ez.showAds(id); } catch (e) {}
819
+ // Let the DOM settle for one macrotask; NodeBB can reflow/replace nodes right after mutations.
820
+ setTimeout(() => {
821
+ if (seq !== state.navSeq) { return; }
822
+ const phFinal = document.getElementById(domId);
823
+ if (!phFinal || !phFinal.isConnected) { return; }
824
+ try { ez.showAds(id); } catch (e) {}
825
+ }, 0);
816
826
  try { state.usedOnce && state.usedOnce.add(id); } catch (e) {}
817
827
 
818
828
  setTimeout(() => { clearTimeout(hardTimer); release(); }, 650);
@@ -1075,6 +1085,12 @@ function startShow(id) {
1075
1085
  function cleanup() {
1076
1086
  blockedUntil = Date.now() + 1200;
1077
1087
 
1088
+ // invalidate any queued showAds from previous view
1089
+ state.navSeq++;
1090
+ state.inflight = 0;
1091
+ state.pending = [];
1092
+ state.pendingSet = new Set();
1093
+
1078
1094
  // remove all wrappers
1079
1095
  try {
1080
1096
  withInternalDomChange(() => {