nodebb-plugin-ezoic-infinite 1.6.1 → 1.6.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +62 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
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
@@ -1345,8 +1345,15 @@ function buildOrdinalMap(items) {
1345
1345
 
1346
1346
 
1347
1347
 
1348
+
1348
1349
  // ===== CLEAN REFRACTOR: visibility manager for Ezoic wraps =====
1349
1350
  (function () {
1351
+ // v2.1 (safe):
1352
+ // - Keep the v2 behavior that didn't break forum rendering.
1353
+ // - Improve speed moderately (earlier preload + slightly higher show throughput).
1354
+ // - Improve up-scroll reliability without scanning the whole DOM:
1355
+ // * on scroll, enqueue showAds for wraps currently in/near viewport (small bounded loop).
1356
+
1350
1357
  var BETWEEN_SELECTOR = '.nodebb-ezoic-wrap.ezoic-ad-between';
1351
1358
  var MESSAGE_SELECTOR = '.nodebb-ezoic-wrap.ezoic-ad-message';
1352
1359
  var WRAP_SELECTOR = BETWEEN_SELECTOR + ', ' + MESSAGE_SELECTOR;
@@ -1354,8 +1361,14 @@ function buildOrdinalMap(items) {
1354
1361
  var KEEP_MARGIN_BETWEEN_DESKTOP = 2600;
1355
1362
  var KEEP_MARGIN_BETWEEN_MOBILE = 1900;
1356
1363
 
1357
- var SHOW_COOLDOWN_MS = 1200;
1358
- var MAX_SHOW_PER_TICK = 4;
1364
+ // Show tuning (moderate)
1365
+ var SHOW_COOLDOWN_MS = 900;
1366
+ var MAX_SHOW_PER_TICK = 6;
1367
+
1368
+ // Up-scroll helper: only check near-viewport wraps, bounded
1369
+ var SCAN_COOLDOWN_MS = 220;
1370
+ var lastScan = 0;
1371
+ var SCAN_BUDGET = 10;
1359
1372
 
1360
1373
  function isMobile() {
1361
1374
  try { return window.matchMedia && window.matchMedia('(max-width: 767px)').matches; } catch (e) { return false; }
@@ -1369,6 +1382,12 @@ function buildOrdinalMap(items) {
1369
1382
  function getWrapId(w) {
1370
1383
  try { return w.getAttribute('data-ezoic-wrapid'); } catch (e) { return null; }
1371
1384
  }
1385
+ function getPlaceholderId(w) {
1386
+ try {
1387
+ var ph = w.querySelector('[data-ezoic-id]');
1388
+ return ph ? ph.getAttribute('data-ezoic-id') : null;
1389
+ } catch (e) { return null; }
1390
+ }
1372
1391
 
1373
1392
  function enqueueShow(id) {
1374
1393
  if (!id) return;
@@ -1422,6 +1441,7 @@ function buildOrdinalMap(items) {
1422
1441
  });
1423
1442
  }
1424
1443
 
1444
+ // IO: preload earlier for faster display
1425
1445
  var io = null;
1426
1446
  function installIO() {
1427
1447
  if (io || typeof IntersectionObserver === 'undefined') return;
@@ -1432,18 +1452,12 @@ function buildOrdinalMap(items) {
1432
1452
  if (!e || !e.target) return;
1433
1453
  if (e.isIntersecting) {
1434
1454
  try { e.target.setAttribute('data-last-visible', String(Date.now())); } catch (err) {}
1435
-
1436
- var id = getWrapId(e.target);
1455
+ var id = getWrapId(e.target) || getPlaceholderId(e.target);
1437
1456
  if (id) enqueueShow(id);
1438
-
1439
- try {
1440
- var ph = e.target.querySelector('[data-ezoic-id]');
1441
- if (ph) enqueueShow(ph.getAttribute('data-ezoic-id'));
1442
- } catch (err) {}
1443
1457
  }
1444
1458
  });
1445
1459
  } catch (e) {}
1446
- }, { root: null, rootMargin: '900px 0px 900px 0px', threshold: 0.01 });
1460
+ }, { root: null, rootMargin: '1200px 0px 1200px 0px', threshold: 0.01 });
1447
1461
 
1448
1462
  try { document.querySelectorAll(WRAP_SELECTOR).forEach(function (w) { try { io.observe(w); } catch(e) {} }); } catch (e) {}
1449
1463
  }
@@ -1465,7 +1479,8 @@ function buildOrdinalMap(items) {
1465
1479
 
1466
1480
  if (n.matches && n.matches(WRAP_SELECTOR)) {
1467
1481
  try { io.observe(n); } catch (e) {}
1468
- try { var id = getWrapId(n); if (id) enqueueShow(id); } catch (e) {}
1482
+ var id = getWrapId(n) || getPlaceholderId(n);
1483
+ if (id) enqueueShow(id);
1469
1484
  } else if (n.querySelectorAll) {
1470
1485
  var inner = n.querySelectorAll(WRAP_SELECTOR);
1471
1486
  for (var k = 0; k < inner.length; k++) {
@@ -1480,6 +1495,31 @@ function buildOrdinalMap(items) {
1480
1495
  try { mo.observe(document.documentElement || document.body, { childList: true, subtree: true }); } catch (e) {}
1481
1496
  }
1482
1497
 
1498
+ // Small bounded scan near viewport on scroll (helps on up-scroll)
1499
+ function scanNearViewport() {
1500
+ var now = Date.now();
1501
+ if (now - lastScan < SCAN_COOLDOWN_MS) return;
1502
+ lastScan = now;
1503
+
1504
+ var vh = window.innerHeight || document.documentElement.clientHeight || 0;
1505
+ var margin = 900; // near viewport window
1506
+ var wraps;
1507
+ try { wraps = document.querySelectorAll(WRAP_SELECTOR); } catch (e) { return; }
1508
+
1509
+ var budget = SCAN_BUDGET;
1510
+ for (var i = 0; i < wraps.length && budget > 0; i++) {
1511
+ var w = wraps[i];
1512
+ try {
1513
+ var r = w.getBoundingClientRect();
1514
+ if (r.bottom >= -margin && r.top <= (vh + margin)) {
1515
+ var id = getWrapId(w) || getPlaceholderId(w);
1516
+ if (id) enqueueShow(id);
1517
+ budget--;
1518
+ }
1519
+ } catch (e) {}
1520
+ }
1521
+ }
1522
+
1483
1523
  var sweepPending = false;
1484
1524
  var lastSweep = 0;
1485
1525
  var SWEEP_COOLDOWN_MS = 600;
@@ -1496,27 +1536,26 @@ function buildOrdinalMap(items) {
1496
1536
  });
1497
1537
  }
1498
1538
 
1539
+ function onScroll() {
1540
+ scheduleSweep();
1541
+ scanNearViewport();
1542
+ scheduleShowTick();
1543
+ }
1544
+
1499
1545
  function init() {
1500
1546
  installIO();
1501
1547
  installMO();
1502
1548
 
1503
- window.addEventListener('scroll', function () {
1504
- scheduleSweep();
1505
- scheduleShowTick();
1506
- }, { passive: true });
1507
-
1508
- window.addEventListener('resize', function () {
1509
- scheduleSweep();
1510
- scheduleShowTick();
1511
- }, { passive: true });
1549
+ window.addEventListener('scroll', onScroll, { passive: true });
1550
+ window.addEventListener('resize', onScroll, { passive: true });
1512
1551
 
1513
1552
  if (window.jQuery) {
1514
1553
  window.jQuery(window).on('action:ajaxify.end action:infiniteScroll.loaded', function () {
1515
- setTimeout(function () { installIO(); scheduleSweep(); scheduleShowTick(); }, 0);
1554
+ setTimeout(function () { installIO(); onScroll(); }, 0);
1516
1555
  });
1517
1556
  }
1518
1557
 
1519
- setTimeout(function () { installIO(); scheduleSweep(); scheduleShowTick(); }, 0);
1558
+ setTimeout(function () { installIO(); onScroll(); }, 0);
1520
1559
  }
1521
1560
 
1522
1561
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
@@ -1525,3 +1564,4 @@ function buildOrdinalMap(items) {
1525
1564
  // ===== /CLEAN REFRACTOR =====
1526
1565
 
1527
1566
 
1567
+