nodebb-plugin-ezoic-infinite 1.6.0 → 1.6.1

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 +88 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
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
@@ -1344,28 +1344,74 @@ function buildOrdinalMap(items) {
1344
1344
 
1345
1345
 
1346
1346
 
1347
+
1347
1348
  // ===== CLEAN REFRACTOR: visibility manager for Ezoic wraps =====
1348
1349
  (function () {
1349
- var WRAP_SELECTOR = '.nodebb-ezoic-wrap.ezoic-ad-between, .nodebb-ezoic-wrap.ezoic-ad-message';
1350
- var KEEP_MARGIN_PX_DESKTOP = 1600;
1351
- var KEEP_MARGIN_PX_MOBILE = 1100;
1352
- var MAX_REMOVALS_PER_SWEEP = 6;
1350
+ var BETWEEN_SELECTOR = '.nodebb-ezoic-wrap.ezoic-ad-between';
1351
+ var MESSAGE_SELECTOR = '.nodebb-ezoic-wrap.ezoic-ad-message';
1352
+ var WRAP_SELECTOR = BETWEEN_SELECTOR + ', ' + MESSAGE_SELECTOR;
1353
+
1354
+ var KEEP_MARGIN_BETWEEN_DESKTOP = 2600;
1355
+ var KEEP_MARGIN_BETWEEN_MOBILE = 1900;
1356
+
1357
+ var SHOW_COOLDOWN_MS = 1200;
1358
+ var MAX_SHOW_PER_TICK = 4;
1353
1359
 
1354
1360
  function isMobile() {
1355
1361
  try { return window.matchMedia && window.matchMedia('(max-width: 767px)').matches; } catch (e) { return false; }
1356
1362
  }
1357
- function keepMargin() { return isMobile() ? KEEP_MARGIN_PX_MOBILE : KEEP_MARGIN_PX_DESKTOP; }
1363
+ function keepMarginBetween() { return isMobile() ? KEEP_MARGIN_BETWEEN_MOBILE : KEEP_MARGIN_BETWEEN_DESKTOP; }
1358
1364
 
1359
- function removeFarWraps() {
1360
- var margin = keepMargin();
1365
+ var lastShowById = Object.create(null);
1366
+ var showQueue = [];
1367
+ var showTicking = false;
1368
+
1369
+ function getWrapId(w) {
1370
+ try { return w.getAttribute('data-ezoic-wrapid'); } catch (e) { return null; }
1371
+ }
1372
+
1373
+ function enqueueShow(id) {
1374
+ if (!id) return;
1375
+ var now = Date.now();
1376
+ var last = lastShowById[id] || 0;
1377
+ if (now - last < SHOW_COOLDOWN_MS) return;
1378
+
1379
+ for (var i = 0; i < showQueue.length; i++) if (showQueue[i] === id) return;
1380
+ showQueue.push(id);
1381
+ scheduleShowTick();
1382
+ }
1383
+
1384
+ function scheduleShowTick() {
1385
+ if (showTicking) return;
1386
+ showTicking = true;
1387
+ requestAnimationFrame(function () {
1388
+ showTicking = false;
1389
+ var n = 0;
1390
+ while (showQueue.length && n < MAX_SHOW_PER_TICK) {
1391
+ var id = showQueue.shift();
1392
+ try {
1393
+ if (window.ezstandalone && typeof window.ezstandalone.showAds === 'function') {
1394
+ window.ezstandalone.showAds(String(id));
1395
+ lastShowById[id] = Date.now();
1396
+ }
1397
+ } catch (e) {}
1398
+ n++;
1399
+ }
1400
+ if (showQueue.length) scheduleShowTick();
1401
+ });
1402
+ }
1403
+
1404
+ function removeFarBetweenWraps() {
1405
+ var margin = keepMarginBetween();
1361
1406
  var removed = 0;
1362
1407
  var wraps;
1363
- try { wraps = document.querySelectorAll(WRAP_SELECTOR); } catch (e) { return; }
1408
+ try { wraps = document.querySelectorAll(BETWEEN_SELECTOR); } catch (e) { return; }
1409
+
1364
1410
  wraps.forEach(function (w) {
1365
- if (removed >= MAX_REMOVALS_PER_SWEEP) return;
1411
+ if (removed >= 3) return;
1366
1412
  try {
1367
1413
  var lv = parseInt(w.getAttribute('data-last-visible') || '0', 10);
1368
- if (lv && (Date.now() - lv) < 8000) return;
1414
+ if (lv && (Date.now() - lv) < 12000) return;
1369
1415
 
1370
1416
  var r = w.getBoundingClientRect();
1371
1417
  if (r.bottom < -margin || r.top > ((window.innerHeight || 0) + margin)) {
@@ -1379,15 +1425,25 @@ function buildOrdinalMap(items) {
1379
1425
  var io = null;
1380
1426
  function installIO() {
1381
1427
  if (io || typeof IntersectionObserver === 'undefined') return;
1428
+
1382
1429
  io = new IntersectionObserver(function (entries) {
1383
1430
  try {
1384
1431
  entries.forEach(function (e) {
1385
- if (e && e.target && e.isIntersecting) {
1432
+ if (!e || !e.target) return;
1433
+ if (e.isIntersecting) {
1386
1434
  try { e.target.setAttribute('data-last-visible', String(Date.now())); } catch (err) {}
1435
+
1436
+ var id = getWrapId(e.target);
1437
+ 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) {}
1387
1443
  }
1388
1444
  });
1389
1445
  } catch (e) {}
1390
- }, { root: null, rootMargin: '0px', threshold: 0.01 });
1446
+ }, { root: null, rootMargin: '900px 0px 900px 0px', threshold: 0.01 });
1391
1447
 
1392
1448
  try { document.querySelectorAll(WRAP_SELECTOR).forEach(function (w) { try { io.observe(w); } catch(e) {} }); } catch (e) {}
1393
1449
  }
@@ -1396,6 +1452,7 @@ function buildOrdinalMap(items) {
1396
1452
  function installMO() {
1397
1453
  if (moInstalled || typeof MutationObserver === 'undefined') return;
1398
1454
  moInstalled = true;
1455
+
1399
1456
  var mo = new MutationObserver(function (muts) {
1400
1457
  if (!io) return;
1401
1458
  try {
@@ -1405,8 +1462,10 @@ function buildOrdinalMap(items) {
1405
1462
  for (var j = 0; j < m.addedNodes.length; j++) {
1406
1463
  var n = m.addedNodes[j];
1407
1464
  if (!n || n.nodeType !== 1) continue;
1465
+
1408
1466
  if (n.matches && n.matches(WRAP_SELECTOR)) {
1409
1467
  try { io.observe(n); } catch (e) {}
1468
+ try { var id = getWrapId(n); if (id) enqueueShow(id); } catch (e) {}
1410
1469
  } else if (n.querySelectorAll) {
1411
1470
  var inner = n.querySelectorAll(WRAP_SELECTOR);
1412
1471
  for (var k = 0; k < inner.length; k++) {
@@ -1417,12 +1476,13 @@ function buildOrdinalMap(items) {
1417
1476
  }
1418
1477
  } catch (e) {}
1419
1478
  });
1479
+
1420
1480
  try { mo.observe(document.documentElement || document.body, { childList: true, subtree: true }); } catch (e) {}
1421
1481
  }
1422
1482
 
1423
1483
  var sweepPending = false;
1424
1484
  var lastSweep = 0;
1425
- var SWEEP_COOLDOWN_MS = 250;
1485
+ var SWEEP_COOLDOWN_MS = 600;
1426
1486
 
1427
1487
  function scheduleSweep() {
1428
1488
  var now = Date.now();
@@ -1432,22 +1492,31 @@ function buildOrdinalMap(items) {
1432
1492
  requestAnimationFrame(function () {
1433
1493
  sweepPending = false;
1434
1494
  lastSweep = Date.now();
1435
- removeFarWraps();
1495
+ removeFarBetweenWraps();
1436
1496
  });
1437
1497
  }
1438
1498
 
1439
1499
  function init() {
1440
1500
  installIO();
1441
1501
  installMO();
1442
- window.addEventListener('scroll', scheduleSweep, { passive: true });
1443
- window.addEventListener('resize', scheduleSweep, { passive: true });
1502
+
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 });
1444
1512
 
1445
1513
  if (window.jQuery) {
1446
1514
  window.jQuery(window).on('action:ajaxify.end action:infiniteScroll.loaded', function () {
1447
- setTimeout(function () { installIO(); scheduleSweep(); }, 0);
1515
+ setTimeout(function () { installIO(); scheduleSweep(); scheduleShowTick(); }, 0);
1448
1516
  });
1449
1517
  }
1450
- setTimeout(function () { installIO(); scheduleSweep(); }, 0);
1518
+
1519
+ setTimeout(function () { installIO(); scheduleSweep(); scheduleShowTick(); }, 0);
1451
1520
  }
1452
1521
 
1453
1522
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
@@ -1455,3 +1524,4 @@ function buildOrdinalMap(items) {
1455
1524
  })();
1456
1525
  // ===== /CLEAN REFRACTOR =====
1457
1526
 
1527
+