nodebb-plugin-ezoic-infinite 1.5.39 → 1.5.40
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 +103 -0
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -135,6 +135,7 @@ function mutationHasRelevantAddedNodes(mutations) {
|
|
|
135
135
|
|
|
136
136
|
// observers / schedulers
|
|
137
137
|
domObs: null,
|
|
138
|
+
tightenObs: null,
|
|
138
139
|
io: null,
|
|
139
140
|
runQueued: false,
|
|
140
141
|
|
|
@@ -292,6 +293,103 @@ function mutationHasRelevantAddedNodes(mutations) {
|
|
|
292
293
|
}
|
|
293
294
|
}
|
|
294
295
|
|
|
296
|
+
// ---------- Ezoic min-height tightening (lightweight) ----------
|
|
297
|
+
// Some Ezoic placements reserve a large min-height (e.g. 400px) even when
|
|
298
|
+
// the rendered iframe/container is smaller (often 250px). That creates a
|
|
299
|
+
// visible empty gap and can make creatives appear to "slide" inside the slot.
|
|
300
|
+
// We correct ONLY those cases, without scroll listeners or full-page rescans.
|
|
301
|
+
|
|
302
|
+
function getRenderedAdHeight(adSpan) {
|
|
303
|
+
try {
|
|
304
|
+
const c = adSpan.querySelector('div[id$="__container__"]');
|
|
305
|
+
if (c && c.offsetHeight) return c.offsetHeight;
|
|
306
|
+
const f = adSpan.querySelector('iframe');
|
|
307
|
+
if (!f) return 0;
|
|
308
|
+
const attr = parseInt(f.getAttribute('height') || '', 10);
|
|
309
|
+
if (Number.isFinite(attr) && attr > 0) return attr;
|
|
310
|
+
if (f.offsetHeight) return f.offsetHeight;
|
|
311
|
+
} catch (e) {}
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function tightenMinHeight(adSpan) {
|
|
316
|
+
try {
|
|
317
|
+
if (!adSpan || adSpan.nodeType !== 1) return;
|
|
318
|
+
if (adSpan.tagName !== 'SPAN') return;
|
|
319
|
+
if (!adSpan.classList || !adSpan.classList.contains('ezoic-ad')) return;
|
|
320
|
+
|
|
321
|
+
const mhStr = adSpan.style && adSpan.style.minHeight ? String(adSpan.style.minHeight) : '';
|
|
322
|
+
const mh = mhStr ? parseInt(mhStr, 10) : 0;
|
|
323
|
+
if (!mh || mh < 350) return; // only fix the "400px"-style reservations
|
|
324
|
+
|
|
325
|
+
const h = getRenderedAdHeight(adSpan);
|
|
326
|
+
if (!h || h <= 0) return;
|
|
327
|
+
if (h >= mh) return;
|
|
328
|
+
|
|
329
|
+
adSpan.style.setProperty('min-height', `${h}px`, 'important');
|
|
330
|
+
} catch (e) {}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function closestEzoicAdSpan(node) {
|
|
334
|
+
try {
|
|
335
|
+
if (!node || node.nodeType !== 1) return null;
|
|
336
|
+
const el = /** @type {Element} */ (node);
|
|
337
|
+
if (el.tagName === 'SPAN' && el.classList && el.classList.contains('ezoic-ad')) return el;
|
|
338
|
+
if (el.closest) return el.closest('span.ezoic-ad');
|
|
339
|
+
} catch (e) {}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function ensureTightenObserver() {
|
|
344
|
+
if (state.tightenObs) return;
|
|
345
|
+
|
|
346
|
+
let raf = 0;
|
|
347
|
+
const pending = new Set();
|
|
348
|
+
const schedule = (adSpan) => {
|
|
349
|
+
if (!adSpan) return;
|
|
350
|
+
pending.add(adSpan);
|
|
351
|
+
if (raf) return;
|
|
352
|
+
raf = requestAnimationFrame(() => {
|
|
353
|
+
raf = 0;
|
|
354
|
+
for (const el of pending) tightenMinHeight(el);
|
|
355
|
+
pending.clear();
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
state.tightenObs = new MutationObserver((mutations) => {
|
|
360
|
+
try {
|
|
361
|
+
for (const m of mutations) {
|
|
362
|
+
if (m.type === 'attributes') {
|
|
363
|
+
const ad = closestEzoicAdSpan(m.target);
|
|
364
|
+
if (ad) schedule(ad);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (!m.addedNodes || !m.addedNodes.length) continue;
|
|
368
|
+
for (const n of m.addedNodes) {
|
|
369
|
+
const ad = closestEzoicAdSpan(n);
|
|
370
|
+
if (ad) schedule(ad);
|
|
371
|
+
if (n && n.nodeType === 1 && n.querySelectorAll) {
|
|
372
|
+
n.querySelectorAll('span.ezoic-ad').forEach(schedule);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} catch (e) {}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
try {
|
|
380
|
+
state.tightenObs.observe(document.documentElement, {
|
|
381
|
+
subtree: true,
|
|
382
|
+
childList: true,
|
|
383
|
+
attributes: true,
|
|
384
|
+
attributeFilter: ['style', 'class', 'data-load-complete', 'height'],
|
|
385
|
+
});
|
|
386
|
+
} catch (e) {}
|
|
387
|
+
|
|
388
|
+
try {
|
|
389
|
+
document.querySelectorAll('span.ezoic-ad[style*="min-height"]').forEach(tightenMinHeight);
|
|
390
|
+
} catch (e) {}
|
|
391
|
+
}
|
|
392
|
+
|
|
295
393
|
const RECYCLE_COOLDOWN_MS = 1500;
|
|
296
394
|
|
|
297
395
|
function kindKeyFromClass(kindClass) {
|
|
@@ -853,6 +951,9 @@ function startShow(id) {
|
|
|
853
951
|
// reset perf profile cache
|
|
854
952
|
state.perfProfile = null;
|
|
855
953
|
|
|
954
|
+
// tighten observer is global; keep it across ajaxify navigation but ensure it exists
|
|
955
|
+
// (do not disconnect here to avoid missing late style rewrites during transitions)
|
|
956
|
+
|
|
856
957
|
// reset state
|
|
857
958
|
state.cfg = null;
|
|
858
959
|
state.allTopics = [];
|
|
@@ -899,6 +1000,7 @@ function startShow(id) {
|
|
|
899
1000
|
|
|
900
1001
|
warmUpNetwork();
|
|
901
1002
|
patchShowAds();
|
|
1003
|
+
ensureTightenObserver();
|
|
902
1004
|
ensurePreloadObserver();
|
|
903
1005
|
ensureDomObserver();
|
|
904
1006
|
|
|
@@ -921,6 +1023,7 @@ function startShow(id) {
|
|
|
921
1023
|
state.pageKey = getPageKey();
|
|
922
1024
|
warmUpNetwork();
|
|
923
1025
|
patchShowAds();
|
|
1026
|
+
ensureTightenObserver();
|
|
924
1027
|
ensurePreloadObserver();
|
|
925
1028
|
ensureDomObserver();
|
|
926
1029
|
|