nodebb-plugin-ezoic-infinite 0.7.6 → 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 +32 -80
- 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,59 +139,18 @@ 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 || {};
|
|
193
146
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
194
147
|
|
|
195
148
|
const run = function () {
|
|
196
|
-
|
|
197
|
-
|
|
149
|
+
try {
|
|
150
|
+
if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
151
|
+
window.ezstandalone.destroyPlaceholders.apply(window.ezstandalone, ids);
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {}
|
|
198
154
|
try {
|
|
199
155
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
200
156
|
window.ezstandalone.showAds.apply(window.ezstandalone, ids);
|
|
@@ -204,28 +160,14 @@ function callEzoic(ids) {
|
|
|
204
160
|
return false;
|
|
205
161
|
};
|
|
206
162
|
|
|
207
|
-
setupAdAutoHeight();
|
|
208
163
|
window.ezstandalone.cmd.push(function () { run(); });
|
|
209
164
|
|
|
210
|
-
// Retry only if showAds isn't available yet (avoid duplicate calls)
|
|
211
165
|
let tries = 0;
|
|
212
166
|
const maxTries = 6;
|
|
213
|
-
const
|
|
167
|
+
const timer = setInterval(function () {
|
|
214
168
|
tries++;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
try {
|
|
218
|
-
if (typeof window.ezstandalone.showAds === 'function') return;
|
|
219
|
-
} catch (e) {}
|
|
220
|
-
if (tries < maxTries) setTimeout(retry, 800);
|
|
221
|
-
};
|
|
222
|
-
try {
|
|
223
|
-
if (typeof window.ezstandalone.showAds !== 'function') {
|
|
224
|
-
setTimeout(retry, 800);
|
|
225
|
-
}
|
|
226
|
-
} catch (e) {
|
|
227
|
-
setTimeout(retry, 800);
|
|
228
|
-
}
|
|
169
|
+
if (run() || tries >= maxTries) clearInterval(timer);
|
|
170
|
+
}, 800);
|
|
229
171
|
}
|
|
230
172
|
|
|
231
173
|
function getPostNumber($post) {
|
|
@@ -338,10 +280,8 @@ async function refreshAds() {
|
|
|
338
280
|
const messagePool = parsePool(cfg.messagePlaceholderIds);
|
|
339
281
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
340
282
|
|
|
341
|
-
const hasTopicList = isCategoryTopicListPage();
|
|
342
283
|
const onTopic = isTopicPage();
|
|
343
|
-
|
|
344
|
-
const onCategory = hasTopicList && !onTopic;
|
|
284
|
+
const onCategory = !onTopic && isCategoryTopicListPage();
|
|
345
285
|
|
|
346
286
|
const newIds = [];
|
|
347
287
|
|
|
@@ -375,32 +315,29 @@ function debounceRefresh() {
|
|
|
375
315
|
debounceTimer = setTimeout(refreshAds, 220);
|
|
376
316
|
}
|
|
377
317
|
|
|
378
|
-
$(document).ready(
|
|
318
|
+
$(document).ready(debounceRefresh);
|
|
379
319
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded action:topics.loaded action:category.loaded', debounceRefresh);
|
|
380
|
-
setTimeout(
|
|
320
|
+
setTimeout(debounceRefresh, 2200);
|
|
381
321
|
|
|
382
322
|
// Fallback: some themes/devices don't emit the expected events for infinite scroll.
|
|
383
323
|
// Observe DOM additions and trigger a refresh when new posts/topics are appended/prepended.
|
|
384
324
|
(function setupEzoicObserver() {
|
|
385
325
|
if (window.__ezoicInfiniteObserver) return;
|
|
386
326
|
try {
|
|
327
|
+
const trigger = function () { debounceRefresh(); };
|
|
328
|
+
|
|
329
|
+
// MutationObserver: trigger when new posts/topics are added anywhere in the page
|
|
387
330
|
const obs = new MutationObserver(function (mutations) {
|
|
388
331
|
for (const m of mutations) {
|
|
389
332
|
if (!m.addedNodes || !m.addedNodes.length) continue;
|
|
390
333
|
for (const n of m.addedNodes) {
|
|
391
334
|
if (!n || n.nodeType !== 1) continue;
|
|
392
|
-
// direct match
|
|
393
|
-
const inContent = (n.closest && n.closest('#content')) || (n.querySelector && n.querySelector('#content'));
|
|
394
|
-
if (!inContent && !document.querySelector('#content')) { /* if #content missing, proceed */ }
|
|
395
|
-
if (document.querySelector('#content') && !(n.closest && n.closest('#content'))) { continue; }
|
|
396
335
|
if (n.matches && (n.matches('[component="post"][data-pid]') || n.matches('li[component="category/topic"]'))) {
|
|
397
|
-
|
|
336
|
+
trigger();
|
|
398
337
|
return;
|
|
399
338
|
}
|
|
400
|
-
// descendant match
|
|
401
|
-
if (document.querySelector('#content') && !(n.closest && n.closest('#content'))) { continue; }
|
|
402
339
|
if (n.querySelector && (n.querySelector('[component="post"][data-pid]') || n.querySelector('li[component="category/topic"]'))) {
|
|
403
|
-
|
|
340
|
+
trigger();
|
|
404
341
|
return;
|
|
405
342
|
}
|
|
406
343
|
}
|
|
@@ -408,5 +345,20 @@ setTimeout(function(){ setupAdAutoHeight(); debounceRefresh(); }, 2200);
|
|
|
408
345
|
});
|
|
409
346
|
obs.observe(document.body, { childList: true, subtree: true });
|
|
410
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);
|
|
411
363
|
} catch (e) {}
|
|
412
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;}
|