nodebb-plugin-ezoic-infinite 0.8.5 → 0.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
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
@@ -114,9 +114,18 @@ function pickNextId(pool, usedSet) {
114
114
  if (!usedSet.has(id)) return id;
115
115
  }
116
116
  return null;
117
+ } finally {
118
+ window.__ezoicRecycling = false;
119
+ }
117
120
  }
118
121
 
119
122
  function destroyEzoicId(id) {
123
+ window.__ezoicLastDestroy = window.__ezoicLastDestroy || {};
124
+ const now = Date.now();
125
+ if (window.__ezoicLastDestroy[id] && now - window.__ezoicLastDestroy[id] < 2000) {
126
+ return;
127
+ }
128
+ window.__ezoicLastDestroy[id] = now;
120
129
  try {
121
130
  window.ezstandalone = window.ezstandalone || {};
122
131
  window.ezstandalone.cmd = window.ezstandalone.cmd || [];
@@ -133,6 +142,9 @@ function destroyEzoicId(id) {
133
142
  }
134
143
 
135
144
  function recycleOldestTopicId($posts) {
145
+ if (window.__ezoicRecycling) return null;
146
+ window.__ezoicRecycling = true;
147
+ try {
136
148
  if (!fifo.length) return null;
137
149
  fifo.sort((a, b) => a.afterPostNo - b.afterPostNo);
138
150
 
@@ -157,9 +169,15 @@ function recycleOldestTopicId($posts) {
157
169
  return old.id;
158
170
  }
159
171
  return null;
172
+ } finally {
173
+ window.__ezoicRecycling = false;
174
+ }
160
175
  }
161
176
 
162
177
  function recycleOldestCategoryId($items) {
178
+ if (window.__ezoicRecycling) return null;
179
+ window.__ezoicRecycling = true;
180
+ try {
163
181
  if (!fifoCat.length) return null;
164
182
  fifoCat.sort((a, b) => a.afterPos - b.afterPos);
165
183
 
@@ -192,6 +210,10 @@ function setupAdAutoHeight() {
192
210
  try {
193
211
  const ro = new ResizeObserver(function () {
194
212
  document.querySelectorAll('.ezoic-ad').forEach(function (wrap) {
213
+ // Collapse until content is injected
214
+ if (!wrap.classList.contains('ezoic-filled')) {
215
+ wrap.style.display = 'none';
216
+ }
195
217
  wrap.style.minHeight = '0px';
196
218
  wrap.style.height = 'auto';
197
219
  });
@@ -199,6 +221,10 @@ function setupAdAutoHeight() {
199
221
 
200
222
  function attach() {
201
223
  document.querySelectorAll('.ezoic-ad').forEach(function (wrap) {
224
+ // Collapse until content is injected
225
+ if (!wrap.classList.contains('ezoic-filled')) {
226
+ wrap.style.display = 'none';
227
+ }
202
228
  if (wrap.__ezoicRO) return;
203
229
  wrap.__ezoicRO = true;
204
230
  ro.observe(wrap);
@@ -242,8 +268,17 @@ function callEzoic(ids) {
242
268
  const collect = function () {
243
269
  const list = [];
244
270
  document.querySelectorAll('.ezoic-ad').forEach(function (wrap) {
271
+ // Collapse until content is injected
272
+ if (!wrap.classList.contains('ezoic-filled')) {
273
+ wrap.style.display = 'none';
274
+ }
245
275
  if (wrap.getAttribute('data-ezoic-rendered') === '1') return;
246
276
  const ph = wrap.querySelector('[id^="ezoic-pub-ad-placeholder-"]');
277
+ if (ph && ph.children && ph.children.length) {
278
+ // Content injected
279
+ wrap.classList.add('ezoic-filled');
280
+ wrap.style.display = '';
281
+ }
247
282
  if (!ph) return;
248
283
  const idStr = ph.id.replace('ezoic-pub-ad-placeholder-', '');
249
284
  const id = parseInt(idStr, 10);
@@ -402,6 +437,9 @@ function injectCategoryBetweenAds($items, pool, interval) {
402
437
  }
403
438
 
404
439
  async function refreshAds() {
440
+ const now = Date.now();
441
+ if (window.__ezoicRefreshThrottle && now - window.__ezoicRefreshThrottle < 250) return;
442
+ window.__ezoicRefreshThrottle = now;
405
443
  const key = getPageKey();
406
444
  if (pageKey !== key) {
407
445
  pageKey = key;
package/public/style.css CHANGED
@@ -1,3 +1,4 @@
1
- .ezoic-ad{min-height:0!important;height:auto!important;padding:0!important;}
2
- .ezoic-ad-post,.ezoic-ad-topic{margin:0.5rem 0;}
1
+ .ezoic-ad{min-height:0 !important;height:auto !important;padding:0 !important;margin:0.5rem 0;}
2
+ .ezoic-ad:not(.ezoic-filled){display:none !important;}
3
3
  .ezoic-ad-message-inner{padding:0;margin:0;}
4
+ .ezoic-ad-message-inner > div{margin:0;padding:0;}