nodebb-plugin-ezoic-infinite 0.6.8 → 0.7.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 +33 -1
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -189,6 +189,8 @@ function injectTopicMessageAds($posts, pool, interval) {
|
|
|
189
189
|
|
|
190
190
|
$posts.each(function () {
|
|
191
191
|
const $p = $(this);
|
|
192
|
+
// Never insert after the last real post: it can break NodeBB infinite scroll
|
|
193
|
+
if ($p.is($posts.last())) return;
|
|
192
194
|
const postNo = getPostNumber($p);
|
|
193
195
|
if (!Number.isFinite(postNo) || postNo <= 0) return;
|
|
194
196
|
|
|
@@ -226,6 +228,8 @@ function injectCategoryBetweenAds($items, pool, interval) {
|
|
|
226
228
|
|
|
227
229
|
$items.each(function () {
|
|
228
230
|
const $it = $(this);
|
|
231
|
+
// Never insert after the last real topic item (keeps NodeBB infinite scroll working)
|
|
232
|
+
if ($it.is($items.last())) return;
|
|
229
233
|
const pos = getTopicPos($it);
|
|
230
234
|
if (!Number.isFinite(pos) || pos <= 0) return;
|
|
231
235
|
|
|
@@ -315,5 +319,33 @@ function debounceRefresh() {
|
|
|
315
319
|
}
|
|
316
320
|
|
|
317
321
|
$(document).ready(debounceRefresh);
|
|
318
|
-
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded', debounceRefresh);
|
|
322
|
+
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded action:topics.loaded action:category.loaded', debounceRefresh);
|
|
319
323
|
setTimeout(debounceRefresh, 2200);
|
|
324
|
+
|
|
325
|
+
// Fallback: some themes/devices don't emit the expected events for infinite scroll.
|
|
326
|
+
// Observe DOM additions and trigger a refresh when new posts/topics are appended/prepended.
|
|
327
|
+
(function setupEzoicObserver() {
|
|
328
|
+
if (window.__ezoicInfiniteObserver) return;
|
|
329
|
+
try {
|
|
330
|
+
const obs = new MutationObserver(function (mutations) {
|
|
331
|
+
for (const m of mutations) {
|
|
332
|
+
if (!m.addedNodes || !m.addedNodes.length) continue;
|
|
333
|
+
for (const n of m.addedNodes) {
|
|
334
|
+
if (!n || n.nodeType !== 1) continue;
|
|
335
|
+
// direct match
|
|
336
|
+
if (n.matches && (n.matches('[component="post"][data-pid]') || n.matches('li[component="category/topic"]'))) {
|
|
337
|
+
debounceRefresh();
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
// descendant match
|
|
341
|
+
if (n.querySelector && (n.querySelector('[component="post"][data-pid]') || n.querySelector('li[component="category/topic"]'))) {
|
|
342
|
+
debounceRefresh();
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
obs.observe(document.body, { childList: true, subtree: true });
|
|
349
|
+
window.__ezoicInfiniteObserver = obs;
|
|
350
|
+
} catch (e) {}
|
|
351
|
+
})();
|