nodebb-plugin-ezoic-infinite 1.8.43 → 1.8.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 +44 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.8.43",
3
+ "version": "1.8.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
@@ -346,16 +346,27 @@
346
346
 
347
347
  function scheduleEmptyCheck(id) {
348
348
  const showTs = now();
349
- setTimeout(() => {
350
- try {
351
- const ph = document.getElementById(`${PH_PREFIX}${id}`);
352
- const wrap = ph?.closest(`.${WRAP_CLASS}`);
353
- if (!wrap || !ph?.isConnected) return;
354
- if (parseInt(wrap.getAttribute(ATTR.SHOWN) || '0', 10) > showTs) return;
355
- if (clearEmptyIfFilled(wrap)) return;
356
- wrap.classList.add('is-empty');
357
- } catch (_) {}
358
- }, TIMING.EMPTY_CHECK_MS);
349
+ // Check at 30s, then again at 60s — very conservative to avoid
350
+ // collapsing slow-loading ads
351
+ for (const delay of [30_000, 60_000]) {
352
+ setTimeout(() => {
353
+ try {
354
+ const ph = document.getElementById(`${PH_PREFIX}${id}`);
355
+ const wrap = ph?.closest(`.${WRAP_CLASS}`);
356
+ if (!wrap || !ph?.isConnected) return;
357
+ // Don't collapse if a newer show happened
358
+ if (parseInt(wrap.getAttribute(ATTR.SHOWN) || '0', 10) > showTs) return;
359
+ // If already collapsed or uncollapsed, skip
360
+ if (clearEmptyIfFilled(wrap)) return;
361
+ // Don't collapse if there's any GPT slot, even unfilled
362
+ // (GPT may still be processing the ad request)
363
+ if (ph.querySelector('[id^="div-gpt-ad"]')) return;
364
+ // Don't collapse if there's any child with meaningful height
365
+ if (ph.offsetHeight > 10) return;
366
+ wrap.classList.add('is-empty');
367
+ } catch (_) {}
368
+ }, delay);
369
+ }
359
370
  }
360
371
 
361
372
  // ── Recycling ──────────────────────────────────────────────────────────────
@@ -677,7 +688,10 @@
677
688
  step();
678
689
  }
679
690
 
680
- // ── Cleanup ────────────────────────────────────────────────────────────────
691
+ // ── Cleanup on navigation ────────────────────────────────────────────────
692
+ //
693
+ // Only runs on actual page transitions (pageKey changes).
694
+ // Uses destroyAll() to properly clean up Ezoic state before removing DOM.
681
695
 
682
696
  function cleanup() {
683
697
  state.blockedUntil = now() + TIMING.BLOCK_DURATION_MS;
@@ -686,6 +700,14 @@
686
700
  if (state.ezFlushTimer) { clearTimeout(state.ezFlushTimer); state.ezFlushTimer = null; }
687
701
  state.ezBatch.clear();
688
702
 
703
+ // Tell Ezoic to destroy all its placeholders BEFORE we remove DOM
704
+ try {
705
+ const ez = window.ezstandalone;
706
+ if (typeof ez?.destroyAll === 'function') {
707
+ ez.destroyAll();
708
+ }
709
+ } catch (_) {}
710
+
689
711
  mutate(() => {
690
712
  for (const w of document.querySelectorAll(`.${WRAP_CLASS}`)) dropWrap(w);
691
713
  });
@@ -882,7 +904,17 @@
882
904
  const $ = window.jQuery;
883
905
  if (!$) return;
884
906
  $(window).off('.nbbEzoic');
885
- $(window).on('action:ajaxify.start.nbbEzoic', cleanup);
907
+ $(window).on('action:ajaxify.start.nbbEzoic', (ev, data) => {
908
+ // Only cleanup if navigating to a different page
909
+ // NodeBB fires ajaxify.start for pagination/sorting on the same page
910
+ const targetUrl = data?.url || data?.tpl_url || '';
911
+ const currentPath = location.pathname.replace(/^\//, '');
912
+ // If the URL is basically the same (ignoring query/hash), skip cleanup
913
+ if (targetUrl && targetUrl.replace(/[?#].*$/, '') === currentPath.replace(/[?#].*$/, '')) {
914
+ return;
915
+ }
916
+ cleanup();
917
+ });
886
918
  $(window).on('action:ajaxify.end.nbbEzoic', () => {
887
919
  state.pageKey = pageKey();
888
920
  state.kind = null;