nodebb-plugin-ezoic-infinite 1.5.72 → 1.5.73

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.5.72",
3
+ "version": "1.5.73",
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,7 +14,8 @@
14
14
 
15
15
  // Keep empty (unfilled) wraps alive for a while. Topics/messages can fill late (auction/CMP).
16
16
  // Pruning too early makes ads look like they "disappear" while scrolling.
17
- const KEEP_EMPTY_WRAP_MS = 30000;
17
+ // Keep empty wraps alive; mobile fills can be slow.
18
+ function keepEmptyWrapMs() { return isMobile() ? 120000 : 60000; }
18
19
 
19
20
  // Preload margins
20
21
  const PRELOAD_MARGIN_DESKTOP = '2600px 0px 2600px 0px';
@@ -37,7 +38,64 @@
37
38
  // Production build: debug disabled
38
39
  function dbg() {}
39
40
 
40
- // ---------------- state ----------------
41
+
42
+
43
+ function isFilledNode(node) {
44
+ return !!(node && node.querySelector && node.querySelector('iframe, ins, img, video, [data-google-container-id]'));
45
+ }
46
+
47
+ // Ezoic often sets inline min-height (e.g. 400px) for adaptive placements.
48
+ // In NodeBB topics/messages this creates visible empty space under 250px creatives.
49
+ // We tighten the outermost Ezoic container to the actual creative height once it exists.
50
+ function tightenEzoicMinHeight(wrap) {
51
+ try {
52
+ if (!wrap || !wrap.querySelector) return;
53
+ const outer = wrap.querySelector('.ezoic-ad-adaptive') ||
54
+ wrap.querySelector('.ezoic-ad[style*="min-height"]') ||
55
+ wrap.querySelector('.ezoic-ad');
56
+ if (!outer) return;
57
+
58
+ const iframes = outer.querySelectorAll('iframe');
59
+ if (!iframes || !iframes.length) return;
60
+
61
+ let h = 0;
62
+ iframes.forEach((f) => {
63
+ const ah = parseInt(f.getAttribute('height') || '0', 10);
64
+ const oh = f.offsetHeight || 0;
65
+ h = Math.max(h, ah, oh);
66
+ });
67
+ if (!h) return;
68
+
69
+ // Override inline min-height with a newer inline important.
70
+ try { outer.style.setProperty('min-height', h + 'px', 'important'); } catch (e) { outer.style.minHeight = h + 'px'; }
71
+ try { outer.style.setProperty('height', 'auto', 'important'); } catch (e) {}
72
+
73
+ // Mobile friendliness: avoid giant fixed widths causing overflow/reflow.
74
+ if (isMobile()) {
75
+ try { outer.style.setProperty('width', '100%', 'important'); } catch (e) {}
76
+ try { outer.style.setProperty('max-width', '100%', 'important'); } catch (e) {}
77
+ try { outer.style.setProperty('min-width', '0', 'important'); } catch (e) {}
78
+ }
79
+ } catch (e) {}
80
+ }
81
+
82
+ function watchWrapForFill(wrap) {
83
+ try {
84
+ if (!wrap || wrap.__ezFillObs) return;
85
+ const obs = new MutationObserver(() => {
86
+ if (isFilledNode(wrap)) {
87
+ wrap.classList.remove('is-empty');
88
+ tightenEzoicMinHeight(wrap);
89
+ try { obs.disconnect(); } catch (e) {}
90
+ wrap.__ezFillObs = null;
91
+ }
92
+ });
93
+ obs.observe(wrap, { childList: true, subtree: true });
94
+ wrap.__ezFillObs = obs;
95
+ } catch (e) {}
96
+ }
97
+
98
+ // ---------------- state ----------------
41
99
 
42
100
  const state = {
43
101
  pageKey: null,
@@ -414,6 +472,8 @@
414
472
  }
415
473
 
416
474
  function pruneOrphanWraps(kindClass, items) {
475
+ // On mobile topics/messages, keep wraps alive longer to avoid 'disappearing' ads.
476
+ if (kindClass === 'ezoic-ad-message' && isMobile()) return 0;
417
477
  if (!items || !items.length) return 0;
418
478
  const itemSet = new Set(items);
419
479
  const wraps = document.querySelectorAll(`.${WRAP_CLASS}.${kindClass}`);
@@ -444,7 +504,7 @@
444
504
  // Never prune a fresh wrap: it may fill late.
445
505
  try {
446
506
  const created = parseInt(wrap.getAttribute('data-created') || '0', 10);
447
- if (created && (now() - created) < KEEP_EMPTY_WRAP_MS) return;
507
+ if (created && (now() - created) < keepEmptyWrapMs()) return;
448
508
  } catch (e) {}
449
509
 
450
510
  if (hasNearbyItem(wrap)) return;
@@ -470,7 +530,7 @@
470
530
  const isFresh = (wrap) => {
471
531
  try {
472
532
  const created = parseInt(wrap.getAttribute('data-created') || '0', 10);
473
- return created && (now() - created) < KEEP_EMPTY_WRAP_MS;
533
+ return created && (now() - created) < keepEmptyWrapMs();
474
534
  } catch (e) {
475
535
  return false;
476
536
  }
@@ -603,11 +663,17 @@
603
663
  // Don't collapse "fresh" placements; slow auctions/CMP can fill late.
604
664
  try {
605
665
  const created = parseInt(w2.getAttribute('data-created') || '0', 10);
606
- if (created && (now() - created) < KEEP_EMPTY_WRAP_MS) return;
666
+ if (created && (now() - created) < keepEmptyWrapMs()) return;
607
667
  } catch (e) {}
608
668
 
609
669
  const hasAd = !!(ph2.querySelector && ph2.querySelector('iframe, ins, img, .ez-ad, .ezoic-ad'));
610
- if (!hasAd) w2.classList.add('is-empty');
670
+ if (!hasAd) {
671
+ w2.classList.add('is-empty');
672
+ watchWrapForFill(w2);
673
+ } else {
674
+ w2.classList.remove('is-empty');
675
+ tightenEzoicMinHeight(w2);
676
+ }
611
677
  } catch (e) {}
612
678
  }, 15000);
613
679
  } catch (e) {}
@@ -645,6 +711,15 @@
645
711
  const doShow = () => {
646
712
  try { ez.showAds(id); } catch (e) {}
647
713
  try { markEmptyWrapper(id); } catch (e) {}
714
+ try {
715
+ const phw = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
716
+ const ww = phw && phw.closest ? phw.closest(`.${WRAP_CLASS}`) : null;
717
+ if (ww) {
718
+ watchWrapForFill(ww);
719
+ setTimeout(() => { try { tightenEzoicMinHeight(ww); } catch (e) {} }, 900);
720
+ setTimeout(() => { try { tightenEzoicMinHeight(ww); } catch (e) {} }, 2200);
721
+ }
722
+ } catch (e) {}
648
723
  setTimeout(() => { clearTimeout(hardTimer); release(); }, 650);
649
724
  };
650
725
 
package/public/style.css CHANGED
@@ -68,3 +68,6 @@
68
68
  min-height: 1px !important; /* kill 400px gaps */
69
69
  height: auto !important;
70
70
  }
71
+
72
+ /* Ensure Ezoic reportline doesn't affect layout */
73
+ .nodebb-ezoic-wrap .reportline{position:absolute!important;}