nodebb-plugin-ezoic-infinite 0.9.5 → 0.9.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 +4 -1
- package/public/client.js +54 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-ezoic-infinite",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,5 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"nbbpm": {
|
|
18
|
+
"compatibility": "^4.0.0"
|
|
16
19
|
}
|
|
17
20
|
}
|
package/public/client.js
CHANGED
|
@@ -92,19 +92,62 @@ function pickNextId(pool) {
|
|
|
92
92
|
}
|
|
93
93
|
return null;
|
|
94
94
|
}
|
|
95
|
+
function callEzoic(ids) {
|
|
96
|
+
if (!ids || !ids.length) return;
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
const key = ids.slice().sort((a, b) => a - b).join(',');
|
|
99
|
+
const now = Date.now();
|
|
100
|
+
if (window.__ezoicLastShowKey === key && now - (window.__ezoicLastShowAt || 0) < 1200) return;
|
|
101
|
+
window.__ezoicLastShowKey = key;
|
|
102
|
+
window.__ezoicLastShowAt = now;
|
|
98
103
|
|
|
99
|
-
window.ezstandalone = window.ezstandalone || {};
|
|
100
|
-
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
101
|
-
|
|
102
|
-
const run = function () {
|
|
103
104
|
try {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
window.ezstandalone = window.ezstandalone || {};
|
|
106
|
+
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
107
|
+
|
|
108
|
+
const run = function () {
|
|
109
|
+
try {
|
|
110
|
+
if (typeof window.ezstandalone.showAds === 'function') {
|
|
111
|
+
window.ezstandalone.showAds.apply(window.ezstandalone, ids);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {}
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
window.ezstandalone.cmd.push(function () { run(); });
|
|
119
|
+
|
|
120
|
+
let tries = 0;
|
|
121
|
+
const tick = function () {
|
|
122
|
+
tries++;
|
|
123
|
+
if (run() || tries >= 10) return;
|
|
124
|
+
setTimeout(tick, 800);
|
|
125
|
+
};
|
|
126
|
+
setTimeout(tick, 800);
|
|
127
|
+
} catch (e) {}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (typeof window.ezstandalone.showAds === 'function') {
|
|
131
|
+
window.ezstandalone.showAds.apply(window.ezstandalone, ids);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {}
|
|
135
|
+
return false;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Ensure destroy->show runs AFTER ezstandalone is ready
|
|
139
|
+
window.ezstandalone.cmd.push(function () { run(); });
|
|
140
|
+
|
|
141
|
+
// retries in case ez loads late
|
|
142
|
+
let tries = 0;
|
|
143
|
+
const tick = function () {
|
|
144
|
+
tries++;
|
|
145
|
+
if (run() || tries >= 10) return;
|
|
146
|
+
setTimeout(tick, 800);
|
|
147
|
+
};
|
|
148
|
+
setTimeout(tick, 800);
|
|
149
|
+
} catch (e) {}
|
|
150
|
+
}
|
|
108
151
|
} catch (e) {}
|
|
109
152
|
return false;
|
|
110
153
|
};
|
|
@@ -249,29 +292,4 @@ function debounceRefresh() {
|
|
|
249
292
|
|
|
250
293
|
$(document).ready(debounceRefresh);
|
|
251
294
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded', debounceRefresh);
|
|
252
|
-
setTimeout(debounceRefresh, 1800);
|
|
253
|
-
const el = document.getElementById('ezoic-pub-ad-placeholder-' + id);
|
|
254
|
-
if (!el) return;
|
|
255
|
-
const wrap = el.closest('.ezoic-ad');
|
|
256
|
-
if (wrap) {
|
|
257
|
-
try { $(wrap).remove(); } catch (e) { wrap.remove(); }
|
|
258
|
-
} else {
|
|
259
|
-
el.remove();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function preDestroyPools() {
|
|
264
|
-
try {
|
|
265
|
-
const poolA = parsePool(settings && settings.placeholderIds);
|
|
266
|
-
const poolB = parsePool(settings && settings.messagePlaceholderIds);
|
|
267
|
-
const ids = Array.from(new Set([].concat(poolA, poolB)));
|
|
268
|
-
if (!ids.length) return;
|
|
269
|
-
ids.forEach(function (id) {
|
|
270
|
-
// If Ezoic has already defined the placeholder in this SPA session, destroy it before we re-use it
|
|
271
|
-
destroyPlaceholder(id);
|
|
272
|
-
removeExistingPlaceholder(id);
|
|
273
|
-
});
|
|
274
|
-
} catch (e) {}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
295
|
+
setTimeout(debounceRefresh, 1800);
|