nodebb-plugin-ezoic-infinite 1.5.57 → 1.5.59

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 +39 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.5.57",
3
+ "version": "1.5.59",
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
@@ -13,9 +13,24 @@
13
13
  // and eliminates "HTML element with id ... does not exist" noise.
14
14
  const POOL_ID = 'ezoic-placeholder-pool';
15
15
 
16
+ function isInPool(el) {
17
+ try { return !!(el && el.closest && el.closest('#' + POOL_ID)); } catch (e) { return false; }
18
+ }
19
+
20
+ function isPlaceholderInUse(ph) {
21
+ // In use = connected AND not parked in our offscreen pool.
22
+ try { return !!(ph && ph.isConnected && !isInPool(ph)); } catch (e) { return false; }
23
+ }
24
+
16
25
  function ensurePool() {
17
26
  let pool = document.getElementById(POOL_ID);
18
- if (pool) return pool;
27
+ if (pool) {
28
+ // In rare cases (aggressive SPA navigation), the pool may get detached.
29
+ if (!pool.isConnected) {
30
+ try { (document.documentElement || document.body).appendChild(pool); } catch (e) {}
31
+ }
32
+ return pool;
33
+ }
19
34
  pool = document.createElement('div');
20
35
  pool.id = POOL_ID;
21
36
  pool.style.position = 'absolute';
@@ -77,6 +92,7 @@ function acquirePlaceholder(id) {
77
92
  if (ph.dataset) {
78
93
  ph.dataset.ezRequested = '0';
79
94
  ph.dataset.ezDefined = '0';
95
+ ph.dataset.ezActive = '0';
80
96
  }
81
97
  } catch (e) {}
82
98
  return ph;
@@ -87,6 +103,7 @@ function parkPlaceholderFromWrap(wrap) {
87
103
  const ph = wrap && wrap.querySelector ? wrap.querySelector(`[id^="${PLACEHOLDER_PREFIX}"]`) : null;
88
104
  if (!ph) return;
89
105
  try { if (state && state.io) state.io.unobserve(ph); } catch (e) {}
106
+ try { if (ph.dataset) ph.dataset.ezActive = '0'; } catch (e) {}
90
107
  ensurePool().appendChild(ph);
91
108
  } catch (e) {}
92
109
  }
@@ -322,8 +339,24 @@ function parkPlaceholderFromWrap(wrap) {
322
339
  if (!Number.isFinite(id) || id <= 0 || seen.has(id)) continue;
323
340
 
324
341
  const domId = `${PLACEHOLDER_PREFIX}${id}`;
325
- const ph = document.getElementById(domId);
326
- if (!ph || !ph.isConnected) continue;
342
+ let ph = document.getElementById(domId);
343
+ if (!ph || !ph.isConnected) {
344
+ // If Ezoic (or another script) tries to show an id we haven't injected yet,
345
+ // create the placeholder in the offscreen pool so it exists, but don't load.
346
+ try {
347
+ ph = document.createElement('div');
348
+ ph.id = domId;
349
+ ph.setAttribute('data-ezoic-id', String(id));
350
+ if (ph.dataset) ph.dataset.ezActive = '0';
351
+ ensurePool().appendChild(ph);
352
+ } catch (e) {}
353
+ continue;
354
+ }
355
+
356
+ // Only allow loads for placeholders actively injected into the page (not parked in the pool)
357
+ // and currently marked active.
358
+ if (!isPlaceholderInUse(ph)) continue;
359
+ if (ph.dataset && ph.dataset.ezActive !== '1') continue;
327
360
 
328
361
  // Prevent repeated "define" attempts on the same placeholder while it remains in DOM.
329
362
  if (ph.dataset && (ph.dataset.ezRequested === '1' || ph.dataset.ezDefined === '1')) continue;
@@ -546,6 +579,7 @@ function buildWrap(id, kindClass, afterPos) {
546
579
  wrap.style.width = '100%';
547
580
 
548
581
  const ph = acquirePlaceholder(id);
582
+ try { if (ph.dataset) ph.dataset.ezActive = '1'; } catch (e) {}
549
583
  wrap.appendChild(ph);
550
584
 
551
585
  return wrap;
@@ -561,7 +595,7 @@ function buildWrap(id, kindClass, afterPos) {
561
595
  if (insertingIds.has(id)) return null;
562
596
 
563
597
  const existingPh = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
564
- if (existingPh && existingPh.isConnected) return null;
598
+ if (existingPh && isPlaceholderInUse(existingPh)) return null;
565
599
 
566
600
  insertingIds.add(id);
567
601
  try {
@@ -584,7 +618,7 @@ function buildWrap(id, kindClass, afterPos) {
584
618
 
585
619
  const id = allIds[idx];
586
620
  const ph = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
587
- if (ph && ph.isConnected) continue;
621
+ if (ph && isPlaceholderInUse(ph)) continue;
588
622
 
589
623
  return id;
590
624
  }