nodebb-plugin-ezoic-infinite 0.7.3 → 0.7.4

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 +29 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
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
@@ -58,7 +58,11 @@ async function fetchConfig() {
58
58
  }
59
59
 
60
60
  function isTopicPage() {
61
- return $('[component="post/content"]').length > 0 || $('[component="post"][data-pid]').length > 0;
61
+ try {
62
+ if (ajaxify && ajaxify.data && ajaxify.data.tid) return true;
63
+ } catch (e) {}
64
+ if (/^\/topic\//.test(window.location.pathname)) return true;
65
+ return $('[component="post/content"]').length > 0;
62
66
  }
63
67
 
64
68
  function isCategoryTopicListPage() {
@@ -178,6 +182,12 @@ function setupAdAutoHeight() {
178
182
  }
179
183
 
180
184
  function callEzoic(ids) {
185
+ const key = Array.isArray(ids) ? ids.join(',') : String(ids);
186
+ if (window.__ezoicLastShowKey === key && Date.now() - (window.__ezoicLastShowAt || 0) < 2000) {
187
+ return;
188
+ }
189
+ window.__ezoicLastShowKey = key;
190
+ window.__ezoicLastShowAt = Date.now();
181
191
  if (!ids || !ids.length) return;
182
192
 
183
193
  window.ezstandalone = window.ezstandalone || {};
@@ -201,12 +211,25 @@ function callEzoic(ids) {
201
211
  setupAdAutoHeight();
202
212
  window.ezstandalone.cmd.push(function () { run(); });
203
213
 
214
+ // Retry only if showAds isn't available yet (avoid duplicate calls)
204
215
  let tries = 0;
205
216
  const maxTries = 6;
206
- const timer = setInterval(function () {
217
+ const retry = function () {
207
218
  tries++;
208
- if (run() || tries >= maxTries) clearInterval(timer);
209
- }, 800);
219
+ const ok = run();
220
+ if (ok) return;
221
+ try {
222
+ if (typeof window.ezstandalone.showAds === 'function') return;
223
+ } catch (e) {}
224
+ if (tries < maxTries) setTimeout(retry, 800);
225
+ };
226
+ try {
227
+ if (typeof window.ezstandalone.showAds !== 'function') {
228
+ setTimeout(retry, 800);
229
+ }
230
+ } catch (e) {
231
+ setTimeout(retry, 800);
232
+ }
210
233
  }
211
234
 
212
235
  function getPostNumber($post) {
@@ -320,7 +343,8 @@ async function refreshAds() {
320
343
  const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
321
344
 
322
345
  const onTopic = isTopicPage();
323
- const onCategory = !onTopic && isCategoryTopicListPage();
346
+ const hasTopicList = isCategoryTopicListPage();
347
+ const onCategory = !onTopic && hasTopicList;
324
348
 
325
349
  const newIds = [];
326
350