nodebb-plugin-ezoic-infinite 1.4.33 → 1.4.35

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 +45 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.33",
3
+ "version": "1.4.35",
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
@@ -10,12 +10,9 @@
10
10
  }, WRAP_CLASS = 'ezoic-ad';
11
11
  const PLACEHOLDER_PREFIX = 'ezoic-pub-ad-placeholder-', MAX_INSERTS_PER_RUN = 3;
12
12
 
13
-
14
-
15
13
  // Nécessaire pour savoir si on doit appeler destroyPlaceholders avant recyclage.
16
14
  const sessionDefinedIds = new Set();
17
15
 
18
-
19
16
  const insertingIds = new Set(), state = {
20
17
  pageKey: null,
21
18
  cfg: null,
@@ -589,9 +586,17 @@
589
586
  }
590
587
  }
591
588
 
592
-
593
589
  enforceNoAdjacentAds();
594
590
 
591
+ // Si on a inséré des placeholders, notifier Ezoic (optionnel)
592
+ if (inserted > 0) {
593
+ try {
594
+ if (window.ezstandalone && typeof window.ezstandalone.refresh === 'function') {
595
+ window.ezstandalone.refresh();
596
+ }
597
+ } catch (e) {}
598
+ }
599
+
595
600
  // If nothing inserted and list isn't in DOM yet (first click), retry a bit
596
601
  let count = 0;
597
602
  if (kind === 'topic') count = getPostContainers().length;
@@ -642,30 +647,28 @@
642
647
  $(window).on('action:ajaxify.end.ezoicInfinite', () => {
643
648
  state.pageKey = getPageKey();
644
649
  ensureObserver();
645
- // NE RIEN FAIRE d'autre ici
646
- // Les hooks category.loaded/topics.loaded/etc. vont déclencher scheduleRun
647
650
  });
648
651
 
649
652
  $(window).on('action:category.loaded.ezoicInfinite', () => {
650
653
  ensureObserver();
651
654
  // category.loaded = infinite scroll, Ezoic déjà chargé normalement
652
- setTimeout(scheduleRun, 800);
655
+ waitForContentThenRun();
653
656
  });
654
657
 
655
658
  $(window).on('action:topics.loaded.ezoicInfinite', () => {
656
659
  ensureObserver();
657
- setTimeout(scheduleRun, 800);
660
+ waitForContentThenRun();
658
661
  });
659
662
 
660
663
  $(window).on('action:topic.loaded.ezoicInfinite', () => {
661
664
  ensureObserver();
662
- setTimeout(scheduleRun, 600);
665
+ waitForContentThenRun();
663
666
  });
664
667
 
665
668
  $(window).on('action:posts.loaded.ezoicInfinite', () => {
666
669
  ensureObserver();
667
670
  // posts.loaded = infinite scroll
668
- setTimeout(scheduleRun, 800);
671
+ waitForContentThenRun();
669
672
  });
670
673
  }
671
674
 
@@ -689,6 +692,37 @@
689
692
  }, { passive: true });
690
693
  }
691
694
 
695
+ // Fonction qui attend que la page ait assez de contenu avant d'insérer les pubs
696
+ function waitForContentThenRun() {
697
+ const MIN_WORDS = 250;
698
+ let attempts = 0;
699
+ const maxAttempts = 20; // 20 × 200ms = 4s max
700
+
701
+ (function check() {
702
+ attempts++;
703
+
704
+ // Compter les mots sur la page
705
+ const text = document.body.innerText || '';
706
+ const wordCount = text.split(/\s+/).filter(Boolean).length;
707
+
708
+ if (wordCount >= MIN_WORDS) {
709
+ // Assez de contenu → lancer l'insertion
710
+ scheduleRun();
711
+ return;
712
+ }
713
+
714
+ // Pas assez de contenu
715
+ if (attempts >= maxAttempts) {
716
+ // Timeout après 4s → tenter quand même
717
+ scheduleRun();
718
+ return;
719
+ }
720
+
721
+ // Réessayer dans 200ms
722
+ setTimeout(check, 200);
723
+ })();
724
+ }
725
+
692
726
  // Fonction qui attend que Ezoic soit vraiment chargé
693
727
  function waitForEzoicThenRun() {
694
728
  let attempts = 0;
@@ -700,7 +734,7 @@
700
734
  if (window.ezstandalone && typeof window.ezstandalone.showAds === 'function') {
701
735
  // Ezoic est prêt → lancer l'insertion
702
736
  scheduleRun();
703
- setTimeout(scheduleRun, 800);
737
+ waitForContentThenRun();
704
738
  return;
705
739
  }
706
740
  // Ezoic pas encore prêt