nodebb-plugin-ezoic-infinite 1.0.10 → 1.0.13
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 +45 -11
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* globals ajaxify */
|
|
4
4
|
(function () {
|
|
5
|
+
try {
|
|
5
6
|
if (window.ezoicInfiniteLoaded) return;
|
|
6
7
|
window.ezoicInfiniteLoaded = true;
|
|
7
8
|
|
|
@@ -23,16 +24,20 @@
|
|
|
23
24
|
|
|
24
25
|
function getPageKey() {
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
27
|
+
const ax = window.ajaxify;
|
|
28
|
+
if (ax && ax.data) {
|
|
29
|
+
if (ax.data.tid) return 'topic:' + ax.data.tid;
|
|
30
|
+
if (ax.data.cid) return 'cid:' + ax.data.cid + ':' + window.location.pathname;
|
|
29
31
|
}
|
|
30
32
|
} catch (e) {}
|
|
31
33
|
return window.location.pathname;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
function isTopicPage() {
|
|
35
|
-
try {
|
|
37
|
+
try {
|
|
38
|
+
const ax = window.ajaxify;
|
|
39
|
+
return !!(ax && ax.data && ax.data.tid);
|
|
40
|
+
} catch (e) {}
|
|
36
41
|
return /^\/topic\//.test(window.location.pathname);
|
|
37
42
|
}
|
|
38
43
|
|
|
@@ -121,18 +126,38 @@
|
|
|
121
126
|
function callShowAdsSingle(id) {
|
|
122
127
|
if (!id) return;
|
|
123
128
|
|
|
129
|
+
// Normalize id key
|
|
130
|
+
const key = String(id);
|
|
131
|
+
|
|
132
|
+
// Ensure we never call showAds twice for the same id within a short window
|
|
124
133
|
const now = Date.now();
|
|
125
134
|
window.__ezoicLastSingle = window.__ezoicLastSingle || {};
|
|
126
|
-
const last = window.__ezoicLastSingle[
|
|
135
|
+
const last = window.__ezoicLastSingle[key] || 0;
|
|
127
136
|
if (now - last < 4000) return;
|
|
128
|
-
|
|
137
|
+
|
|
138
|
+
// If showAds is ready now, call once and exit (no cmd + no retry)
|
|
139
|
+
try {
|
|
140
|
+
window.ezstandalone = window.ezstandalone || {};
|
|
141
|
+
if (typeof window.ezstandalone.showAds === 'function') {
|
|
142
|
+
window.__ezoicLastSingle[key] = now;
|
|
143
|
+
window.ezstandalone.showAds(id);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
} catch (e) {}
|
|
147
|
+
|
|
148
|
+
// Otherwise: schedule a single pending call via cmd + retries until it succeeds
|
|
149
|
+
window.__ezoicPending = window.__ezoicPending || {};
|
|
150
|
+
if (window.__ezoicPending[key]) return;
|
|
151
|
+
window.__ezoicPending[key] = true;
|
|
129
152
|
|
|
130
153
|
window.ezstandalone = window.ezstandalone || {};
|
|
131
154
|
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
132
155
|
|
|
133
|
-
const
|
|
156
|
+
const tryRun = function () {
|
|
134
157
|
try {
|
|
135
158
|
if (typeof window.ezstandalone.showAds === 'function') {
|
|
159
|
+
window.__ezoicLastSingle[key] = Date.now();
|
|
160
|
+
delete window.__ezoicPending[key];
|
|
136
161
|
window.ezstandalone.showAds(id);
|
|
137
162
|
return true;
|
|
138
163
|
}
|
|
@@ -140,12 +165,17 @@
|
|
|
140
165
|
return false;
|
|
141
166
|
};
|
|
142
167
|
|
|
143
|
-
|
|
168
|
+
// When Ezoic finishes loading, it will drain cmd; run once there
|
|
169
|
+
window.ezstandalone.cmd.push(function () { tryRun(); });
|
|
144
170
|
|
|
171
|
+
// Retry a few times in case cmd doesn't fire (race conditions)
|
|
145
172
|
let tries = 0;
|
|
146
173
|
(function tick() {
|
|
147
174
|
tries++;
|
|
148
|
-
if (
|
|
175
|
+
if (tryRun() || tries >= 8) {
|
|
176
|
+
if (tries >= 8) delete window.__ezoicPending[key];
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
149
179
|
setTimeout(tick, 800);
|
|
150
180
|
})();
|
|
151
181
|
}
|
|
@@ -266,7 +296,7 @@
|
|
|
266
296
|
injectBetweenTopics(cfg);
|
|
267
297
|
} else {
|
|
268
298
|
window.__ezoicCatRetry = window.__ezoicCatRetry || 0;
|
|
269
|
-
if (window.__ezoicCatRetry <
|
|
299
|
+
if (window.__ezoicCatRetry < 20) {
|
|
270
300
|
window.__ezoicCatRetry++;
|
|
271
301
|
setTimeout(run, 250);
|
|
272
302
|
}
|
|
@@ -293,7 +323,7 @@ function bindNodeBBEvents() {
|
|
|
293
323
|
if (window.jQuery) {
|
|
294
324
|
const $w = window.jQuery(window);
|
|
295
325
|
$w.off('.ezoicInfinite');
|
|
296
|
-
$w.on('action:ajaxify.end.ezoicInfinite', scheduleRun);
|
|
326
|
+
$w.on('action:ajaxify.end.ezoicInfinite', function(){ scheduleRun(); setTimeout(scheduleRun, 600); });
|
|
297
327
|
$w.on('action:posts.loaded.ezoicInfinite', scheduleRun);
|
|
298
328
|
$w.on('action:topic.loaded.ezoicInfinite', scheduleRun);
|
|
299
329
|
$w.on('action:topics.loaded.ezoicInfinite', scheduleRun);
|
|
@@ -323,4 +353,8 @@ function bindNodeBBEvents() {
|
|
|
323
353
|
setTimeout(run, 1200);
|
|
324
354
|
});
|
|
325
355
|
}
|
|
356
|
+
;
|
|
357
|
+
} catch (e) {
|
|
358
|
+
// fail silently to avoid breaking NodeBB
|
|
359
|
+
}
|
|
326
360
|
})();
|