nodebb-plugin-ezoic-infinite 1.9.0 → 1.9.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 +26 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.9.0",
3
+ "version": "1.9.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
@@ -58,6 +58,7 @@
58
58
  };
59
59
 
60
60
  const FILL_SEL = 'iframe, ins, img, video, [data-google-container-id], div[id$="__container__"]';
61
+ const SUPPORTS_HAS = typeof CSS !== 'undefined' && !!CSS.supports?.('selector(:has(*))');
61
62
 
62
63
  // ── Utility ────────────────────────────────────────────────────────────────
63
64
 
@@ -108,10 +109,8 @@
108
109
 
109
110
  // ── DOM caches (burst-scoped) ──────────────────────────────────────────────
110
111
 
111
- let _postsCache = null, _postsCacheTs = 0;
112
- let _topicsCache = null, _topicsCacheTs = 0;
113
- let _catsCache = null, _catsCacheTs = 0;
114
112
  const POSTS_CACHE_MS = 200;
113
+ const _dc = { posts: null, postsAt: 0, topics: null, topicsAt: 0, cats: null, catsAt: 0 };
115
114
 
116
115
  function mutate(fn) {
117
116
  S.mutGuard++;
@@ -183,37 +182,41 @@
183
182
 
184
183
  function getPosts() {
185
184
  const t = now();
186
- if (_postsCache && t - _postsCacheTs < POSTS_CACHE_MS) return _postsCache;
187
- const all = document.querySelectorAll(SEL.post);
185
+ if (_dc.posts && t - _dc.postsAt < POSTS_CACHE_MS) return _dc.posts;
186
+ const all = SUPPORTS_HAS
187
+ ? document.querySelectorAll('[component="post"][data-pid]:has([component="post/content"])')
188
+ : document.querySelectorAll(SEL.post);
188
189
  const out = [];
189
190
  for (let i = 0; i < all.length; i++) {
190
191
  const el = all[i];
191
192
  if (!el.isConnected) continue;
192
- if (el.childElementCount === 0) continue;
193
- if (!el.querySelector('[component="post/content"]')) continue;
193
+ if (!SUPPORTS_HAS) {
194
+ if (el.childElementCount === 0) continue;
195
+ if (!el.querySelector('[component="post/content"]')) continue;
196
+ }
194
197
  const parent = el.parentElement?.closest(SEL.post);
195
198
  if (parent && parent !== el) continue;
196
199
  if (el.getAttribute('component') === 'post/parent') continue;
197
200
  out.push(el);
198
201
  }
199
- _postsCache = out;
200
- _postsCacheTs = t;
202
+ _dc.posts = out;
203
+ _dc.postsAt = t;
201
204
  return out;
202
205
  }
203
206
 
204
207
  function getTopics() {
205
208
  const t = now();
206
- if (_topicsCache && t - _topicsCacheTs < POSTS_CACHE_MS) return _topicsCache;
207
- _topicsCache = Array.from(document.querySelectorAll(SEL.topic));
208
- _topicsCacheTs = t;
209
- return _topicsCache;
209
+ if (_dc.topics && t - _dc.topicsAt < POSTS_CACHE_MS) return _dc.topics;
210
+ _dc.topics = Array.from(document.querySelectorAll(SEL.topic));
211
+ _dc.topicsAt = t;
212
+ return _dc.topics;
210
213
  }
211
214
  function getCategories() {
212
215
  const t = now();
213
- if (_catsCache && t - _catsCacheTs < POSTS_CACHE_MS) return _catsCache;
214
- _catsCache = Array.from(document.querySelectorAll(SEL.category));
215
- _catsCacheTs = t;
216
- return _catsCache;
216
+ if (_dc.cats && t - _dc.catsAt < POSTS_CACHE_MS) return _dc.cats;
217
+ _dc.cats = Array.from(document.querySelectorAll(SEL.category));
218
+ _dc.catsAt = t;
219
+ return _dc.cats;
217
220
  }
218
221
 
219
222
  // ── Anchor keys & wrap registry ────────────────────────────────────────────
@@ -270,22 +273,7 @@
270
273
  function wrapIsLive(wrap) {
271
274
  if (!wrap?.classList?.contains(WRAP_CLASS)) return false;
272
275
  const key = wrap.getAttribute(ATTR.ANCHOR);
273
- if (!key) return false;
274
- if (S.wrapByKey.get(key) === wrap) return wrap.isConnected;
275
- const colonIdx = key.indexOf(':');
276
- const klass = key.slice(0, colonIdx);
277
- const anchorId = key.slice(colonIdx + 1);
278
- const cfg = KIND[klass];
279
- if (!cfg) return false;
280
- const parent = wrap.parentElement;
281
- if (!parent) return false;
282
- const sel = `${cfg.baseTag || ''}[${cfg.anchorAttr}="${anchorId}"]`;
283
- for (const sib of parent.children) {
284
- if (sib !== wrap) {
285
- try { if (sib.matches(sel)) return sib.isConnected; } catch (_) {}
286
- }
287
- }
288
- return false;
276
+ return !!key && S.wrapByKey.get(key) === wrap && wrap.isConnected;
289
277
  }
290
278
 
291
279
  const adjacentWrap = el => wrapIsLive(el.nextElementSibling) || wrapIsLive(el.previousElementSibling);
@@ -436,12 +424,9 @@
436
424
  if (Number.isFinite(id)) {
437
425
  const timers = S.wrapTimers.get(id);
438
426
  if (timers) { for (const t of timers) clearTimeout(t); S.wrapTimers.delete(id); }
439
- if (!S.cleaningUp) {
440
- S.mountedIds.delete(id);
441
- S.lastShow.delete(id);
442
- }
443
427
  }
444
428
  if (!S.cleaningUp) {
429
+ if (Number.isFinite(id)) { S.mountedIds.delete(id); S.lastShow.delete(id); }
445
430
  const key = w.getAttribute(ATTR.ANCHOR);
446
431
  if (key && S.wrapByKey.get(key) === w) S.wrapByKey.delete(key);
447
432
  const colonIdx = key?.indexOf(':') ?? -1;
@@ -735,9 +720,9 @@
735
720
  S.wrapTimers.clear();
736
721
  S.domObs?.disconnect(); S.domObs = null;
737
722
  S.io?.disconnect(); S.io = null; _ioMobile = null;
738
- _postsCache = null; _postsCacheTs = 0;
739
- _topicsCache = null; _topicsCacheTs = 0;
740
- _catsCache = null; _catsCacheTs = 0;
723
+ _dc.posts = null; _dc.postsAt = 0;
724
+ _dc.topics = null; _dc.topicsAt = 0;
725
+ _dc.cats = null; _dc.catsAt = 0;
741
726
  // cfg/opts/pools are static for the session (window.__nbbEzoicCfg is set once
742
727
  // by the server and never changes between SPA navigations) — preserve them.
743
728
  S.cursors = { topics: 0, posts: 0, categories: 0 };
@@ -802,7 +787,7 @@
802
787
  }
803
788
  }
804
789
  }
805
- if (needsBurst) { _postsCacheTs = 0; _topicsCacheTs = 0; _catsCacheTs = 0; requestBurst(); }
790
+ if (needsBurst) { _dc.postsAt = 0; _dc.topicsAt = 0; _dc.catsAt = 0; requestBurst(); }
806
791
  });
807
792
  try {
808
793
  const target = document.getElementById('content') || document.body;