nodebb-plugin-ezoic-infinite 0.7.6 → 0.7.9
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 +17 -57
- 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,22 @@ 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) {
|
|
143
|
+
if (!ids || !ids.length) return;
|
|
144
|
+
|
|
145
|
+
// Prevent duplicate calls (observer/poller can fire multiple times)
|
|
184
146
|
const key = Array.isArray(ids) ? ids.join(',') : String(ids);
|
|
185
|
-
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
if (window.__ezoicLastShowKey === key && (now - (window.__ezoicLastShowAt || 0)) < 2500) {
|
|
186
149
|
return;
|
|
187
150
|
}
|
|
188
151
|
window.__ezoicLastShowKey = key;
|
|
189
|
-
window.__ezoicLastShowAt =
|
|
190
|
-
if (!ids || !ids.length) return;
|
|
152
|
+
window.__ezoicLastShowAt = now;
|
|
191
153
|
|
|
192
154
|
window.ezstandalone = window.ezstandalone || {};
|
|
193
155
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
194
156
|
|
|
195
157
|
const run = function () {
|
|
196
|
-
// destroyPlaceholders is only needed when placeholder IDs are reused.
|
|
197
|
-
// This plugin avoids reusing IDs on the same page, so we skip it to prevent Ezoic from removing valid placeholders.
|
|
198
158
|
try {
|
|
199
159
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
200
160
|
window.ezstandalone.showAds.apply(window.ezstandalone, ids);
|
|
@@ -207,7 +167,7 @@ function callEzoic(ids) {
|
|
|
207
167
|
setupAdAutoHeight();
|
|
208
168
|
window.ezstandalone.cmd.push(function () { run(); });
|
|
209
169
|
|
|
210
|
-
// Retry only if showAds isn't available yet
|
|
170
|
+
// Retry only if showAds isn't available yet
|
|
211
171
|
let tries = 0;
|
|
212
172
|
const maxTries = 6;
|
|
213
173
|
const retry = function () {
|
|
@@ -219,6 +179,7 @@ function callEzoic(ids) {
|
|
|
219
179
|
} catch (e) {}
|
|
220
180
|
if (tries < maxTries) setTimeout(retry, 800);
|
|
221
181
|
};
|
|
182
|
+
|
|
222
183
|
try {
|
|
223
184
|
if (typeof window.ezstandalone.showAds !== 'function') {
|
|
224
185
|
setTimeout(retry, 800);
|
|
@@ -318,6 +279,11 @@ function injectCategoryBetweenAds($items, pool, interval) {
|
|
|
318
279
|
}
|
|
319
280
|
|
|
320
281
|
async function refreshAds() {
|
|
282
|
+
const now = Date.now();
|
|
283
|
+
if (window.__ezoicLastRefreshAt && now - window.__ezoicLastRefreshAt < 400) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
window.__ezoicLastRefreshAt = now;
|
|
321
287
|
const key = getPageKey();
|
|
322
288
|
if (pageKey !== key) {
|
|
323
289
|
pageKey = key;
|
|
@@ -338,10 +304,8 @@ async function refreshAds() {
|
|
|
338
304
|
const messagePool = parsePool(cfg.messagePlaceholderIds);
|
|
339
305
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
340
306
|
|
|
341
|
-
const hasTopicList = isCategoryTopicListPage();
|
|
342
307
|
const onTopic = isTopicPage();
|
|
343
|
-
|
|
344
|
-
const onCategory = hasTopicList && !onTopic;
|
|
308
|
+
const onCategory = !onTopic && isCategoryTopicListPage();
|
|
345
309
|
|
|
346
310
|
const newIds = [];
|
|
347
311
|
|
|
@@ -375,9 +339,9 @@ function debounceRefresh() {
|
|
|
375
339
|
debounceTimer = setTimeout(refreshAds, 220);
|
|
376
340
|
}
|
|
377
341
|
|
|
378
|
-
$(document).ready(
|
|
342
|
+
$(document).ready(debounceRefresh);
|
|
379
343
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded action:topics.loaded action:category.loaded', debounceRefresh);
|
|
380
|
-
setTimeout(
|
|
344
|
+
setTimeout(debounceRefresh, 2200);
|
|
381
345
|
|
|
382
346
|
// Fallback: some themes/devices don't emit the expected events for infinite scroll.
|
|
383
347
|
// Observe DOM additions and trigger a refresh when new posts/topics are appended/prepended.
|
|
@@ -390,15 +354,11 @@ setTimeout(function(){ setupAdAutoHeight(); debounceRefresh(); }, 2200);
|
|
|
390
354
|
for (const n of m.addedNodes) {
|
|
391
355
|
if (!n || n.nodeType !== 1) continue;
|
|
392
356
|
// 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
357
|
if (n.matches && (n.matches('[component="post"][data-pid]') || n.matches('li[component="category/topic"]'))) {
|
|
397
358
|
debounceRefresh();
|
|
398
359
|
return;
|
|
399
360
|
}
|
|
400
361
|
// descendant match
|
|
401
|
-
if (document.querySelector('#content') && !(n.closest && n.closest('#content'))) { continue; }
|
|
402
362
|
if (n.querySelector && (n.querySelector('[component="post"][data-pid]') || n.querySelector('li[component="category/topic"]'))) {
|
|
403
363
|
debounceRefresh();
|
|
404
364
|
return;
|
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;}
|