nodebb-plugin-ezoic-infinite 1.1.3 → 1.1.4

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 +36 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
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
@@ -14,39 +14,6 @@
14
14
  const WRAP_CLASS = 'ezoic-ad';
15
15
  const PLACEHOLDER_PREFIX = 'ezoic-pub-ad-placeholder-';
16
16
 
17
-
18
- function patchShowAdsOnce() {
19
- try {
20
- window.ezstandalone = window.ezstandalone || {};
21
- if (window.ezstandalone.__nodebbEzoicPatched) return;
22
- window.ezstandalone.__nodebbEzoicPatched = true;
23
-
24
- const orig = window.ezstandalone.showAds;
25
- if (typeof orig !== 'function') return;
26
-
27
- window.ezstandalone.showAds = function patchedShowAds(arg) {
28
- // If someone calls showAds([ids...]), split into individual calls to avoid Ezoic "loadMore" errors
29
- // and to avoid duplicates/ordering issues.
30
- try {
31
- if (Array.isArray(arg)) {
32
- const uniq = [];
33
- const seen = new Set();
34
- for (const v of arg) {
35
- const n = parseInt(v, 10);
36
- if (Number.isFinite(n) && n > 0 && !seen.has(n)) { seen.add(n); uniq.push(n); }
37
- }
38
- uniq.forEach((id) => {
39
- try { orig.call(window.ezstandalone, id); } catch (e) {}
40
- });
41
- return;
42
- }
43
- } catch (e) {}
44
-
45
- return orig.apply(window.ezstandalone, arguments);
46
- };
47
- } catch (e) {}
48
- }
49
-
50
17
  const state = {
51
18
  pageKey: null,
52
19
  cfg: null,
@@ -64,6 +31,40 @@
64
31
  observers: {},
65
32
  };
66
33
 
34
+ function patchShowAds() {
35
+ try {
36
+ window.ezstandalone = window.ezstandalone || {};
37
+ const ez = window.ezstandalone;
38
+ if (ez.__nodebbEzoicPatched) return;
39
+ if (typeof ez.showAds !== 'function') return;
40
+
41
+ ez.__nodebbEzoicPatched = true;
42
+ const orig = ez.showAds;
43
+
44
+ ez.showAds = function showAdsPatched(arg) {
45
+ if (Array.isArray(arg)) {
46
+ // This batch call is NOT coming from this plugin (we never call showAds with arrays).
47
+ // Split into individual calls to avoid Ezoic loadMore/placeholder issues.
48
+ try {
49
+ if (window.__ezoicInfiniteDebug) {
50
+ console.warn('[ezoic-infinite] showAds(batch) detected. Source stack:', new Error().stack);
51
+ }
52
+ } catch (e) {}
53
+
54
+ const seen = new Set();
55
+ for (const v of arg) {
56
+ const id = parseInt(v, 10);
57
+ if (!Number.isFinite(id) || id <= 0 || seen.has(id)) continue;
58
+ seen.add(id);
59
+ try { orig.call(ez, id); } catch (e) {}
60
+ }
61
+ return;
62
+ }
63
+ return orig.apply(ez, arguments);
64
+ };
65
+ } catch (e) {}
66
+ }
67
+
67
68
  function normalizeBool(v) {
68
69
  return v === true || v === 'true' || v === 1 || v === '1' || v === 'on';
69
70
  }
@@ -477,7 +478,7 @@
477
478
  });
478
479
 
479
480
  $w.on('action:ajaxify.end.ezoicInfinite', () => {
480
- patchShowAdsOnce();
481
+ patchShowAds();
481
482
  run();
482
483
  setTimeout(run, 200);
483
484
  setTimeout(run, 800);
@@ -499,7 +500,7 @@
499
500
  }
500
501
 
501
502
  // Boot
502
- patchShowAdsOnce();
503
+ patchShowAds();
503
504
  cleanupForNewPage();
504
505
  bindNodeBBEvents();
505
506