nodebb-plugin-ezoic-infinite 0.7.9 → 0.8.0
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 +25 -17
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -140,24 +140,35 @@ function removeOldestCategoryAd() {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
function callEzoic(ids) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// Prevent duplicate calls (observer/poller can fire multiple times)
|
|
146
|
-
const key = Array.isArray(ids) ? ids.join(',') : String(ids);
|
|
147
|
-
const now = Date.now();
|
|
148
|
-
if (window.__ezoicLastShowKey === key && (now - (window.__ezoicLastShowAt || 0)) < 2500) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
window.__ezoicLastShowKey = key;
|
|
152
|
-
window.__ezoicLastShowAt = now;
|
|
153
|
-
|
|
143
|
+
// ids optional; if omitted, we will scan DOM for unrendered placeholders
|
|
154
144
|
window.ezstandalone = window.ezstandalone || {};
|
|
155
145
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
156
146
|
|
|
147
|
+
const collect = function () {
|
|
148
|
+
const list = [];
|
|
149
|
+
document.querySelectorAll('.ezoic-ad [id^="ezoic-pub-ad-placeholder-"]').forEach(function (ph) {
|
|
150
|
+
const idStr = ph.id.replace('ezoic-pub-ad-placeholder-', '');
|
|
151
|
+
const id = parseInt(idStr, 10);
|
|
152
|
+
if (!Number.isFinite(id) || id <= 0) return;
|
|
153
|
+
|
|
154
|
+
const wrap = ph.closest('.ezoic-ad');
|
|
155
|
+
if (!wrap) return;
|
|
156
|
+
if (wrap.getAttribute('data-ezoic-rendered') === '1') return;
|
|
157
|
+
|
|
158
|
+
list.push(id);
|
|
159
|
+
wrap.setAttribute('data-ezoic-rendered', '1');
|
|
160
|
+
});
|
|
161
|
+
// de-dupe
|
|
162
|
+
return Array.from(new Set(list));
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const toShow = (ids && ids.length) ? Array.from(new Set(ids)) : collect();
|
|
166
|
+
if (!toShow.length) return;
|
|
167
|
+
|
|
157
168
|
const run = function () {
|
|
158
169
|
try {
|
|
159
170
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
160
|
-
window.ezstandalone.showAds.apply(window.ezstandalone,
|
|
171
|
+
window.ezstandalone.showAds.apply(window.ezstandalone, toShow);
|
|
161
172
|
return true;
|
|
162
173
|
}
|
|
163
174
|
} catch (e) {}
|
|
@@ -279,11 +290,6 @@ function injectCategoryBetweenAds($items, pool, interval) {
|
|
|
279
290
|
}
|
|
280
291
|
|
|
281
292
|
async function refreshAds() {
|
|
282
|
-
const now = Date.now();
|
|
283
|
-
if (window.__ezoicLastRefreshAt && now - window.__ezoicLastRefreshAt < 400) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
window.__ezoicLastRefreshAt = now;
|
|
287
293
|
const key = getPageKey();
|
|
288
294
|
if (pageKey !== key) {
|
|
289
295
|
pageKey = key;
|
|
@@ -315,6 +321,7 @@ async function refreshAds() {
|
|
|
315
321
|
newIds.push(...injectCategoryBetweenAds($items, betweenPool, betweenInterval));
|
|
316
322
|
}
|
|
317
323
|
callEzoic(newIds);
|
|
324
|
+
callEzoic();
|
|
318
325
|
return;
|
|
319
326
|
}
|
|
320
327
|
|
|
@@ -324,6 +331,7 @@ async function refreshAds() {
|
|
|
324
331
|
newIds.push(...injectTopicMessageAds($posts, messagePool, messageInterval));
|
|
325
332
|
}
|
|
326
333
|
callEzoic(newIds);
|
|
334
|
+
callEzoic();
|
|
327
335
|
}
|
|
328
336
|
} finally {
|
|
329
337
|
inFlight = false;
|