nodebb-plugin-ezoic-infinite 1.8.90 → 1.8.91

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 +42 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.8.90",
3
+ "version": "1.8.91",
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
@@ -886,25 +886,56 @@
886
886
 
887
887
  // Retry boot: sa.min.js async + Cloudflare Rocket Loader + NodeBB SPA
888
888
  // can cause client.js to boot before DOM/Ezoic are ready.
889
- // Retries stop once ads are mounted or after ~10s.
890
- // If Ezoic defineScript failed (CMP race on first load), reload sa.min.js once.
889
+ //
890
+ // Two reload cases:
891
+ // 1. sa.min.js never injected (Rocket Loader stripped it) — reload immediately.
892
+ // 2. Cold-start crash: first visit with no Ezoic cookies causes sa.min.js to set
893
+ // loadingStatus='LOADING' but never reach 'complete' (_ezaq.ab_test_id undefined
894
+ // in ez-standalone.js → onStandaloneLoadEvent crash). After ~6s, remove and reload
895
+ // sa.min.js; Ezoic's partial first-run state may let the second run succeed.
896
+ // Once recovered, re-enqueue all mounted placeholders so showAds() fires.
891
897
  let _retries = 0;
892
898
  let _scriptReloaded = false;
899
+ let _postReloadShown = false;
893
900
  function retryBoot() {
894
- if (_retries >= 12 || S.mountedIds.size > 0) return;
901
+ if (_retries >= 12) return;
895
902
  _retries++;
896
903
  patchShowAds();
897
904
 
898
- // Reload sa.min.js only if Ezoic never initialized at all (no loadingStatus)
899
- // AND sa.min.js is not already present in the DOM (to avoid duplicates on first load
900
- // when the script is injected server-side but loadingStatus hasn't been set yet).
901
- // Do NOT reload when loadingStatus === 'complete' (post-defineScript-failure):
902
- // that would trigger a second defineScript failed error.
903
- if (!_scriptReloaded && _retries <= 3) {
904
- const ez = window.ezstandalone;
905
- if (!ez?.loadingStatus && !document.querySelector('script[src*="sa.min.js"]')) {
905
+ const ez = window.ezstandalone;
906
+ const status = ez?.loadingStatus;
907
+
908
+ // After reload: once Ezoic reaches 'complete', re-call showAds for all mounted placeholders
909
+ if (_scriptReloaded && !_postReloadShown && status === 'complete') {
910
+ _postReloadShown = true;
911
+ for (const id of S.mountedIds) { try { enqueueShow(id); } catch (_) {} }
912
+ return;
913
+ }
914
+
915
+ // Normal exit: placeholders mounted, no reload triggered (healthy load)
916
+ if (S.mountedIds.size > 0 && !_scriptReloaded) return;
917
+ // Exit once reload is done and re-show has been triggered
918
+ if (_scriptReloaded && _postReloadShown) return;
919
+
920
+ if (!_scriptReloaded) {
921
+ // Case 1: sa.min.js never injected (Rocket Loader stripped it, etc.)
922
+ const neverInjected = !status && !document.querySelector('script[src*="sa.min.js"]') && _retries <= 3;
923
+ // Case 2: cold-start crash — loadingStatus stuck before 'complete' after enough wait.
924
+ // Do NOT reload when status==='complete' (post-defineScript-failure would re-trigger).
925
+ const anyFilled = !!document.querySelector(`.${WRAP_CLASS} ${FILL_SEL}`);
926
+ const crashed = _retries >= 8 && !anyFilled && status && status !== 'complete';
927
+ if (neverInjected || crashed) {
906
928
  _scriptReloaded = true;
907
929
  try {
930
+ if (crashed) {
931
+ // Remove the broken script before re-adding to avoid a duplicate
932
+ const old = document.querySelector('script[src*="sa.min.js"]');
933
+ if (old) old.remove();
934
+ // Reset ezstandalone to initial state, preserving queued cmd items
935
+ const savedCmd = Array.isArray(ez?.cmd) ? [...ez.cmd] : [];
936
+ window.ezstandalone = { cmd: savedCmd };
937
+ window.__nbbEzPatched = false;
938
+ }
908
939
  const s = document.createElement('script');
909
940
  s.setAttribute('data-cfasync', 'false');
910
941
  s.src = '//www.ezojs.com/ezoic/sa.min.js';