nodebb-plugin-ezoic-infinite 0.6.6 → 0.6.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/plugin.json +4 -1
- package/public/client.js +18 -21
- package/public/style.css +2 -0
package/package.json
CHANGED
package/plugin.json
CHANGED
package/public/client.js
CHANGED
|
@@ -12,12 +12,12 @@ let rerunRequested = false;
|
|
|
12
12
|
|
|
13
13
|
// Per-page incremental state
|
|
14
14
|
let pageKey = null;
|
|
15
|
-
let
|
|
15
|
+
let seenSlots = new Set(); // slots already processed (never cleared on eviction)
|
|
16
16
|
let usedIds = new Set(); // IDs currently present in DOM
|
|
17
17
|
let adsFIFO = []; // [{slot, id}] oldest first
|
|
18
18
|
|
|
19
19
|
function resetPageState() {
|
|
20
|
-
|
|
20
|
+
seenSlots = new Set();
|
|
21
21
|
usedIds = new Set();
|
|
22
22
|
adsFIFO = [];
|
|
23
23
|
}
|
|
@@ -58,23 +58,24 @@ function isCategoryTopicListPage() {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function getTopicPosts() {
|
|
61
|
+
// Only real posts
|
|
61
62
|
const $primary = $('[component="post"][data-pid]');
|
|
62
|
-
if ($primary.length) return $primary
|
|
63
|
+
if ($primary.length) return $primary;
|
|
63
64
|
|
|
65
|
+
// Fallback: top-level with post/content
|
|
64
66
|
return $('[data-pid]').filter(function () {
|
|
65
67
|
const $el = $(this);
|
|
66
68
|
const hasContent = $el.find('[component="post/content"]').length > 0;
|
|
67
69
|
const nested = $el.parents('[data-pid]').length > 0;
|
|
68
70
|
return hasContent && !nested;
|
|
69
|
-
})
|
|
71
|
+
});
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
function getCategoryTopicItems() {
|
|
73
|
-
return $('li[component="category/topic"]')
|
|
75
|
+
return $('li[component="category/topic"]');
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
//
|
|
77
|
-
// If posts/topics are in a <ul>/<ol>, the wrapper MUST be a <li> or the browser may move it outside the list (often to the top).
|
|
78
|
+
// If target's parent is UL/OL, wrapper MUST be LI (otherwise browser may move it to top)
|
|
78
79
|
function wrapperTagFor($target) {
|
|
79
80
|
if (!$target || !$target.length) return 'div';
|
|
80
81
|
const parentTag = ($target.parent().prop('tagName') || '').toUpperCase();
|
|
@@ -94,7 +95,7 @@ function makeWrapperLike($target, classes, innerHtml, attrs) {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
function cleanupWrappersOnNav() {
|
|
97
|
-
$('.ezoic-ad-post, .ezoic-ad-
|
|
98
|
+
$('.ezoic-ad-post, .ezoic-ad-topic, .ezoic-ad-between').remove();
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
function pickNextId(pool) {
|
|
@@ -112,7 +113,6 @@ function evictOldestOne() {
|
|
|
112
113
|
const $el = $(sel);
|
|
113
114
|
if ($el.length) $el.remove();
|
|
114
115
|
|
|
115
|
-
injectedSlots.delete(old.slot);
|
|
116
116
|
usedIds.delete(old.id);
|
|
117
117
|
return true;
|
|
118
118
|
}
|
|
@@ -152,7 +152,7 @@ function injectBetweenIncremental($items, pool, interval, wrapperClass) {
|
|
|
152
152
|
const newIds = [];
|
|
153
153
|
|
|
154
154
|
for (let slot = 1; slot <= maxSlot; slot++) {
|
|
155
|
-
if (
|
|
155
|
+
if (seenSlots.has(slot)) continue;
|
|
156
156
|
|
|
157
157
|
const index = slot * interval - 1;
|
|
158
158
|
const $target = $items.eq(index);
|
|
@@ -168,14 +168,14 @@ function injectBetweenIncremental($items, pool, interval, wrapperClass) {
|
|
|
168
168
|
const placeholder = '<div id="ezoic-pub-ad-placeholder-' + id + '"></div>';
|
|
169
169
|
const html = makeWrapperLike(
|
|
170
170
|
$target,
|
|
171
|
-
wrapperClass,
|
|
171
|
+
wrapperClass + ' ezoic-ad',
|
|
172
172
|
placeholder,
|
|
173
173
|
'data-ezoic-slot="' + slot + '" data-ezoic-id="' + id + '"'
|
|
174
174
|
);
|
|
175
175
|
|
|
176
176
|
$target.after(html);
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
seenSlots.add(slot);
|
|
179
179
|
usedIds.add(id);
|
|
180
180
|
adsFIFO.push({ slot: slot, id: id });
|
|
181
181
|
newIds.push(id);
|
|
@@ -192,7 +192,7 @@ function injectMessageIncremental($posts, pool, interval) {
|
|
|
192
192
|
const newIds = [];
|
|
193
193
|
|
|
194
194
|
for (let slot = 1; slot <= maxSlot; slot++) {
|
|
195
|
-
if (
|
|
195
|
+
if (seenSlots.has(slot)) continue;
|
|
196
196
|
|
|
197
197
|
const index = slot * interval - 1;
|
|
198
198
|
const $target = $posts.eq(index);
|
|
@@ -205,17 +205,18 @@ function injectMessageIncremental($posts, pool, interval) {
|
|
|
205
205
|
if (!id) break;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
|
|
208
|
+
// Do NOT use class "post" nor component="post" for ads: can break NodeBB infinite scroll.
|
|
209
|
+
const inner = '<div class="ezoic-ad-message-inner"><div id="ezoic-pub-ad-placeholder-' + id + '"></div></div>';
|
|
209
210
|
const html = makeWrapperLike(
|
|
210
211
|
$target,
|
|
211
|
-
'post ezoic-ad
|
|
212
|
+
'ezoic-ad-post ezoic-ad',
|
|
212
213
|
inner,
|
|
213
214
|
'data-ezoic-slot="' + slot + '" data-ezoic-id="' + id + '"'
|
|
214
215
|
);
|
|
215
216
|
|
|
216
217
|
$target.after(html);
|
|
217
218
|
|
|
218
|
-
|
|
219
|
+
seenSlots.add(slot);
|
|
219
220
|
usedIds.add(id);
|
|
220
221
|
adsFIFO.push({ slot: slot, id: id });
|
|
221
222
|
newIds.push(id);
|
|
@@ -225,7 +226,6 @@ function injectMessageIncremental($posts, pool, interval) {
|
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
async function refreshAds() {
|
|
228
|
-
// Reset state on navigation
|
|
229
229
|
const key = currentPageKey();
|
|
230
230
|
if (pageKey !== key) {
|
|
231
231
|
pageKey = key;
|
|
@@ -256,9 +256,6 @@ async function refreshAds() {
|
|
|
256
256
|
|
|
257
257
|
const newIds = [];
|
|
258
258
|
|
|
259
|
-
// Your rule:
|
|
260
|
-
// - Category topic list: BETWEEN only
|
|
261
|
-
// - Topic page: MESSAGE only
|
|
262
259
|
if ($topicItems.length) {
|
|
263
260
|
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
264
261
|
newIds.push(...injectBetweenIncremental($topicItems, betweenPool, betweenInterval, 'ezoic-ad-topic'));
|
|
@@ -284,7 +281,7 @@ async function refreshAds() {
|
|
|
284
281
|
|
|
285
282
|
function debounceRefresh() {
|
|
286
283
|
clearTimeout(debounceTimer);
|
|
287
|
-
debounceTimer = setTimeout(refreshAds,
|
|
284
|
+
debounceTimer = setTimeout(refreshAds, 200);
|
|
288
285
|
}
|
|
289
286
|
|
|
290
287
|
$(document).ready(debounceRefresh);
|
package/public/style.css
ADDED