nodebb-plugin-ezoic-infinite 1.5.69 → 1.5.70

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.69",
3
+ "version": "1.5.70",
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
@@ -393,12 +393,22 @@
393
393
 
394
394
  wraps.forEach((wrap) => {
395
395
  let ok = false;
396
+ // NodeBB/skins can insert helper nodes between posts (clearfix, separators, etc.).
397
+ // Be tolerant so we don't remove a valid ad too early ("disappears too fast").
396
398
  let prev = wrap.previousElementSibling;
397
- for (let i = 0; i < 3 && prev; i++) {
399
+ for (let i = 0; i < 8 && prev; i++) {
398
400
  if (itemSet.has(prev)) { ok = true; break; }
399
401
  prev = prev.previousElementSibling;
400
402
  }
401
403
 
404
+ if (!ok) {
405
+ let next = wrap.nextElementSibling;
406
+ for (let i = 0; i < 3 && next; i++) {
407
+ if (itemSet.has(next)) { ok = true; break; }
408
+ next = next.nextElementSibling;
409
+ }
410
+ }
411
+
402
412
  if (!ok) {
403
413
  withInternalDomChange(() => releaseWrapNode(wrap));
404
414
  removed++;
@@ -469,6 +479,9 @@
469
479
  if (!ph || !ph.isConnected) return;
470
480
  ph.setAttribute('data-ezoic-id', String(id));
471
481
 
482
+ // When the ad actually fills, tighten height to the real iframe height and remove empty-collapsing.
483
+ armFillObserver(ph);
484
+
472
485
  const io = ensurePreloadObserver();
473
486
  try { io && io.observe(ph); } catch (e) {}
474
487
 
@@ -481,6 +494,56 @@
481
494
  } catch (e) {}
482
495
  }
483
496
 
497
+ // ---------------- fill tightening ----------------
498
+
499
+ const _fillObserved = new WeakSet();
500
+ function tightenFilled(ph) {
501
+ if (!ph || !ph.isConnected) return;
502
+ const wrap = ph.closest ? ph.closest(`.${WRAP_CLASS}`) : null;
503
+ if (!wrap) return;
504
+
505
+ // If we have any real ad content, we should not be in "empty" mode.
506
+ const frame = ph.querySelector ? ph.querySelector('iframe') : null;
507
+ const hasAd = !!(frame || (ph.querySelector && ph.querySelector('ins, img, .ez-ad, .ezoic-ad')));
508
+ if (!hasAd) return;
509
+
510
+ try { wrap.classList.remove('is-empty'); } catch (e) {}
511
+
512
+ // Remove the common "extra reserved space" created by Ezoic's min-height styles.
513
+ // Set minHeight to the actual iframe height when available.
514
+ try {
515
+ if (frame && frame.offsetHeight) {
516
+ const h = frame.offsetHeight;
517
+ const ezoicSpan = ph.closest ? ph.closest('span.ezoic-ad, .ezoic-ad') : null;
518
+ if (ezoicSpan && ezoicSpan.style) {
519
+ ezoicSpan.style.minHeight = `${h}px`;
520
+ }
521
+ // Also tighten the wrapper itself to avoid "space under" when the parent is taller.
522
+ wrap.style.minHeight = `${h}px`;
523
+ }
524
+ } catch (e) {}
525
+ }
526
+
527
+ function armFillObserver(ph) {
528
+ if (!ph || _fillObserved.has(ph)) return;
529
+ _fillObserved.add(ph);
530
+
531
+ // Fast path: already filled
532
+ try { tightenFilled(ph); } catch (e) {}
533
+
534
+ // Observe until it fills, then disconnect.
535
+ try {
536
+ const mo = new MutationObserver(() => {
537
+ try {
538
+ tightenFilled(ph);
539
+ const hasFrame = !!(ph.querySelector && ph.querySelector('iframe'));
540
+ if (hasFrame) mo.disconnect();
541
+ } catch (e) {}
542
+ });
543
+ mo.observe(ph, { childList: true, subtree: true });
544
+ } catch (e) {}
545
+ }
546
+
484
547
  function enqueueShow(id) {
485
548
  if (!id || isBlocked()) return;
486
549
 
package/public/style.css CHANGED
@@ -22,6 +22,10 @@
22
22
  .nodebb-ezoic-wrap .ezoic-ad {
23
23
  margin: 0 !important;
24
24
  padding: 0 !important;
25
+ /* Ezoic sometimes reserves extra height (e.g. min-height: 400px) even when the filled iframe is smaller.
26
+ We prefer zero unused space; JS will also tighten after fill to the real iframe height. */
27
+ min-height: 0 !important;
28
+ height: auto !important;
25
29
  }
26
30
 
27
31
  /* Remove the classic "gap under iframe" (baseline/inline-block) */