nodebb-plugin-ezoic-infinite 0.6.0 → 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 +46 -15
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -28,28 +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
|
|
58
|
+
const $top = $('[data-pid]').filter(function () {
|
|
44
59
|
const $el = $(this);
|
|
45
60
|
const hasContent = $el.find('[component="post/content"]').length > 0;
|
|
46
61
|
const nested = $el.parents('[data-pid]').length > 0;
|
|
47
62
|
return hasContent && !nested;
|
|
48
|
-
})
|
|
63
|
+
});
|
|
64
|
+
return $top.not('.ezoic-ad-post');
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
function getCategoryTopicItems() {
|
|
52
|
-
if (!
|
|
68
|
+
if (!guessIsCategoryPage()) return $();
|
|
53
69
|
return $('li[component="category/topic"]').not('.ezoic-ad-topic');
|
|
54
70
|
}
|
|
55
71
|
|
|
@@ -58,7 +74,6 @@ function tagName($el) {
|
|
|
58
74
|
}
|
|
59
75
|
|
|
60
76
|
function removeExistingEzoicNodes() {
|
|
61
|
-
// Remove only the wrappers we created. Their inner placeholder divs go away with them.
|
|
62
77
|
$('.ezoic-ad-post').remove();
|
|
63
78
|
$('.ezoic-ad-between').remove();
|
|
64
79
|
$('.ezoic-ad-topic').remove();
|
|
@@ -122,16 +137,32 @@ function insertAdMessagesBetweenReplies($posts, ids, interval) {
|
|
|
122
137
|
return activeIds;
|
|
123
138
|
}
|
|
124
139
|
|
|
125
|
-
function
|
|
140
|
+
function ezoicRender(ids) {
|
|
126
141
|
if (!ids || !ids.length) return;
|
|
127
142
|
|
|
128
|
-
// Ezoic supports showAds(101,102,103) and recommends a single call with all ids.
|
|
129
143
|
window.ezstandalone = window.ezstandalone || {};
|
|
130
144
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
145
|
+
|
|
146
|
+
// Ezoic doc: showAds(101,102,103) within cmd.push for dynamic content citeturn0search0turn0search6
|
|
131
147
|
window.ezstandalone.cmd.push(function () {
|
|
148
|
+
try {
|
|
149
|
+
if (typeof window.ezstandalone.refreshAds === 'function') {
|
|
150
|
+
window.ezstandalone.refreshAds.apply(window.ezstandalone, ids);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {}
|
|
154
|
+
|
|
132
155
|
try {
|
|
133
156
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
134
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();
|
|
135
166
|
}
|
|
136
167
|
} catch (e) {}
|
|
137
168
|
});
|
|
@@ -176,21 +207,21 @@ async function refreshAds() {
|
|
|
176
207
|
|
|
177
208
|
const activeIds = [];
|
|
178
209
|
|
|
179
|
-
// Category pages: BETWEEN only
|
|
210
|
+
// Category pages: BETWEEN only
|
|
180
211
|
if ($topicItems.length) {
|
|
181
212
|
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
182
213
|
activeIds.push(...insertBetweenGeneric($topicItems, betweenPool, betweenInterval, 'ezoic-ad-topic'));
|
|
183
214
|
}
|
|
184
|
-
|
|
215
|
+
ezoicRender(activeIds);
|
|
185
216
|
return;
|
|
186
217
|
}
|
|
187
218
|
|
|
188
|
-
// Topic pages: MESSAGE only (
|
|
219
|
+
// Topic pages: MESSAGE only (as you requested)
|
|
189
220
|
if ($posts.length) {
|
|
190
221
|
if (cfg.enableMessageAds && messagePool.length) {
|
|
191
222
|
activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
|
|
192
223
|
}
|
|
193
|
-
|
|
224
|
+
ezoicRender(activeIds);
|
|
194
225
|
}
|
|
195
226
|
} finally {
|
|
196
227
|
inFlight = false;
|