nodebb-plugin-ezoic-infinite 0.8.5 → 0.8.6

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 +21 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
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
@@ -114,9 +114,18 @@ function pickNextId(pool, usedSet) {
114
114
  if (!usedSet.has(id)) return id;
115
115
  }
116
116
  return null;
117
+ } finally {
118
+ window.__ezoicRecycling = false;
119
+ }
117
120
  }
118
121
 
119
122
  function destroyEzoicId(id) {
123
+ window.__ezoicLastDestroy = window.__ezoicLastDestroy || {};
124
+ const now = Date.now();
125
+ if (window.__ezoicLastDestroy[id] && now - window.__ezoicLastDestroy[id] < 2000) {
126
+ return;
127
+ }
128
+ window.__ezoicLastDestroy[id] = now;
120
129
  try {
121
130
  window.ezstandalone = window.ezstandalone || {};
122
131
  window.ezstandalone.cmd = window.ezstandalone.cmd || [];
@@ -133,6 +142,9 @@ function destroyEzoicId(id) {
133
142
  }
134
143
 
135
144
  function recycleOldestTopicId($posts) {
145
+ if (window.__ezoicRecycling) return null;
146
+ window.__ezoicRecycling = true;
147
+ try {
136
148
  if (!fifo.length) return null;
137
149
  fifo.sort((a, b) => a.afterPostNo - b.afterPostNo);
138
150
 
@@ -157,9 +169,15 @@ function recycleOldestTopicId($posts) {
157
169
  return old.id;
158
170
  }
159
171
  return null;
172
+ } finally {
173
+ window.__ezoicRecycling = false;
174
+ }
160
175
  }
161
176
 
162
177
  function recycleOldestCategoryId($items) {
178
+ if (window.__ezoicRecycling) return null;
179
+ window.__ezoicRecycling = true;
180
+ try {
163
181
  if (!fifoCat.length) return null;
164
182
  fifoCat.sort((a, b) => a.afterPos - b.afterPos);
165
183
 
@@ -402,6 +420,9 @@ function injectCategoryBetweenAds($items, pool, interval) {
402
420
  }
403
421
 
404
422
  async function refreshAds() {
423
+ const now = Date.now();
424
+ if (window.__ezoicRefreshThrottle && now - window.__ezoicRefreshThrottle < 250) return;
425
+ window.__ezoicRefreshThrottle = now;
405
426
  const key = getPageKey();
406
427
  if (pageKey !== key) {
407
428
  pageKey = key;