nodebb-plugin-ezoic-infinite 1.1.2 → 1.1.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 +35 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.1.2",
3
+ "version": "1.1.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
@@ -14,6 +14,39 @@
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
+
17
50
  const state = {
18
51
  pageKey: null,
19
52
  cfg: null,
@@ -444,6 +477,7 @@
444
477
  });
445
478
 
446
479
  $w.on('action:ajaxify.end.ezoicInfinite', () => {
480
+ patchShowAdsOnce();
447
481
  run();
448
482
  setTimeout(run, 200);
449
483
  setTimeout(run, 800);
@@ -465,6 +499,7 @@
465
499
  }
466
500
 
467
501
  // Boot
502
+ patchShowAdsOnce();
468
503
  cleanupForNewPage();
469
504
  bindNodeBBEvents();
470
505