nodebb-plugin-ezoic-infinite 0.7.7 → 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 +47 -31
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -140,34 +140,64 @@ function removeOldestCategoryAd() {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
function callEzoic(ids) {
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
// ids optional; if omitted, we will scan DOM for unrendered placeholders
|
|
145
144
|
window.ezstandalone = window.ezstandalone || {};
|
|
146
145
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
147
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
|
+
|
|
148
168
|
const run = function () {
|
|
149
|
-
try {
|
|
150
|
-
if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
151
|
-
window.ezstandalone.destroyPlaceholders.apply(window.ezstandalone, ids);
|
|
152
|
-
}
|
|
153
|
-
} catch (e) {}
|
|
154
169
|
try {
|
|
155
170
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
156
|
-
window.ezstandalone.showAds.apply(window.ezstandalone,
|
|
171
|
+
window.ezstandalone.showAds.apply(window.ezstandalone, toShow);
|
|
157
172
|
return true;
|
|
158
173
|
}
|
|
159
174
|
} catch (e) {}
|
|
160
175
|
return false;
|
|
161
176
|
};
|
|
162
177
|
|
|
178
|
+
setupAdAutoHeight();
|
|
163
179
|
window.ezstandalone.cmd.push(function () { run(); });
|
|
164
180
|
|
|
181
|
+
// Retry only if showAds isn't available yet
|
|
165
182
|
let tries = 0;
|
|
166
183
|
const maxTries = 6;
|
|
167
|
-
const
|
|
184
|
+
const retry = function () {
|
|
168
185
|
tries++;
|
|
169
|
-
|
|
170
|
-
|
|
186
|
+
const ok = run();
|
|
187
|
+
if (ok) return;
|
|
188
|
+
try {
|
|
189
|
+
if (typeof window.ezstandalone.showAds === 'function') return;
|
|
190
|
+
} catch (e) {}
|
|
191
|
+
if (tries < maxTries) setTimeout(retry, 800);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
if (typeof window.ezstandalone.showAds !== 'function') {
|
|
196
|
+
setTimeout(retry, 800);
|
|
197
|
+
}
|
|
198
|
+
} catch (e) {
|
|
199
|
+
setTimeout(retry, 800);
|
|
200
|
+
}
|
|
171
201
|
}
|
|
172
202
|
|
|
173
203
|
function getPostNumber($post) {
|
|
@@ -291,6 +321,7 @@ async function refreshAds() {
|
|
|
291
321
|
newIds.push(...injectCategoryBetweenAds($items, betweenPool, betweenInterval));
|
|
292
322
|
}
|
|
293
323
|
callEzoic(newIds);
|
|
324
|
+
callEzoic();
|
|
294
325
|
return;
|
|
295
326
|
}
|
|
296
327
|
|
|
@@ -300,6 +331,7 @@ async function refreshAds() {
|
|
|
300
331
|
newIds.push(...injectTopicMessageAds($posts, messagePool, messageInterval));
|
|
301
332
|
}
|
|
302
333
|
callEzoic(newIds);
|
|
334
|
+
callEzoic();
|
|
303
335
|
}
|
|
304
336
|
} finally {
|
|
305
337
|
inFlight = false;
|
|
@@ -324,20 +356,19 @@ setTimeout(debounceRefresh, 2200);
|
|
|
324
356
|
(function setupEzoicObserver() {
|
|
325
357
|
if (window.__ezoicInfiniteObserver) return;
|
|
326
358
|
try {
|
|
327
|
-
const trigger = function () { debounceRefresh(); };
|
|
328
|
-
|
|
329
|
-
// MutationObserver: trigger when new posts/topics are added anywhere in the page
|
|
330
359
|
const obs = new MutationObserver(function (mutations) {
|
|
331
360
|
for (const m of mutations) {
|
|
332
361
|
if (!m.addedNodes || !m.addedNodes.length) continue;
|
|
333
362
|
for (const n of m.addedNodes) {
|
|
334
363
|
if (!n || n.nodeType !== 1) continue;
|
|
364
|
+
// direct match
|
|
335
365
|
if (n.matches && (n.matches('[component="post"][data-pid]') || n.matches('li[component="category/topic"]'))) {
|
|
336
|
-
|
|
366
|
+
debounceRefresh();
|
|
337
367
|
return;
|
|
338
368
|
}
|
|
369
|
+
// descendant match
|
|
339
370
|
if (n.querySelector && (n.querySelector('[component="post"][data-pid]') || n.querySelector('li[component="category/topic"]'))) {
|
|
340
|
-
|
|
371
|
+
debounceRefresh();
|
|
341
372
|
return;
|
|
342
373
|
}
|
|
343
374
|
}
|
|
@@ -345,20 +376,5 @@ setTimeout(debounceRefresh, 2200);
|
|
|
345
376
|
});
|
|
346
377
|
obs.observe(document.body, { childList: true, subtree: true });
|
|
347
378
|
window.__ezoicInfiniteObserver = obs;
|
|
348
|
-
|
|
349
|
-
// Poller fallback: if some renders bypass observers/events, detect count changes
|
|
350
|
-
let lastPostCount = 0;
|
|
351
|
-
let lastTopicCount = 0;
|
|
352
|
-
setInterval(function () {
|
|
353
|
-
try {
|
|
354
|
-
const posts = document.querySelectorAll('[component="post"][data-pid]').length;
|
|
355
|
-
const topics = document.querySelectorAll('li[component="category/topic"]').length;
|
|
356
|
-
if (posts !== lastPostCount || topics !== lastTopicCount) {
|
|
357
|
-
lastPostCount = posts;
|
|
358
|
-
lastTopicCount = topics;
|
|
359
|
-
trigger();
|
|
360
|
-
}
|
|
361
|
-
} catch (e) {}
|
|
362
|
-
}, 1500);
|
|
363
379
|
} catch (e) {}
|
|
364
380
|
})();
|