nodebb-plugin-ezoic-infinite 1.8.2 → 1.8.3

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 +33 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
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
@@ -138,7 +138,8 @@
138
138
  destroyPendingSet: new Set(),
139
139
  sweepQueued: false,
140
140
  wrapByKey: new Map(), // anchorKey → wrap DOM node
141
- ezActiveIds: new Set(), // ids déjà passés à showAds/displayMore
141
+ ezActiveIds: new Set(), // ids actifs côté plugin (wrap présent / récemment show)
142
+ ezShownSinceDestroy: new Set(), // ids déjà show depuis le dernier destroy Ezoic
142
143
  scrollDir: 1, // 1=bas, -1=haut
143
144
  scrollSpeed: 0, // px/s approx (EMA)
144
145
  lastScrollY: 0,
@@ -240,6 +241,24 @@ function destroyEzoicId(id) {
240
241
  scheduleDestroyFlush();
241
242
  }
242
243
 
244
+ function destroyBeforeReuse(ids) {
245
+ const out = [];
246
+ const toDestroy = [];
247
+ const seen = new Set();
248
+ for (const raw of (ids || [])) {
249
+ const id = parseInt(raw, 10);
250
+ if (!Number.isFinite(id) || id <= 0 || seen.has(id)) continue;
251
+ seen.add(id);
252
+ out.push(id);
253
+ if (S.ezShownSinceDestroy.has(id)) toDestroy.push(id);
254
+ }
255
+ if (toDestroy.length) {
256
+ try { window.ezstandalone?.destroyPlaceholders?.(toDestroy); } catch (_) {}
257
+ for (const id of toDestroy) S.ezShownSinceDestroy.delete(id);
258
+ }
259
+ return out;
260
+ }
261
+
243
262
 
244
263
  // ── Config ─────────────────────────────────────────────────────────────────
245
264
 
@@ -484,11 +503,15 @@ function recycleAndMove(klass, targetEl, newKey) {
484
503
  S.wrapByKey.set(newKey, best);
485
504
 
486
505
  const doDestroy = () => {
487
- if (S.ezActiveIds.has(id)) destroyEzoicId(id);
506
+ if (S.ezShownSinceDestroy.has(id)) {
507
+ try { ez.destroyPlaceholders([id]); } catch (_) {}
508
+ S.ezShownSinceDestroy.delete(id);
509
+ }
510
+ S.ezActiveIds.delete(id);
488
511
  setTimeout(doDefine, 330);
489
512
  };
490
513
  const doDefine = () => { try { ez.define([id]); } catch (_) {} setTimeout(doDisplay, 300); };
491
- const doDisplay = () => { try { ez.displayMore([id]); S.ezActiveIds.add(id); } catch (_) {} };
514
+ const doDisplay = () => { try { ez.displayMore([id]); S.ezActiveIds.add(id); S.ezShownSinceDestroy.add(id); } catch (_) {} };
492
515
  try { (typeof ez.cmd?.push === 'function') ? ez.cmd.push(doDestroy) : doDestroy(); } catch (_) {}
493
516
 
494
517
  return { id, wrap: best };
@@ -529,7 +552,7 @@ function recycleAndMove(klass, targetEl, newKey) {
529
552
  const ph = w.querySelector(`[id^="${PH_PREFIX}"]`);
530
553
  if (ph instanceof Element) S.io?.unobserve(ph);
531
554
  const id = parseInt(w.getAttribute(A_WRAPID), 10);
532
- if (Number.isFinite(id)) { destroyEzoicId(id); S.mountedIds.delete(id); }
555
+ if (Number.isFinite(id)) { S.ezActiveIds.delete(id); S.mountedIds.delete(id); }
533
556
  const key = w.getAttribute(A_ANCHOR);
534
557
  if (key && S.wrapByKey.get(key) === w) S.wrapByKey.delete(key);
535
558
  w.remove();
@@ -723,9 +746,12 @@ function startShowBatch(ids) {
723
746
  window.ezstandalone = window.ezstandalone || {};
724
747
  const ez = window.ezstandalone;
725
748
  const doShow = () => {
726
- try { ez.showAds(...valid); } catch (_) {}
727
- for (const id of valid) {
749
+ const prepared = destroyBeforeReuse(valid);
750
+ if (!prepared.length) { setTimeout(() => { clearTimeout(timer); release(); }, SHOW_RELEASE_MS); return; }
751
+ try { ez.showAds(...prepared); } catch (_) {}
752
+ for (const id of prepared) {
728
753
  S.ezActiveIds.add(id);
754
+ S.ezShownSinceDestroy.add(id);
729
755
  }
730
756
  setTimeout(() => { clearTimeout(timer); release(); }, SHOW_RELEASE_MS);
731
757
  };
@@ -868,6 +894,7 @@ function startShowBatch(ids) {
868
894
  S.lastShow.clear();
869
895
  S.wrapByKey.clear();
870
896
  S.ezActiveIds.clear();
897
+ S.ezShownSinceDestroy.clear();
871
898
  S.inflight = 0;
872
899
  S.pending = [];
873
900
  S.pendingSet.clear();