nodebb-plugin-ezoic-infinite 1.5.92 → 1.5.94
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 +2 -145
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function ezoicTrySetAnchor(wrap, el, kindClass, afterPos) {
|
|
5
|
-
try {
|
|
6
|
-
if (!wrap || !el) return;
|
|
7
|
-
var pid = el.getAttribute && (el.getAttribute('data-pid') || el.getAttribute('data-id'));
|
|
8
|
-
var tid = el.getAttribute && (el.getAttribute('data-tid') || el.getAttribute('data-topic-id'));
|
|
9
|
-
var key = kindClass + ':' + (pid ? ('pid:' + pid) : (tid ? ('tid:' + tid) : ('pos:' + String(afterPos || 0))));
|
|
10
|
-
wrap.setAttribute('data-ezoic-anchor', key);
|
|
11
|
-
} catch (e) {}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
4
|
// Track scroll direction to avoid aggressive recycling when the user scrolls upward.
|
|
16
5
|
// Recycling while scrolling up is a common cause of ads "bunching" and a "disappearing too fast" feeling.
|
|
17
6
|
let lastScrollY = 0;
|
|
@@ -651,7 +640,6 @@ function globalGapFixInit() {
|
|
|
651
640
|
const wrap = document.createElement('div');
|
|
652
641
|
wrap.className = `${WRAP_CLASS} ${kindClass}`;
|
|
653
642
|
wrap.setAttribute('data-ezoic-after', String(afterPos));
|
|
654
|
-
ezoicTrySetAnchor(wrap, el, kindClass, afterPos);
|
|
655
643
|
wrap.setAttribute('data-ezoic-wrapid', String(id));
|
|
656
644
|
wrap.setAttribute('data-created', String(now()));
|
|
657
645
|
// "Pinned" placements (after the first item) should remain stable.
|
|
@@ -716,143 +704,12 @@ function globalGapFixInit() {
|
|
|
716
704
|
}
|
|
717
705
|
|
|
718
706
|
function pruneOrphanWraps(kindClass, items) {
|
|
719
|
-
// Topic pages can be virtualized (posts removed from DOM as you scroll).
|
|
720
|
-
// When that happens, previously-inserted ad wraps may become "orphan" nodes with no
|
|
721
|
-
// nearby post containers, which leads to ads clustering together when scrolling back up.
|
|
722
|
-
// We prune only *true* orphans that are far offscreen to keep the UI stable.
|
|
723
|
-
if (!items || !items.length) return 0;
|
|
724
|
-
const itemSet = new Set(items);
|
|
725
|
-
const wraps = document.querySelectorAll(`.${WRAP_CLASS}.${kindClass}`);
|
|
726
|
-
let removed = 0;
|
|
727
|
-
|
|
728
|
-
const isFilled = (wrap) => {
|
|
729
|
-
return !!(wrap.querySelector('iframe, ins, img, video, [data-google-container-id]'));
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
const hasNearbyItem = (wrap) => {
|
|
733
|
-
// NodeBB/skins can inject separators/spacers; be tolerant.
|
|
734
|
-
let prev = wrap.previousElementSibling;
|
|
735
|
-
for (let i = 0; i < 14 && prev; i++) {
|
|
736
|
-
if (itemSet.has(prev)) return true;
|
|
737
|
-
prev = prev.previousElementSibling;
|
|
738
|
-
}
|
|
739
|
-
let next = wrap.nextElementSibling;
|
|
740
|
-
for (let i = 0; i < 14 && next; i++) {
|
|
741
|
-
if (itemSet.has(next)) return true;
|
|
742
|
-
next = next.nextElementSibling;
|
|
743
|
-
}
|
|
744
|
-
return false;
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
wraps.forEach((wrap) => {
|
|
748
|
-
// Never prune pinned placements.
|
|
749
|
-
try {
|
|
750
|
-
if (wrap.getAttribute('data-ezoic-pin') === '1') return;
|
|
751
|
-
} catch (e) {}
|
|
752
|
-
|
|
753
|
-
// For message/topic pages we may prune filled or empty orphans if they are far away,
|
|
754
|
-
// otherwise consecutive "stacks" can appear when posts are virtualized.
|
|
755
|
-
const isMessage = (kindClass === 'ezoic-ad-message');
|
|
756
|
-
if (!isMessage && isFilled(wrap)) return; // never prune filled ads for non-message lists
|
|
757
|
-
|
|
758
|
-
// Never prune a fresh wrap: it may fill late.
|
|
759
|
-
try {
|
|
760
|
-
const created = parseInt(wrap.getAttribute('data-created') || '0', 10);
|
|
761
|
-
if (created && (now() - created) < keepEmptyWrapMs()) return;
|
|
762
|
-
} catch (e) {}
|
|
763
|
-
|
|
764
|
-
if (hasNearbyItem(wrap)) {
|
|
765
|
-
try { wrap.classList && wrap.classList.remove('ez-orphan-hidden'); wrap.style && (wrap.style.display = ''); } catch (e) {}
|
|
766
707
|
return;
|
|
767
708
|
}
|
|
768
709
|
|
|
769
|
-
// If the anchor item is no longer in the DOM (virtualized), hide the wrap so ads never "stack"
|
|
770
|
-
// back-to-back while scrolling. We'll recycle it when its anchor comes back.
|
|
771
|
-
try { wrap.classList && wrap.classList.add('ez-orphan-hidden'); wrap.style && (wrap.style.display = 'none'); } catch (e) {}
|
|
772
|
-
|
|
773
|
-
// For message ads: only release if far offscreen to avoid perceived "vanishing" during fast scroll.
|
|
774
|
-
if (isMessage) {
|
|
775
|
-
try {
|
|
776
|
-
const r = wrap.getBoundingClientRect();
|
|
777
|
-
const vh = Math.max(1, window.innerHeight || 1);
|
|
778
|
-
const farAbove = r.bottom < -vh * 2;
|
|
779
|
-
const farBelow = r.top > vh * 4;
|
|
780
|
-
if (!farAbove && !farBelow) return;
|
|
781
|
-
} catch (e) {
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
withInternalDomChange(() => releaseWrapNode(wrap));
|
|
787
|
-
removed++;
|
|
788
|
-
});
|
|
789
|
-
|
|
790
|
-
return removed;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
710
|
function decluster(kindClass) {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (wraps.length < 2) return 0;
|
|
797
|
-
|
|
798
|
-
const isWrap = (el) => !!(el && el.classList && el.classList.contains(WRAP_CLASS));
|
|
799
|
-
|
|
800
|
-
const isFilled = (wrap) => {
|
|
801
|
-
return !!(wrap && wrap.querySelector && wrap.querySelector('iframe, ins, img, video, [data-google-container-id]'));
|
|
802
|
-
};
|
|
803
|
-
|
|
804
|
-
const isFresh = (wrap) => {
|
|
805
|
-
try {
|
|
806
|
-
const created = parseInt(wrap.getAttribute('data-created') || '0', 10);
|
|
807
|
-
return created && (now() - created) < keepEmptyWrapMs();
|
|
808
|
-
} catch (e) {
|
|
809
|
-
return false;
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
|
|
813
|
-
let removed = 0;
|
|
814
|
-
for (const w of wraps) {
|
|
815
|
-
// Never decluster pinned placements.
|
|
816
|
-
try {
|
|
817
|
-
if (w.getAttribute && w.getAttribute('data-ezoic-pin') === '1') continue;
|
|
818
|
-
} catch (e) {}
|
|
819
|
-
|
|
820
|
-
let prev = w.previousElementSibling;
|
|
821
|
-
for (let i = 0; i < 3 && prev; i++) {
|
|
822
|
-
if (isWrap(prev)) {
|
|
823
|
-
// If the previous wrap is pinned, keep this one (spacing is intentional).
|
|
824
|
-
try {
|
|
825
|
-
if (prev.getAttribute && prev.getAttribute('data-ezoic-pin') === '1') break;
|
|
826
|
-
} catch (e) {}
|
|
827
|
-
|
|
828
|
-
// Never remove a wrap that is already filled; otherwise it looks like
|
|
829
|
-
// ads "disappear" while scrolling. Only remove the empty neighbour.
|
|
830
|
-
const prevFilled = isFilled(prev);
|
|
831
|
-
const curFilled = isFilled(w);
|
|
832
|
-
|
|
833
|
-
if (curFilled) {
|
|
834
|
-
// If the previous one is empty (and not fresh), drop the previous instead.
|
|
835
|
-
if (!prevFilled && !isFresh(prev)) {
|
|
836
|
-
withInternalDomChange(() => releaseWrapNode(prev));
|
|
837
|
-
removed++;
|
|
838
|
-
}
|
|
839
|
-
break;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
// Current is empty.
|
|
843
|
-
// Don't decluster two "fresh" empty wraps — it can reduce fill on slow auctions.
|
|
844
|
-
// Only decluster when previous is filled, or when current is stale.
|
|
845
|
-
if (prevFilled || !isFresh(w)) {
|
|
846
|
-
withInternalDomChange(() => releaseWrapNode(w));
|
|
847
|
-
removed++;
|
|
848
|
-
}
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
prev = prev.previousElementSibling;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
return removed;
|
|
855
|
-
}
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
856
713
|
|
|
857
714
|
// ---------------- show (preload / fast fill) ----------------
|
|
858
715
|
|