nodebb-plugin-ezoic-infinite 0.8.3 → 0.8.5

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 +28 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -25,7 +25,8 @@ let fifoCat = []; // [{afterPos, id}]
25
25
  function resetState() {
26
26
  seenAfterPostNo = new Set();
27
27
  seenAfterTopicPos = new Set();
28
- usedIds = new Set();
28
+ usedIdsMsg = new Set();
29
+ usedIdsBetween = new Set();
29
30
  fifo = [];
30
31
  fifoCat = [];
31
32
  }
@@ -108,9 +109,9 @@ function cleanupOnNav() {
108
109
  $('.ezoic-ad-post, .ezoic-ad-topic').remove();
109
110
  }
110
111
 
111
- function pickNextId(pool) {
112
+ function pickNextId(pool, usedSet) {
112
113
  for (const id of pool) {
113
- if (!usedIds.has(id)) return id;
114
+ if (!usedSet.has(id)) return id;
114
115
  }
115
116
  return null;
116
117
  }
@@ -151,7 +152,7 @@ function recycleOldestTopicId($posts) {
151
152
  } catch (e) {}
152
153
 
153
154
  $el.remove();
154
- usedIds.delete(old.id);
155
+ usedIdsMsg.delete(old.id);
155
156
  destroyEzoicId(old.id);
156
157
  return old.id;
157
158
  }
@@ -177,7 +178,7 @@ function recycleOldestCategoryId($items) {
177
178
  } catch (e) {}
178
179
 
179
180
  $el.remove();
180
- usedIds.delete(old.id);
181
+ usedIdsBetween.delete(old.id);
181
182
  destroyEzoicId(old.id);
182
183
  return old.id;
183
184
  }
@@ -336,7 +337,7 @@ function injectTopicMessageAds($posts, pool, interval) {
336
337
  if (postNo % interval !== 0) return;
337
338
  if (seenAfterPostNo.has(postNo)) return;
338
339
 
339
- let id = pickNextId(pool);
340
+ let id = pickNextId(pool, usedIdsMsg);
340
341
  if (!id) {
341
342
  id = recycleOldestTopicId($posts);
342
343
  if (!id) return;
@@ -353,7 +354,7 @@ function injectTopicMessageAds($posts, pool, interval) {
353
354
  $p.after(html);
354
355
 
355
356
  seenAfterPostNo.add(postNo);
356
- usedIds.add(id);
357
+ usedIdsMsg.add(id);
357
358
  fifo.push({ afterPostNo: postNo, id: id });
358
359
  newIds.push(id);
359
360
  });
@@ -375,7 +376,7 @@ function injectCategoryBetweenAds($items, pool, interval) {
375
376
  if (pos % interval !== 0) return;
376
377
  if (seenAfterTopicPos.has(pos)) return;
377
378
 
378
- let id = pickNextId(pool);
379
+ let id = pickNextId(pool, usedIdsBetween);
379
380
  if (!id) {
380
381
  id = recycleOldestCategoryId($items);
381
382
  if (!id) return;
@@ -392,7 +393,7 @@ function injectCategoryBetweenAds($items, pool, interval) {
392
393
  $it.after(html);
393
394
 
394
395
  seenAfterTopicPos.add(pos);
395
- usedIds.add(id);
396
+ usedIdsBetween.add(id);
396
397
  fifoCat.push({ afterPos: pos, id: id });
397
398
  newIds.push(id);
398
399
  });
@@ -462,6 +463,24 @@ function debounceRefresh() {
462
463
 
463
464
  $(document).ready(function () { setupAdAutoHeight(); debounceRefresh(); });
464
465
 
466
+ $(window).on('action:ajaxify.start', function (ev, data) {
467
+ // IMPORTANT: do not cleanup on infinite scroll loads; only when navigating to a different page.
468
+ try {
469
+ const targetUrl = (data && (data.url || data.href)) ? String(data.url || data.href) : '';
470
+ if (targetUrl) {
471
+ const a = document.createElement('a');
472
+ a.href = targetUrl;
473
+ const targetPath = a.pathname || targetUrl;
474
+ // If we're staying on the same logical page (same path), don't wipe ads/state
475
+ if (targetPath === window.location.pathname) {
476
+ return;
477
+ }
478
+ }
479
+ } catch (e) {}
480
+ pageKey = null;
481
+ resetState();
482
+ cleanupOnNav();
483
+ });
465
484
  $(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded action:topics.loaded action:category.loaded', debounceRefresh);
466
485
 
467
486
  setTimeout(function () { setupAdAutoHeight(); debounceRefresh(); }, 2200);