nodebb-plugin-ezoic-infinite 1.0.8 → 1.0.10

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 +34 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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
@@ -111,13 +111,20 @@
111
111
  destroyPlaceholder(id);
112
112
  }
113
113
 
114
+ function showAdsOnceForElement(wrapperEl, id) {
115
+ if (!wrapperEl || !id) return;
116
+ if (wrapperEl.getAttribute('data-ezoic-shown') === '1') return;
117
+ wrapperEl.setAttribute('data-ezoic-shown', '1');
118
+ callShowAdsSingle(id);
119
+ }
120
+
114
121
  function callShowAdsSingle(id) {
115
122
  if (!id) return;
116
123
 
117
124
  const now = Date.now();
118
125
  window.__ezoicLastSingle = window.__ezoicLastSingle || {};
119
126
  const last = window.__ezoicLastSingle[id] || 0;
120
- if (now - last < 1200) return;
127
+ if (now - last < 4000) return;
121
128
  window.__ezoicLastSingle[id] = now;
122
129
 
123
130
  window.ezstandalone = window.ezstandalone || {};
@@ -170,6 +177,7 @@
170
177
  wrap.setAttribute('data-ezoic-after', String(afterVal));
171
178
  wrap.innerHTML = '<div class="ezoic-ad-inner"><div id="ezoic-pub-ad-placeholder-' + id + '"></div></div>';
172
179
  targetEl.insertAdjacentElement('afterend', wrap);
180
+ return wrap;
173
181
  }
174
182
 
175
183
  function injectBetweenTopics(cfg) {
@@ -198,8 +206,8 @@
198
206
  usedBetween.add(id);
199
207
  fifoBetween.push({ id, after: pos });
200
208
 
201
- insertAfter(li, id, 'ezoic-ad-between', pos);
202
- callShowAdsSingle(id);
209
+ const wrap = insertAfter(li, id, 'ezoic-ad-between', pos);
210
+ showAdsOnceForElement(wrap, id);
203
211
  });
204
212
  }
205
213
 
@@ -229,8 +237,8 @@
229
237
  usedMessage.add(id);
230
238
  fifoMessage.push({ id, after: no });
231
239
 
232
- insertAfter(post, id, 'ezoic-ad-message', no);
233
- callShowAdsSingle(id);
240
+ const wrap = insertAfter(post, id, 'ezoic-ad-message', no);
241
+ showAdsOnceForElement(wrap, id);
234
242
  });
235
243
  }
236
244
 
@@ -243,13 +251,27 @@
243
251
  if (pageKey !== key) {
244
252
  pageKey = key;
245
253
  cleanupForNewPage();
254
+ window.__ezoicCatRetry = 0;
246
255
  }
247
256
 
248
257
  const cfg = await fetchConfig();
249
258
  if (!cfg || cfg.excluded) return;
250
259
 
251
- if (isTopicPage()) injectBetweenMessages(cfg);
252
- else if (isCategoryTopicList()) injectBetweenTopics(cfg);
260
+ if (isTopicPage()) {
261
+ injectBetweenMessages(cfg);
262
+ } else {
263
+ // category/topic list pages may render after ajaxify end; retry a few times
264
+ const hasList = document.querySelectorAll('li[component="category/topic"]').length > 0;
265
+ if (hasList) {
266
+ injectBetweenTopics(cfg);
267
+ } else {
268
+ window.__ezoicCatRetry = window.__ezoicCatRetry || 0;
269
+ if (window.__ezoicCatRetry < 10) {
270
+ window.__ezoicCatRetry++;
271
+ setTimeout(run, 250);
272
+ }
273
+ }
274
+ }
253
275
  } catch (e) {
254
276
  // silent
255
277
  } finally {
@@ -279,6 +301,7 @@ function bindNodeBBEvents() {
279
301
  $w.on('action:ajaxify.start.ezoicInfinite', function () {
280
302
  pageKey = null;
281
303
  cleanupForNewPage();
304
+ window.__ezoicCatRetry = 0;
282
305
  });
283
306
  }
284
307
  }
@@ -287,7 +310,10 @@ function bindNodeBBEvents() {
287
310
 
288
311
  // Run immediately, so it works on first ajaxify navigation too
289
312
  run();
290
- setTimeout(run, 1200);
313
+ setTimeout(function(){
314
+ // only retry if nothing was injected yet
315
+ if (!document.querySelector('.ezoic-ad')) run();
316
+ }, 1400);
291
317
 
292
318
  // Also run on hard-refresh initial load
293
319
  if (document.readyState === 'loading') {