nodebb-plugin-ezoic-infinite 0.7.5 → 0.7.7
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 +27 -78
- package/public/style.css +2 -5
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -58,10 +58,7 @@ async function fetchConfig() {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function isTopicPage() {
|
|
61
|
-
|
|
62
|
-
if (ajaxify && ajaxify.data && ajaxify.data.tid) return true;
|
|
63
|
-
} catch (e) {}
|
|
64
|
-
return /^\/topic\//.test(window.location.pathname);
|
|
61
|
+
return $('[component="post/content"]').length > 0 || $('[component="post"][data-pid]').length > 0;
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
function isCategoryTopicListPage() {
|
|
@@ -142,51 +139,7 @@ function removeOldestCategoryAd() {
|
|
|
142
139
|
return true;
|
|
143
140
|
}
|
|
144
141
|
|
|
145
|
-
|
|
146
|
-
function setupAdAutoHeight() {
|
|
147
|
-
if (window.__ezoicAutoHeightAttached) return;
|
|
148
|
-
window.__ezoicAutoHeightAttached = true;
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
const ro = new ResizeObserver(function (entries) {
|
|
152
|
-
for (const entry of entries) {
|
|
153
|
-
const el = entry.target;
|
|
154
|
-
el.style.minHeight = '0px';
|
|
155
|
-
el.style.height = 'auto';
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
function attach() {
|
|
160
|
-
document.querySelectorAll('.ezoic-ad').forEach(function (wrap) {
|
|
161
|
-
if (wrap.__ezoicRO) return;
|
|
162
|
-
wrap.__ezoicRO = true;
|
|
163
|
-
ro.observe(wrap);
|
|
164
|
-
|
|
165
|
-
const ph = wrap.querySelector('[id^="ezoic-pub-ad-placeholder-"]');
|
|
166
|
-
if (ph && ph.firstElementChild && !ph.firstElementChild.__ezoicRO) {
|
|
167
|
-
ph.firstElementChild.__ezoicRO = true;
|
|
168
|
-
ro.observe(ph.firstElementChild);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
attach();
|
|
174
|
-
setTimeout(attach, 500);
|
|
175
|
-
setTimeout(attach, 1500);
|
|
176
|
-
setTimeout(attach, 3000);
|
|
177
|
-
|
|
178
|
-
const mo = new MutationObserver(function () { attach(); });
|
|
179
|
-
mo.observe(document.body, { childList: true, subtree: true });
|
|
180
|
-
} catch (e) {}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
142
|
function callEzoic(ids) {
|
|
184
|
-
const key = Array.isArray(ids) ? ids.join(',') : String(ids);
|
|
185
|
-
if (window.__ezoicLastShowKey === key && Date.now() - (window.__ezoicLastShowAt || 0) < 2000) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
window.__ezoicLastShowKey = key;
|
|
189
|
-
window.__ezoicLastShowAt = Date.now();
|
|
190
143
|
if (!ids || !ids.length) return;
|
|
191
144
|
|
|
192
145
|
window.ezstandalone = window.ezstandalone || {};
|
|
@@ -207,28 +160,14 @@ function callEzoic(ids) {
|
|
|
207
160
|
return false;
|
|
208
161
|
};
|
|
209
162
|
|
|
210
|
-
setupAdAutoHeight();
|
|
211
163
|
window.ezstandalone.cmd.push(function () { run(); });
|
|
212
164
|
|
|
213
|
-
// Retry only if showAds isn't available yet (avoid duplicate calls)
|
|
214
165
|
let tries = 0;
|
|
215
166
|
const maxTries = 6;
|
|
216
|
-
const
|
|
167
|
+
const timer = setInterval(function () {
|
|
217
168
|
tries++;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
if (typeof window.ezstandalone.showAds === 'function') return;
|
|
222
|
-
} catch (e) {}
|
|
223
|
-
if (tries < maxTries) setTimeout(retry, 800);
|
|
224
|
-
};
|
|
225
|
-
try {
|
|
226
|
-
if (typeof window.ezstandalone.showAds !== 'function') {
|
|
227
|
-
setTimeout(retry, 800);
|
|
228
|
-
}
|
|
229
|
-
} catch (e) {
|
|
230
|
-
setTimeout(retry, 800);
|
|
231
|
-
}
|
|
169
|
+
if (run() || tries >= maxTries) clearInterval(timer);
|
|
170
|
+
}, 800);
|
|
232
171
|
}
|
|
233
172
|
|
|
234
173
|
function getPostNumber($post) {
|
|
@@ -341,10 +280,8 @@ async function refreshAds() {
|
|
|
341
280
|
const messagePool = parsePool(cfg.messagePlaceholderIds);
|
|
342
281
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
343
282
|
|
|
344
|
-
const hasTopicList = isCategoryTopicListPage();
|
|
345
283
|
const onTopic = isTopicPage();
|
|
346
|
-
|
|
347
|
-
const onCategory = hasTopicList && !onTopic;
|
|
284
|
+
const onCategory = !onTopic && isCategoryTopicListPage();
|
|
348
285
|
|
|
349
286
|
const newIds = [];
|
|
350
287
|
|
|
@@ -378,32 +315,29 @@ function debounceRefresh() {
|
|
|
378
315
|
debounceTimer = setTimeout(refreshAds, 220);
|
|
379
316
|
}
|
|
380
317
|
|
|
381
|
-
$(document).ready(
|
|
318
|
+
$(document).ready(debounceRefresh);
|
|
382
319
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded action:topics.loaded action:category.loaded', debounceRefresh);
|
|
383
|
-
setTimeout(
|
|
320
|
+
setTimeout(debounceRefresh, 2200);
|
|
384
321
|
|
|
385
322
|
// Fallback: some themes/devices don't emit the expected events for infinite scroll.
|
|
386
323
|
// Observe DOM additions and trigger a refresh when new posts/topics are appended/prepended.
|
|
387
324
|
(function setupEzoicObserver() {
|
|
388
325
|
if (window.__ezoicInfiniteObserver) return;
|
|
389
326
|
try {
|
|
327
|
+
const trigger = function () { debounceRefresh(); };
|
|
328
|
+
|
|
329
|
+
// MutationObserver: trigger when new posts/topics are added anywhere in the page
|
|
390
330
|
const obs = new MutationObserver(function (mutations) {
|
|
391
331
|
for (const m of mutations) {
|
|
392
332
|
if (!m.addedNodes || !m.addedNodes.length) continue;
|
|
393
333
|
for (const n of m.addedNodes) {
|
|
394
334
|
if (!n || n.nodeType !== 1) continue;
|
|
395
|
-
// direct match
|
|
396
|
-
const inContent = (n.closest && n.closest('#content')) || (n.querySelector && n.querySelector('#content'));
|
|
397
|
-
if (!inContent && !document.querySelector('#content')) { /* if #content missing, proceed */ }
|
|
398
|
-
if (document.querySelector('#content') && !(n.closest && n.closest('#content'))) { continue; }
|
|
399
335
|
if (n.matches && (n.matches('[component="post"][data-pid]') || n.matches('li[component="category/topic"]'))) {
|
|
400
|
-
|
|
336
|
+
trigger();
|
|
401
337
|
return;
|
|
402
338
|
}
|
|
403
|
-
// descendant match
|
|
404
|
-
if (document.querySelector('#content') && !(n.closest && n.closest('#content'))) { continue; }
|
|
405
339
|
if (n.querySelector && (n.querySelector('[component="post"][data-pid]') || n.querySelector('li[component="category/topic"]'))) {
|
|
406
|
-
|
|
340
|
+
trigger();
|
|
407
341
|
return;
|
|
408
342
|
}
|
|
409
343
|
}
|
|
@@ -411,5 +345,20 @@ setTimeout(function(){ setupAdAutoHeight(); debounceRefresh(); }, 2200);
|
|
|
411
345
|
});
|
|
412
346
|
obs.observe(document.body, { childList: true, subtree: true });
|
|
413
347
|
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);
|
|
414
363
|
} catch (e) {}
|
|
415
364
|
})();
|
package/public/style.css
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
.ezoic-ad{
|
|
2
|
-
.ezoic-ad-
|
|
3
|
-
.ezoic-ad-topic{margin:0.5rem 0;}
|
|
4
|
-
.ezoic-ad-message-inner{padding:0;margin:0;}
|
|
5
|
-
.ezoic-ad-message-inner > div{margin:0;padding:0;}
|
|
1
|
+
.ezoic-ad-post{margin:0.75rem 0;}
|
|
2
|
+
.ezoic-ad-message-inner{padding:0.75rem 0;}
|