nodebb-plugin-ezoic-infinite 1.4.34 → 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 +14 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.34",
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,20 +647,6 @@
642
647
  $(window).on('action:ajaxify.end.ezoicInfinite', () => {
643
648
  state.pageKey = getPageKey();
644
649
  ensureObserver();
645
-
646
- // CRITIQUE : Forcer Ezoic à recalculer le word count après navigation
647
- try {
648
- if (window.ezstandalone) {
649
- // Méthode 1 : fireEvent pour notifier la navigation AJAX
650
- if (typeof window.ezstandalone.fireEvent === 'function') {
651
- window.ezstandalone.fireEvent('ajax');
652
- }
653
- // Méthode 2 : refresh force un recalcul complet
654
- if (typeof window.ezstandalone.refresh === 'function') {
655
- window.ezstandalone.refresh();
656
- }
657
- }
658
- } catch (e) {}
659
650
  });
660
651
 
661
652
  $(window).on('action:category.loaded.ezoicInfinite', () => {
@@ -701,42 +692,32 @@
701
692
  }, { passive: true });
702
693
  }
703
694
 
704
-
705
695
  // Fonction qui attend que la page ait assez de contenu avant d'insérer les pubs
706
696
  function waitForContentThenRun() {
707
697
  const MIN_WORDS = 250;
708
698
  let attempts = 0;
709
699
  const maxAttempts = 20; // 20 × 200ms = 4s max
710
-
700
+
711
701
  (function check() {
712
702
  attempts++;
713
-
714
- // Forcer Ezoic à recalculer avant de vérifier (première tentative seulement)
715
- if (attempts === 1) {
716
- try {
717
- if (window.ezstandalone && typeof window.ezstandalone.refresh === 'function') {
718
- window.ezstandalone.refresh();
719
- }
720
- } catch (e) {}
721
- }
722
-
703
+
723
704
  // Compter les mots sur la page
724
705
  const text = document.body.innerText || '';
725
706
  const wordCount = text.split(/\s+/).filter(Boolean).length;
726
-
707
+
727
708
  if (wordCount >= MIN_WORDS) {
728
709
  // Assez de contenu → lancer l'insertion
729
710
  scheduleRun();
730
711
  return;
731
712
  }
732
-
713
+
733
714
  // Pas assez de contenu
734
715
  if (attempts >= maxAttempts) {
735
716
  // Timeout après 4s → tenter quand même
736
717
  scheduleRun();
737
718
  return;
738
719
  }
739
-
720
+
740
721
  // Réessayer dans 200ms
741
722
  setTimeout(check, 200);
742
723
  })();