nodebb-plugin-ezoic-infinite 1.5.36 → 1.5.37
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 +93 -4
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
// Preload before viewport (earlier load for smoother scroll)
|
|
14
14
|
// Preload far enough ahead that fast scroll doesn't outrun ad loading.
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
// Slightly more aggressive margins to reduce “I scrolled past it before it loaded”.
|
|
16
|
+
const PRELOAD_MARGIN_DESKTOP = '4200px 0px 4200px 0px';
|
|
17
|
+
const PRELOAD_MARGIN_MOBILE = '2400px 0px 2400px 0px';
|
|
17
18
|
|
|
18
19
|
// When the user scrolls very fast, temporarily preload more aggressively.
|
|
19
20
|
// This helps ensure ads are already in-flight before the user reaches them.
|
|
20
|
-
const PRELOAD_MARGIN_DESKTOP_BOOST = '
|
|
21
|
-
const PRELOAD_MARGIN_MOBILE_BOOST = '
|
|
21
|
+
const PRELOAD_MARGIN_DESKTOP_BOOST = '6500px 0px 6500px 0px';
|
|
22
|
+
const PRELOAD_MARGIN_MOBILE_BOOST = '4200px 0px 4200px 0px';
|
|
22
23
|
const BOOST_DURATION_MS = 2500;
|
|
23
24
|
const BOOST_SPEED_PX_PER_MS = 2.2; // ~2200px/s
|
|
24
25
|
|
|
@@ -601,6 +602,9 @@ function startShow(id) {
|
|
|
601
602
|
try { ez.showAds(id); } catch (e) {}
|
|
602
603
|
try { state.usedOnce && state.usedOnce.add(id); } catch (e) {}
|
|
603
604
|
|
|
605
|
+
// Tighten any oversized reserved height once the creative is in the DOM.
|
|
606
|
+
try { scheduleTighten(id); } catch (e) {}
|
|
607
|
+
|
|
604
608
|
setTimeout(() => { clearTimeout(hardTimer); release(); }, 650);
|
|
605
609
|
};
|
|
606
610
|
|
|
@@ -615,6 +619,83 @@ function startShow(id) {
|
|
|
615
619
|
});
|
|
616
620
|
}
|
|
617
621
|
|
|
622
|
+
// ---------- height normalization (reduce empty space) ----------
|
|
623
|
+
// Some Ezoic / GPT wrappers reserve a larger min-height (e.g., 400px) than the rendered creative (e.g., 250px),
|
|
624
|
+
// leaving visible empty space. We “tighten” the reserved min-height to the actual iframe/container height after load.
|
|
625
|
+
const _heightObsByPlaceholder = new Map();
|
|
626
|
+
|
|
627
|
+
function tightenEzoicHeightFor(id) {
|
|
628
|
+
try {
|
|
629
|
+
const ph = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
|
|
630
|
+
if (!ph || !ph.isConnected) return;
|
|
631
|
+
|
|
632
|
+
const ad = ph.querySelector('span.ezoic-ad');
|
|
633
|
+
if (!ad) return;
|
|
634
|
+
|
|
635
|
+
// Prefer the safeframe/container size if present.
|
|
636
|
+
let h = 0;
|
|
637
|
+
const container = ad.querySelector('div[id$="__container__"]');
|
|
638
|
+
if (container) {
|
|
639
|
+
const r = container.getBoundingClientRect();
|
|
640
|
+
if (r && r.height) h = Math.max(h, r.height);
|
|
641
|
+
}
|
|
642
|
+
const iframe = ad.querySelector('iframe');
|
|
643
|
+
if (iframe) {
|
|
644
|
+
const r2 = iframe.getBoundingClientRect();
|
|
645
|
+
if (r2 && r2.height) h = Math.max(h, r2.height);
|
|
646
|
+
const attrH = parseInt(iframe.getAttribute('height') || '', 10);
|
|
647
|
+
if (Number.isFinite(attrH) && attrH > 0) h = Math.max(h, attrH);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Fall back to inner wrapper height.
|
|
651
|
+
if (!h) {
|
|
652
|
+
const inner = ad.firstElementChild;
|
|
653
|
+
if (inner) {
|
|
654
|
+
const r3 = inner.getBoundingClientRect();
|
|
655
|
+
if (r3 && r3.height) h = Math.max(h, r3.height);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
if (!h || h < 10) return;
|
|
660
|
+
const px = `${Math.ceil(h)}px`;
|
|
661
|
+
|
|
662
|
+
// Override inline min-height with an inline !important value.
|
|
663
|
+
try { ad.style.setProperty('min-height', px, 'important'); } catch (e) {}
|
|
664
|
+
// Keep height auto so responsive creatives can expand if needed.
|
|
665
|
+
try { ad.style.setProperty('height', 'auto', 'important'); } catch (e) {}
|
|
666
|
+
} catch (e) {}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function ensureHeightObserver(id) {
|
|
670
|
+
try {
|
|
671
|
+
if (_heightObsByPlaceholder.has(id)) return;
|
|
672
|
+
const ph = document.getElementById(`${PLACEHOLDER_PREFIX}${id}`);
|
|
673
|
+
if (!ph || !ph.isConnected) return;
|
|
674
|
+
|
|
675
|
+
const ro = (typeof ResizeObserver === 'function') ? new ResizeObserver(() => {
|
|
676
|
+
tightenEzoicHeightFor(id);
|
|
677
|
+
}) : null;
|
|
678
|
+
|
|
679
|
+
if (ro) {
|
|
680
|
+
const ad = ph.querySelector('span.ezoic-ad');
|
|
681
|
+
const container = ad && ad.querySelector && ad.querySelector('div[id$="__container__"]');
|
|
682
|
+
const iframe = ad && ad.querySelector && ad.querySelector('iframe');
|
|
683
|
+
try { if (container) ro.observe(container); } catch (e) {}
|
|
684
|
+
try { if (iframe) ro.observe(iframe); } catch (e) {}
|
|
685
|
+
try { if (ad) ro.observe(ad); } catch (e) {}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
_heightObsByPlaceholder.set(id, ro || true);
|
|
689
|
+
} catch (e) {}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function scheduleTighten(id) {
|
|
693
|
+
// Run a couple of times (creatives may resize after initial load)
|
|
694
|
+
try { setTimeout(() => tightenEzoicHeightFor(id), 250); } catch (e) {}
|
|
695
|
+
try { setTimeout(() => tightenEzoicHeightFor(id), 1100); } catch (e) {}
|
|
696
|
+
try { ensureHeightObserver(id); } catch (e) {}
|
|
697
|
+
}
|
|
698
|
+
|
|
618
699
|
|
|
619
700
|
// ---------- preload / above-the-fold ----------
|
|
620
701
|
|
|
@@ -875,6 +956,14 @@ function startShow(id) {
|
|
|
875
956
|
// reset perf profile cache
|
|
876
957
|
state.perfProfile = null;
|
|
877
958
|
|
|
959
|
+
// disconnect any ResizeObservers used for height tightening
|
|
960
|
+
try {
|
|
961
|
+
for (const v of _heightObsByPlaceholder.values()) {
|
|
962
|
+
try { v && v.disconnect && v.disconnect(); } catch (e) {}
|
|
963
|
+
}
|
|
964
|
+
_heightObsByPlaceholder.clear();
|
|
965
|
+
} catch (e) {}
|
|
966
|
+
|
|
878
967
|
// reset state
|
|
879
968
|
state.cfg = null;
|
|
880
969
|
state.allTopics = [];
|