nodebb-plugin-ezoic-infinite 0.5.6 → 0.5.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/public/client.js +30 -14
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -127,6 +127,30 @@ function uniqueConcat(a, b) {
|
|
|
127
127
|
return out;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
function ezoicCall(ids) {
|
|
131
|
+
if (!ids || !ids.length) return;
|
|
132
|
+
|
|
133
|
+
// Queue calls until Ezoic is ready (recommended pattern)
|
|
134
|
+
window.ezstandalone = window.ezstandalone || {};
|
|
135
|
+
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
136
|
+
|
|
137
|
+
window.ezstandalone.cmd.push(function () {
|
|
138
|
+
try {
|
|
139
|
+
// IMPORTANT: destroy only the placeholders we are about to reuse,
|
|
140
|
+
// NOT all placeholders. Destroying too early/all can make ads disappear.
|
|
141
|
+
if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
142
|
+
window.ezstandalone.destroyPlaceholders.apply(window.ezstandalone, ids);
|
|
143
|
+
}
|
|
144
|
+
} catch (e) {}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
if (typeof window.ezstandalone.showAds === 'function') {
|
|
148
|
+
window.ezstandalone.showAds.apply(window.ezstandalone, ids);
|
|
149
|
+
}
|
|
150
|
+
} catch (e) {}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
130
154
|
async function refreshAds() {
|
|
131
155
|
let cfg;
|
|
132
156
|
try { cfg = await fetchConfig(); } catch (e) { return; }
|
|
@@ -150,14 +174,14 @@ async function refreshAds() {
|
|
|
150
174
|
|
|
151
175
|
const activeIds = [];
|
|
152
176
|
|
|
153
|
-
// Category topic list page
|
|
177
|
+
// Category topic list page
|
|
154
178
|
if (!$posts.length && $topicItems.length) {
|
|
155
179
|
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
156
180
|
activeIds.push(...insertBetweenGeneric($topicItems, combinedUnique.slice(0, betweenPool.length), betweenInterval, 'ezoic-ad-topic'));
|
|
157
181
|
}
|
|
158
182
|
}
|
|
159
183
|
|
|
160
|
-
// Topic page
|
|
184
|
+
// Topic page
|
|
161
185
|
if ($posts.length) {
|
|
162
186
|
let cursor = 0;
|
|
163
187
|
|
|
@@ -174,23 +198,15 @@ async function refreshAds() {
|
|
|
174
198
|
}
|
|
175
199
|
}
|
|
176
200
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
activeIds.forEach(id => {
|
|
181
|
-
try {
|
|
182
|
-
if (window.ezstandalone && typeof window.ezstandalone.showAds === 'function') {
|
|
183
|
-
window.ezstandalone.showAds(id);
|
|
184
|
-
}
|
|
185
|
-
} catch (e) {}
|
|
186
|
-
});
|
|
201
|
+
// Ask Ezoic to (re)fill ONLY the placeholders we inserted.
|
|
202
|
+
ezoicCall(activeIds);
|
|
187
203
|
}
|
|
188
204
|
|
|
189
205
|
function debounceRefresh() {
|
|
190
206
|
clearTimeout(debounceTimer);
|
|
191
|
-
debounceTimer = setTimeout(refreshAds,
|
|
207
|
+
debounceTimer = setTimeout(refreshAds, 180);
|
|
192
208
|
}
|
|
193
209
|
|
|
194
210
|
$(document).ready(debounceRefresh);
|
|
195
211
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded', debounceRefresh);
|
|
196
|
-
setTimeout(debounceRefresh,
|
|
212
|
+
setTimeout(debounceRefresh, 1800);
|