nodebb-plugin-ezoic-infinite 1.8.39 → 1.8.40

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 +27 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.8.39",
3
+ "version": "1.8.40",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -109,7 +109,6 @@
109
109
  ezFlushTimer: null,
110
110
 
111
111
  // Lifecycle
112
- enableCalled: false, // ez.enable() called once per page
113
112
  runQueued: false,
114
113
  burstActive: false, burstDeadline: 0, burstCount: 0, lastBurstTs: 0,
115
114
  };
@@ -301,7 +300,14 @@
301
300
  }
302
301
 
303
302
  /**
304
- * Flush: define all queued IDs, then enable (first time) or displayMore.
303
+ * Flush: define new IDs with Ezoic, then call displayMore.
304
+ *
305
+ * IMPORTANT: We NEVER call ez.enable() — Ezoic's sa.min.js calls it
306
+ * automatically on page load. Calling it again causes
307
+ * "Enable should only ever be called once" error.
308
+ *
309
+ * We also check ez.getSelectedPlaceholders() or equivalent to skip
310
+ * IDs that Ezoic already knows about (defined during initial enable).
305
311
  */
306
312
  function ezFlush() {
307
313
  state.ezFlushTimer = null;
@@ -318,34 +324,39 @@
318
324
  state.ezBatch.clear();
319
325
  if (!ids.length) return;
320
326
 
321
- const isFirst = !state.enableCalled;
322
-
323
327
  ezCmd(() => {
324
328
  const ez = window.ezstandalone;
325
329
  if (!ez) return;
326
330
 
327
- // define() registers the placeholder IDs with Ezoic
331
+ // Check which IDs Ezoic already knows about to avoid "already defined"
332
+ const alreadyDefined = new Set();
328
333
  try {
329
- if (typeof ez.define === 'function') {
330
- ez.define(...ids);
334
+ // ez.allPlaceholders is an array of IDs Ezoic has already seen
335
+ if (Array.isArray(ez.allPlaceholders)) {
336
+ for (const p of ez.allPlaceholders) alreadyDefined.add(Number(p));
331
337
  }
332
338
  } catch (_) {}
333
339
 
334
- for (const id of ids) state.phState.set(id, 'defined');
340
+ const toDefine = ids.filter(id => !alreadyDefined.has(id));
341
+ // All IDs get displayMore, but only new ones get define
342
+ const toDisplay = ids;
335
343
 
336
- if (isFirst) {
337
- // First batch on this page: use enable() which triggers the initial ad request
338
- state.enableCalled = true;
344
+ // define() only for truly new placeholders
345
+ if (toDefine.length) {
339
346
  try {
340
- if (typeof ez.enable === 'function') {
341
- ez.enable();
347
+ if (typeof ez.define === 'function') {
348
+ ez.define(...toDefine);
342
349
  }
343
350
  } catch (_) {}
344
- } else {
345
- // Subsequent batches: use displayMore() for infinite scroll
351
+ }
352
+
353
+ for (const id of ids) state.phState.set(id, 'defined');
354
+
355
+ // displayMore() for all IDs — this is the infinite scroll API
356
+ if (toDisplay.length) {
346
357
  try {
347
358
  if (typeof ez.displayMore === 'function') {
348
- ez.displayMore(...ids);
359
+ ez.displayMore(...toDisplay);
349
360
  }
350
361
  } catch (_) {}
351
362
  }
@@ -738,7 +749,6 @@
738
749
  state.wrapsByClass.clear();
739
750
  state.kind = null;
740
751
  state.phState.clear();
741
- state.enableCalled = false;
742
752
  state.burstActive = false;
743
753
  state.runQueued = false;
744
754
  }