nodebb-plugin-ezoic-infinite 0.9.4 → 0.9.6

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 +1 -1
  2. package/public/client.js +41 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -92,19 +92,50 @@ function pickNextId(pool) {
92
92
  }
93
93
  return null;
94
94
  }
95
+ function callEzoic(ids) {
96
+ if (!ids || !ids.length) return;
95
97
 
96
- function callEzoic(ids) {
97
- if (!ids || !ids.length) return;
98
+ // de-dupe rapid identical calls
99
+ const key = ids.slice().sort((a, b) => a - b).join(',');
100
+ const now = Date.now();
101
+ if (window.__ezoicLastShowKey === key && now - (window.__ezoicLastShowAt || 0) < 1200) return;
102
+ window.__ezoicLastShowKey = key;
103
+ window.__ezoicLastShowAt = now;
98
104
 
99
- window.ezstandalone = window.ezstandalone || {};
100
- window.ezstandalone.cmd = window.ezstandalone.cmd || [];
101
-
102
- const run = function () {
103
105
  try {
104
- if (typeof window.ezstandalone.showAds === 'function') {
105
- window.ezstandalone.showAds.apply(window.ezstandalone, ids);
106
- return true;
107
- }
106
+ window.ezstandalone = window.ezstandalone || {};
107
+ window.ezstandalone.cmd = window.ezstandalone.cmd || [];
108
+
109
+ const run = function () {
110
+ 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
+ });
116
+ }
117
+
118
+ if (typeof window.ezstandalone.showAds === 'function') {
119
+ window.ezstandalone.showAds.apply(window.ezstandalone, ids);
120
+ return true;
121
+ }
122
+ } catch (e) {}
123
+ return false;
124
+ };
125
+
126
+ // Ensure destroy->show runs AFTER ezstandalone is ready
127
+ window.ezstandalone.cmd.push(function () { run(); });
128
+
129
+ // retries in case ez loads late
130
+ let tries = 0;
131
+ const tick = function () {
132
+ tries++;
133
+ if (run() || tries >= 10) return;
134
+ setTimeout(tick, 800);
135
+ };
136
+ setTimeout(tick, 800);
137
+ } catch (e) {}
138
+ }
108
139
  } catch (e) {}
109
140
  return false;
110
141
  };