nodebb-plugin-ezoic-infinite 0.8.2 → 0.8.3
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.
- package/package.json +1 -1
- package/public/client.js +39 -5
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -214,7 +214,30 @@ function callEzoic(ids) {
|
|
|
214
214
|
window.ezstandalone = window.ezstandalone || {};
|
|
215
215
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
const markAndFilterByIds = function (list) {
|
|
218
|
+
const out = [];
|
|
219
|
+
list.forEach(function (id) {
|
|
220
|
+
const sel = '.ezoic-ad[data-ezoic-id="' + id + '"]';
|
|
221
|
+
const wraps = document.querySelectorAll(sel);
|
|
222
|
+
let anyUnrendered = false;
|
|
223
|
+
wraps.forEach(function (w) {
|
|
224
|
+
if (w.getAttribute('data-ezoic-rendered') !== '1') {
|
|
225
|
+
anyUnrendered = true;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
if (!wraps.length) {
|
|
229
|
+
// fallback: if wrapper is missing, allow showAds (Ezoic might still handle placeholder)
|
|
230
|
+
out.push(id);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (anyUnrendered) {
|
|
234
|
+
wraps.forEach(function (w) { w.setAttribute('data-ezoic-rendered', '1'); });
|
|
235
|
+
out.push(id);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return out;
|
|
239
|
+
};
|
|
240
|
+
|
|
218
241
|
const collect = function () {
|
|
219
242
|
const list = [];
|
|
220
243
|
document.querySelectorAll('.ezoic-ad').forEach(function (wrap) {
|
|
@@ -224,16 +247,25 @@ function callEzoic(ids) {
|
|
|
224
247
|
const idStr = ph.id.replace('ezoic-pub-ad-placeholder-', '');
|
|
225
248
|
const id = parseInt(idStr, 10);
|
|
226
249
|
if (!Number.isFinite(id) || id <= 0) return;
|
|
227
|
-
|
|
228
250
|
wrap.setAttribute('data-ezoic-rendered', '1');
|
|
229
251
|
list.push(id);
|
|
230
252
|
});
|
|
231
253
|
return Array.from(new Set(list));
|
|
232
254
|
};
|
|
233
255
|
|
|
234
|
-
const
|
|
256
|
+
const input = (ids && ids.length) ? Array.from(new Set(ids)) : null;
|
|
257
|
+
const toShow = input ? markAndFilterByIds(input) : collect();
|
|
235
258
|
if (!toShow.length) return;
|
|
236
259
|
|
|
260
|
+
// De-dupe rapid duplicate calls (observer/poller can fire twice)
|
|
261
|
+
const key = toShow.join(',');
|
|
262
|
+
const now = Date.now();
|
|
263
|
+
if (window.__ezoicLastShowKey === key && (now - (window.__ezoicLastShowAt || 0)) < 1200) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
window.__ezoicLastShowKey = key;
|
|
267
|
+
window.__ezoicLastShowAt = now;
|
|
268
|
+
|
|
237
269
|
const run = function () {
|
|
238
270
|
try {
|
|
239
271
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
@@ -247,13 +279,16 @@ function callEzoic(ids) {
|
|
|
247
279
|
setupAdAutoHeight();
|
|
248
280
|
window.ezstandalone.cmd.push(function () { run(); });
|
|
249
281
|
|
|
250
|
-
// Retry if
|
|
282
|
+
// Retry only if showAds isn't available yet
|
|
251
283
|
let tries = 0;
|
|
252
284
|
const maxTries = 6;
|
|
253
285
|
const retry = function () {
|
|
254
286
|
tries++;
|
|
255
287
|
const ok = run();
|
|
256
288
|
if (ok) return;
|
|
289
|
+
try {
|
|
290
|
+
if (typeof window.ezstandalone.showAds === 'function') return;
|
|
291
|
+
} catch (e) {}
|
|
257
292
|
if (tries < maxTries) setTimeout(retry, 800);
|
|
258
293
|
};
|
|
259
294
|
|
|
@@ -410,7 +445,6 @@ async function refreshAds() {
|
|
|
410
445
|
newIds.push(...injectTopicMessageAds($posts, messagePool, messageInterval));
|
|
411
446
|
}
|
|
412
447
|
callEzoic(newIds);
|
|
413
|
-
callEzoic();
|
|
414
448
|
}
|
|
415
449
|
} finally {
|
|
416
450
|
inFlight = false;
|