nodebb-plugin-ezoic-infinite 1.0.6 → 1.0.8
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 +54 -13
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -40,7 +40,27 @@
|
|
|
40
40
|
return document.querySelectorAll('li[component="category/topic"]').length > 0 && !isTopicPage();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
|
|
44
|
+
function normalizeBool(v) {
|
|
45
|
+
return v === true || v === 1 || v === '1' || v === 'on' || v === 'true' || v === 'yes';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function normalizeInterval(v, fallback) {
|
|
49
|
+
const n = parseInt(v, 10);
|
|
50
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getPoolValue(v) {
|
|
54
|
+
// Accept string, array of numbers/strings
|
|
55
|
+
if (Array.isArray(v)) return v.join('\n');
|
|
56
|
+
return v;
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
function parsePool(raw) {
|
|
60
|
+
raw = getPoolValue(raw);
|
|
61
|
+
|
|
62
|
+
raw = getPoolValue(raw);
|
|
63
|
+
|
|
44
64
|
if (!raw) return [];
|
|
45
65
|
// accept newline, comma, space, semicolon
|
|
46
66
|
const arr = String(raw).split(/[\n,;\s]+/)
|
|
@@ -153,8 +173,8 @@
|
|
|
153
173
|
}
|
|
154
174
|
|
|
155
175
|
function injectBetweenTopics(cfg) {
|
|
156
|
-
if (!cfg.enableBetweenAds) return;
|
|
157
|
-
const interval =
|
|
176
|
+
if (!normalizeBool(cfg.enableBetweenAds)) return;
|
|
177
|
+
const interval = normalizeInterval(cfg.intervalPosts ?? cfg.intervalTopics, 6);
|
|
158
178
|
const pool = parsePool(cfg.placeholderIds);
|
|
159
179
|
if (!pool.length) return;
|
|
160
180
|
|
|
@@ -184,8 +204,8 @@
|
|
|
184
204
|
}
|
|
185
205
|
|
|
186
206
|
function injectBetweenMessages(cfg) {
|
|
187
|
-
if (!cfg.enableMessageAds) return;
|
|
188
|
-
const interval =
|
|
207
|
+
if (!normalizeBool(cfg.enableMessageAds)) return;
|
|
208
|
+
const interval = normalizeInterval(cfg.messageIntervalPosts, 3);
|
|
189
209
|
const pool = parsePool(cfg.messagePlaceholderIds);
|
|
190
210
|
if (!pool.length) return;
|
|
191
211
|
|
|
@@ -246,14 +266,35 @@
|
|
|
246
266
|
debounceTimer = setTimeout(run, 150);
|
|
247
267
|
}
|
|
248
268
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
269
|
+
function bindNodeBBEvents() {
|
|
270
|
+
// NodeBB triggers these events through jQuery on window
|
|
271
|
+
if (window.jQuery) {
|
|
272
|
+
const $w = window.jQuery(window);
|
|
273
|
+
$w.off('.ezoicInfinite');
|
|
274
|
+
$w.on('action:ajaxify.end.ezoicInfinite', scheduleRun);
|
|
275
|
+
$w.on('action:posts.loaded.ezoicInfinite', scheduleRun);
|
|
276
|
+
$w.on('action:topic.loaded.ezoicInfinite', scheduleRun);
|
|
277
|
+
$w.on('action:topics.loaded.ezoicInfinite', scheduleRun);
|
|
278
|
+
$w.on('action:category.loaded.ezoicInfinite', scheduleRun);
|
|
279
|
+
$w.on('action:ajaxify.start.ezoicInfinite', function () {
|
|
280
|
+
pageKey = null;
|
|
281
|
+
cleanupForNewPage();
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
253
285
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
286
|
+
bindNodeBBEvents();
|
|
287
|
+
|
|
288
|
+
// Run immediately, so it works on first ajaxify navigation too
|
|
289
|
+
run();
|
|
290
|
+
setTimeout(run, 1200);
|
|
291
|
+
|
|
292
|
+
// Also run on hard-refresh initial load
|
|
293
|
+
if (document.readyState === 'loading') {
|
|
294
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
295
|
+
bindNodeBBEvents();
|
|
296
|
+
run();
|
|
297
|
+
setTimeout(run, 1200);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
259
300
|
})();
|