nodebb-plugin-ezoic-infinite 1.5.53 → 1.5.55
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.
- package/package.json +1 -1
- package/public/client.js +61 -4
- package/public/style.css +2 -0
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -7,6 +7,57 @@
|
|
|
7
7
|
const WRAP_CLASS = 'ezoic-ad';
|
|
8
8
|
const PLACEHOLDER_PREFIX = 'ezoic-pub-ad-placeholder-';
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
// Offscreen pool to keep placeholder elements alive across ajaxify/navigation.
|
|
12
|
+
// This prevents Ezoic from trying to define ids that are not currently injected,
|
|
13
|
+
// and eliminates "HTML element with id ... does not exist" noise.
|
|
14
|
+
const POOL_ID = 'ezoic-placeholder-pool';
|
|
15
|
+
|
|
16
|
+
function ensurePool() {
|
|
17
|
+
let pool = document.getElementById(POOL_ID);
|
|
18
|
+
if (pool) return pool;
|
|
19
|
+
pool = document.createElement('div');
|
|
20
|
+
pool.id = POOL_ID;
|
|
21
|
+
pool.style.position = 'absolute';
|
|
22
|
+
pool.style.left = '-99999px';
|
|
23
|
+
pool.style.top = '0';
|
|
24
|
+
pool.style.width = '1px';
|
|
25
|
+
pool.style.height = '1px';
|
|
26
|
+
pool.style.overflow = 'hidden';
|
|
27
|
+
pool.setAttribute('aria-hidden', 'true');
|
|
28
|
+
try { (document.body || document.documentElement).appendChild(pool); } catch (e) {}
|
|
29
|
+
return pool;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function acquirePlaceholder(id) {
|
|
33
|
+
const domId = `${PLACEHOLDER_PREFIX}${id}`;
|
|
34
|
+
let ph = document.getElementById(domId);
|
|
35
|
+
if (!ph) {
|
|
36
|
+
ph = document.createElement('div');
|
|
37
|
+
ph.id = domId;
|
|
38
|
+
ph.setAttribute('data-ezoic-id', String(id));
|
|
39
|
+
ensurePool().appendChild(ph);
|
|
40
|
+
}
|
|
41
|
+
// Detach from wherever it currently is (pool or a previous wrap)
|
|
42
|
+
try { if (ph.parentNode) ph.parentNode.removeChild(ph); } catch (e) {}
|
|
43
|
+
// Clear request/defined flags when reusing
|
|
44
|
+
try {
|
|
45
|
+
if (ph.dataset) {
|
|
46
|
+
ph.dataset.ezRequested = '0';
|
|
47
|
+
ph.dataset.ezDefined = '0';
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {}
|
|
50
|
+
return ph;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function parkPlaceholderFromWrap(wrap) {
|
|
54
|
+
try {
|
|
55
|
+
const ph = wrap && wrap.querySelector ? wrap.querySelector(`[id^="${PLACEHOLDER_PREFIX}"]`) : null;
|
|
56
|
+
if (!ph) return;
|
|
57
|
+
try { if (state && state.io) state.io.unobserve(ph); } catch (e) {}
|
|
58
|
+
ensurePool().appendChild(ph);
|
|
59
|
+
} catch (e) {}
|
|
60
|
+
}
|
|
10
61
|
// Insert at most N ads per run to keep the UI smooth on infinite scroll
|
|
11
62
|
const MAX_INSERTS_PER_RUN = 3;
|
|
12
63
|
|
|
@@ -386,10 +437,15 @@ function withInternalDomChange(fn) {
|
|
|
386
437
|
try {
|
|
387
438
|
const domId = `${PLACEHOLDER_PREFIX}${id}`;
|
|
388
439
|
const ph = document.getElementById(domId);
|
|
389
|
-
|
|
440
|
+
|
|
441
|
+
// If the element is already gone, do NOT call destroyPlaceholders (Ezoic will log "does not exist").
|
|
442
|
+
if (!ph || !ph.isConnected) return;
|
|
443
|
+
|
|
444
|
+
if (ph.dataset) {
|
|
390
445
|
delete ph.dataset.ezDefined;
|
|
391
446
|
delete ph.dataset.ezRequested;
|
|
392
447
|
}
|
|
448
|
+
|
|
393
449
|
const ez = window.ezstandalone;
|
|
394
450
|
if (ez && typeof ez.destroyPlaceholders === 'function') {
|
|
395
451
|
ez.destroyPlaceholders([domId]);
|
|
@@ -417,6 +473,7 @@ function withInternalDomChange(fn) {
|
|
|
417
473
|
withInternalDomChange(() => {
|
|
418
474
|
try {
|
|
419
475
|
if (id) safeDestroyById(id);
|
|
476
|
+
parkPlaceholderFromWrap(wrap);
|
|
420
477
|
wrap.remove();
|
|
421
478
|
} catch (e) {}
|
|
422
479
|
});
|
|
@@ -450,9 +507,7 @@ function buildWrap(id, kindClass, afterPos) {
|
|
|
450
507
|
wrap.setAttribute('data-ezoic-wrapid', String(id));
|
|
451
508
|
wrap.style.width = '100%';
|
|
452
509
|
|
|
453
|
-
const ph =
|
|
454
|
-
ph.id = `${PLACEHOLDER_PREFIX}${id}`;
|
|
455
|
-
ph.setAttribute('data-ezoic-id', String(id));
|
|
510
|
+
const ph = acquirePlaceholder(id);
|
|
456
511
|
wrap.appendChild(ph);
|
|
457
512
|
|
|
458
513
|
return wrap;
|
|
@@ -519,6 +574,7 @@ function buildWrap(id, kindClass, afterPos) {
|
|
|
519
574
|
if (ph && state.io) state.io.unobserve(ph);
|
|
520
575
|
} catch (e) {}
|
|
521
576
|
|
|
577
|
+
parkPlaceholderFromWrap(victim);
|
|
522
578
|
victim.remove();
|
|
523
579
|
return true;
|
|
524
580
|
} catch (e) {
|
|
@@ -865,6 +921,7 @@ function startShow(id) {
|
|
|
865
921
|
// remove all wrappers
|
|
866
922
|
try {
|
|
867
923
|
document.querySelectorAll(`.${WRAP_CLASS}`).forEach((el) => {
|
|
924
|
+
try { parkPlaceholderFromWrap(el); } catch (e) {}
|
|
868
925
|
try { el.remove(); } catch (e) {}
|
|
869
926
|
});
|
|
870
927
|
} catch (e) {}
|