nodebb-plugin-ezoic-infinite 1.4.39 → 1.4.41

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 +22 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.39",
3
+ "version": "1.4.41",
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
@@ -39,6 +39,8 @@
39
39
  timer: null,
40
40
 
41
41
  obs: null,
42
+ canShowAds: true,
43
+ activeTimeouts: new Set(),
42
44
  lastScrollRun: 0,
43
45
  __scrollBound: false,
44
46
  };
@@ -325,10 +327,6 @@
325
327
 
326
328
  function callShowAdsWhenReady(id) {
327
329
  if (!id) return;
328
-
329
- if (window.location.pathname !== '/') {
330
- console.log('[TIMING] callShowAdsWhenReady ID:', id);
331
- }
332
330
 
333
331
  const now = Date.now(), last = state.lastShowById.get(id) || 0;
334
332
  if (now - last < 3500) return;
@@ -352,25 +350,19 @@
352
350
  if (state.pageKey !== startPageKey) return;
353
351
  // Abort if another concurrent call is already handling this id
354
352
  if (state.pendingById.has(id)) return;
355
-
353
+
356
354
  attempts += 1;
357
355
  const el = document.getElementById(phId);
358
356
  if (el && el.isConnected) {
359
- if (window.location.pathname !== '/') {
360
- console.log('[TIMING] Placeholder', id, 'trouvé dans DOM, appel showAds');
361
- }
362
-
363
357
  // Double-check pageKey juste avant doCall (au cas où cleanup appelé entre-temps)
364
358
  if (state.pageKey !== startPageKey) {
365
- if (window.location.pathname !== '/') {
366
- console.log('[TIMING] ABORT ID', id, '- navigation détectée avant showAds');
367
- }
359
+ // Note: les timeouts seront nettoyés par cleanup()
368
360
  return;
369
361
  }
370
-
362
+
371
363
  // Si doCall() réussit, Ezoic est chargé et showAds a été appelé → sortir
372
364
  if (doCall()) {
373
- state.pendingById.delete(id); // nettoyage au cas où
365
+ state.pendingById.delete(id);
374
366
  return;
375
367
  }
376
368
 
@@ -392,7 +384,10 @@
392
384
  return;
393
385
  }
394
386
 
395
- if (attempts < 100) setTimeout(waitForPh, 50);
387
+ if (attempts < 100) {
388
+ const timeoutId = setTimeout(waitForPh, 50);
389
+ state.activeTimeouts.add(timeoutId);
390
+ }
396
391
  })();
397
392
  }
398
393
 
@@ -556,8 +551,13 @@
556
551
  // quand NodeBB vide le DOM lors de la navigation ajaxify
557
552
  // Les supprimer manuellement cause des problèmes avec l'état interne d'Ezoic
558
553
 
554
+ // CRITIQUE: Annuler TOUS les timeouts en cours pour éviter que les anciens
555
+ // showAds() continuent à s'exécuter après la navigation
556
+ state.activeTimeouts.forEach(id => clearTimeout(id));
557
+ state.activeTimeouts.clear();
558
+
559
559
  if (state.obs) { state.obs.disconnect(); state.obs = null; }
560
- state.canInsert = false;
560
+ state.canShowAds = false;
561
561
  state.scheduled = false;
562
562
  clearTimeout(state.timer);
563
563
  state.timer = null;
@@ -571,10 +571,10 @@
571
571
 
572
572
  async function runCore() {
573
573
  // Attendre que canInsert soit true (protection race condition navigation)
574
- if (!state.canInsert) {
574
+ if (!state.canShowAds) {
575
575
  return;
576
576
  }
577
-
577
+
578
578
  patchShowAds();
579
579
 
580
580
  const cfg = await fetchConfig();
@@ -613,7 +613,6 @@
613
613
 
614
614
  enforceNoAdjacentAds();
615
615
 
616
-
617
616
  // If nothing inserted and list isn't in DOM yet (first click), retry a bit
618
617
  let count = 0;
619
618
  if (kind === 'topic') count = getPostContainers().length;
@@ -664,14 +663,14 @@
664
663
  $(window).on('action:ajaxify.end.ezoicInfinite', () => {
665
664
  state.pageKey = getPageKey();
666
665
  ensureObserver();
667
-
666
+
668
667
  // CRITIQUE: Attendre 300ms avant de permettre l'insertion de nouveaux placeholders
669
668
  // pour laisser les anciens showAds() (en cours) se terminer ou échouer proprement
670
669
  // Sinon race condition: NodeBB vide le DOM pendant que Ezoic essaie d'accéder aux placeholders
671
- state.canInsert = false;
670
+ state.canShowAds = false;
672
671
  setTimeout(() => {
673
- state.canInsert = true;
674
- }, 300);
672
+ state.canShowAds = true;
673
+ }, 500);
675
674
  });
676
675
 
677
676
  $(window).on('action:category.loaded.ezoicInfinite', () => {