nodebb-plugin-ezoic-infinite 1.5.56 → 1.5.58

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 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.5.56",
3
+ "version": "1.5.58",
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
@@ -44,9 +44,24 @@ function primePool(ids) {
44
44
  try {
45
45
  if (!ids || !ids.length) return;
46
46
  const pool = ensurePool();
47
+
48
+ // Normalize and compute bounds
49
+ const arr = [];
47
50
  for (const v of ids) {
48
- const id = parseInt(v, 10);
49
- if (!Number.isFinite(id) || id <= 0) continue;
51
+ const n = parseInt(v, 10);
52
+ if (Number.isFinite(n) && n > 0) arr.push(n);
53
+ }
54
+ if (!arr.length) return;
55
+
56
+ let min = arr[0], max = arr[0];
57
+ for (const n of arr) { if (n < min) min = n; if (n > max) max = n; }
58
+
59
+ // Ezoic sometimes touches ids in a contiguous range. If the configured list
60
+ // looks like a range, pre-create all ids between min..max (bounded).
61
+ const RANGE_LIMIT = 2000;
62
+ const useRange = (max - min) <= RANGE_LIMIT;
63
+
64
+ const ensureOne = (id) => {
50
65
  const domId = `${PLACEHOLDER_PREFIX}${id}`;
51
66
  let ph = document.getElementById(domId);
52
67
  if (!ph) {
@@ -57,6 +72,12 @@ function primePool(ids) {
57
72
  } else if (!ph.isConnected) {
58
73
  pool.appendChild(ph);
59
74
  }
75
+ };
76
+
77
+ if (useRange) {
78
+ for (let id = min; id <= max; id++) ensureOne(id);
79
+ } else {
80
+ for (const id of arr) ensureOne(id);
60
81
  }
61
82
  } catch (e) {}
62
83
  }
@@ -225,11 +246,10 @@ function parkPlaceholderFromWrap(wrap) {
225
246
 
226
247
  function parsePool(raw) {
227
248
  if (!raw) return [];
228
- const lines = String(raw)
229
- .split(/\r?\n/)
230
- .map(s => s.trim())
231
- .filter(Boolean);
232
- return uniqInts(lines);
249
+ // Accept newline, comma, semicolon, space separated lists.
250
+ // Some ACP inputs may be stored as "611,612,613" in a single line.
251
+ const tokens = String(raw).match(/\d+/g) || [];
252
+ return uniqInts(tokens);
233
253
  }
234
254
 
235
255
  function getPageKey() {
@@ -689,14 +709,16 @@ function startShow(id) {
689
709
  const ph = document.getElementById(domId);
690
710
  if (!ph || !ph.isConnected) return;
691
711
 
692
- // If this id was used before, destroy safely using full DOM id.
712
+ // If this id was used before, destroy it first to avoid "already defined".
713
+ // Then schedule showAds on the next tick (gives Ezoic time to clear state).
693
714
  if (state.usedOnce && state.usedOnce.has(id)) {
694
715
  safeDestroyById(id);
716
+ setTimeout(() => { try { ez.showAds(id); } catch (e) {} }, 0);
717
+ } else {
718
+ // First time: show immediately
719
+ ez.showAds(id);
695
720
  }
696
721
 
697
- // showAds is patched to ignore missing placeholders and repeated defines.
698
- ez.showAds(id);
699
-
700
722
  try { state.usedOnce && state.usedOnce.add(id); } catch (e) {}
701
723
  } catch (e) {}
702
724
  finally {