nodebb-plugin-ezoic-infinite 0.5.9 → 0.6.1
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 +41 -35
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -28,32 +28,44 @@ function parsePool(raw) {
|
|
|
28
28
|
));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function
|
|
32
|
-
|
|
31
|
+
function guessIsTopicPage() {
|
|
32
|
+
// Prefer ajaxify template, fallback to DOM presence
|
|
33
|
+
try {
|
|
34
|
+
if (ajaxify && ajaxify.data && ajaxify.data.template) {
|
|
35
|
+
return ['topic', 'topicEvents'].includes(ajaxify.data.template);
|
|
36
|
+
}
|
|
37
|
+
} catch (e) {}
|
|
38
|
+
return $('[component="post/content"]').length > 0;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
function
|
|
36
|
-
|
|
41
|
+
function guessIsCategoryPage() {
|
|
42
|
+
try {
|
|
43
|
+
if (ajaxify && ajaxify.data && ajaxify.data.template) {
|
|
44
|
+
return ajaxify.data.template === 'category';
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {}
|
|
47
|
+
return $('li[component="category/topic"]').length > 0;
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
function getTopicPosts() {
|
|
40
|
-
if (!
|
|
51
|
+
if (!guessIsTopicPage()) return $();
|
|
52
|
+
|
|
53
|
+
// Harmony standard wrapper
|
|
41
54
|
const $primary = $('[component="post"][data-pid]');
|
|
42
55
|
if ($primary.length) return $primary.not('.ezoic-ad-post');
|
|
43
56
|
|
|
57
|
+
// Fallback: top-level data-pid that contains post content and isn't nested
|
|
44
58
|
const $top = $('[data-pid]').filter(function () {
|
|
45
59
|
const $el = $(this);
|
|
46
60
|
const hasContent = $el.find('[component="post/content"]').length > 0;
|
|
47
61
|
const nested = $el.parents('[data-pid]').length > 0;
|
|
48
62
|
return hasContent && !nested;
|
|
49
63
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return $('.posts .post').not('.ezoic-ad-post');
|
|
64
|
+
return $top.not('.ezoic-ad-post');
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
function getCategoryTopicItems() {
|
|
56
|
-
if (!
|
|
68
|
+
if (!guessIsCategoryPage()) return $();
|
|
57
69
|
return $('li[component="category/topic"]').not('.ezoic-ad-topic');
|
|
58
70
|
}
|
|
59
71
|
|
|
@@ -65,7 +77,6 @@ function removeExistingEzoicNodes() {
|
|
|
65
77
|
$('.ezoic-ad-post').remove();
|
|
66
78
|
$('.ezoic-ad-between').remove();
|
|
67
79
|
$('.ezoic-ad-topic').remove();
|
|
68
|
-
$('[id^="ezoic-pub-ad-placeholder-"]').remove();
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
function computeWindowSlots(totalItems, interval, poolSize) {
|
|
@@ -126,34 +137,32 @@ function insertAdMessagesBetweenReplies($posts, ids, interval) {
|
|
|
126
137
|
return activeIds;
|
|
127
138
|
}
|
|
128
139
|
|
|
129
|
-
function
|
|
130
|
-
const seen = new Set();
|
|
131
|
-
const out = [];
|
|
132
|
-
[...a, ...b].forEach((x) => {
|
|
133
|
-
if (!seen.has(x)) {
|
|
134
|
-
seen.add(x);
|
|
135
|
-
out.push(x);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
return out;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function ezoicCall(ids) {
|
|
140
|
+
function ezoicRender(ids) {
|
|
142
141
|
if (!ids || !ids.length) return;
|
|
143
142
|
|
|
144
143
|
window.ezstandalone = window.ezstandalone || {};
|
|
145
144
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
146
145
|
|
|
146
|
+
// Ezoic doc: showAds(101,102,103) within cmd.push for dynamic content citeturn0search0turn0search6
|
|
147
147
|
window.ezstandalone.cmd.push(function () {
|
|
148
148
|
try {
|
|
149
|
-
if (typeof window.ezstandalone.
|
|
150
|
-
window.ezstandalone.
|
|
149
|
+
if (typeof window.ezstandalone.refreshAds === 'function') {
|
|
150
|
+
window.ezstandalone.refreshAds.apply(window.ezstandalone, ids);
|
|
151
|
+
return;
|
|
151
152
|
}
|
|
152
153
|
} catch (e) {}
|
|
153
154
|
|
|
154
155
|
try {
|
|
155
156
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
156
157
|
window.ezstandalone.showAds.apply(window.ezstandalone, ids);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
} catch (e) {}
|
|
161
|
+
|
|
162
|
+
// Last resort: call showAds() with no args = "all placeholders" citeturn0search0turn0search6
|
|
163
|
+
try {
|
|
164
|
+
if (typeof window.ezstandalone.showAds === 'function') {
|
|
165
|
+
window.ezstandalone.showAds();
|
|
157
166
|
}
|
|
158
167
|
} catch (e) {}
|
|
159
168
|
});
|
|
@@ -196,32 +205,29 @@ async function refreshAds() {
|
|
|
196
205
|
|
|
197
206
|
removeExistingEzoicNodes();
|
|
198
207
|
|
|
199
|
-
const combinedUnique = uniqueConcat(betweenPool, messagePool);
|
|
200
208
|
const activeIds = [];
|
|
201
209
|
|
|
202
|
-
// Category
|
|
210
|
+
// Category pages: BETWEEN only
|
|
203
211
|
if ($topicItems.length) {
|
|
204
212
|
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
205
|
-
activeIds.push(...insertBetweenGeneric($topicItems,
|
|
213
|
+
activeIds.push(...insertBetweenGeneric($topicItems, betweenPool, betweenInterval, 'ezoic-ad-topic'));
|
|
206
214
|
}
|
|
207
|
-
|
|
215
|
+
ezoicRender(activeIds);
|
|
208
216
|
return;
|
|
209
217
|
}
|
|
210
218
|
|
|
211
|
-
// Topic
|
|
219
|
+
// Topic pages: MESSAGE only (as you requested)
|
|
212
220
|
if ($posts.length) {
|
|
213
221
|
if (cfg.enableMessageAds && messagePool.length) {
|
|
214
|
-
|
|
215
|
-
const idsForMessage = combinedUnique.slice(0, messagePool.length);
|
|
216
|
-
activeIds.push(...insertAdMessagesBetweenReplies($posts, idsForMessage, messageInterval));
|
|
222
|
+
activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
|
|
217
223
|
}
|
|
218
|
-
|
|
224
|
+
ezoicRender(activeIds);
|
|
219
225
|
}
|
|
220
226
|
} finally {
|
|
221
227
|
inFlight = false;
|
|
222
228
|
if (rerunRequested) {
|
|
223
229
|
rerunRequested = false;
|
|
224
|
-
setTimeout(refreshAds,
|
|
230
|
+
setTimeout(refreshAds, 80);
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
}
|