nodebb-plugin-ezoic-infinite 0.9.6 → 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.
Files changed (2) hide show
  1. package/package.json +4 -1
  2. package/public/client.js +18 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.9.6",
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
@@ -95,7 +95,6 @@ function pickNextId(pool) {
95
95
  function callEzoic(ids) {
96
96
  if (!ids || !ids.length) return;
97
97
 
98
- // de-dupe rapid identical calls
99
98
  const key = ids.slice().sort((a, b) => a - b).join(',');
100
99
  const now = Date.now();
101
100
  if (window.__ezoicLastShowKey === key && now - (window.__ezoicLastShowAt || 0) < 1200) return;
@@ -108,12 +107,25 @@ function pickNextId(pool) {
108
107
 
109
108
  const run = function () {
110
109
  try {
111
- // SPA/infinite scroll: reset any previously-defined placeholders before using these IDs
112
- if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
113
- ids.forEach(function (id) {
114
- try { window.ezstandalone.destroyPlaceholders(id); } catch (e) {}
115
- });
110
+ if (typeof window.ezstandalone.showAds === 'function') {
111
+ window.ezstandalone.showAds.apply(window.ezstandalone, ids);
112
+ return true;
116
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
+ }
117
129
 
118
130
  if (typeof window.ezstandalone.showAds === 'function') {
119
131
  window.ezstandalone.showAds.apply(window.ezstandalone, ids);