nodebb-plugin-ezoic-infinite 1.4.32 → 1.4.34

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 +60 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.32",
3
+ "version": "1.4.34",
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
@@ -328,9 +328,6 @@
328
328
 
329
329
  function callShowAdsWhenReady(id) {
330
330
  if (!id) return;
331
- if (window.location.pathname !== '/') {
332
- console.log('[AJAXIFY] callShowAdsWhenReady ID:', id);
333
- }
334
331
 
335
332
  const now = Date.now(), last = state.lastShowById.get(id) || 0;
336
333
  if (now - last < 3500) return;
@@ -357,9 +354,6 @@
357
354
  attempts += 1;
358
355
  const el = document.getElementById(phId);
359
356
  if (el && el.isConnected) {
360
- if (window.location.pathname !== '/') {
361
- console.log('[AJAXIFY] Placeholder', id, 'trouvé, appel showAds');
362
- }
363
357
  // Si doCall() réussit, Ezoic est chargé et showAds a été appelé → sortir
364
358
  if (doCall()) {
365
359
  state.pendingById.delete(id); // nettoyage au cas où
@@ -559,8 +553,6 @@
559
553
  }
560
554
 
561
555
  async function runCore() {
562
- const isAjaxify = window.location.pathname !== '/';
563
- if (isAjaxify) console.log('[AJAXIFY] runCore - pageKey:', state.pageKey);
564
556
  patchShowAds();
565
557
 
566
558
  const cfg = await fetchConfig();
@@ -597,9 +589,6 @@
597
589
  }
598
590
  }
599
591
 
600
- if (window.location.pathname !== '/') {
601
- console.log('[AJAXIFY] Inserted:', inserted, 'wrappers. Items count:', count);
602
- }
603
592
 
604
593
  enforceNoAdjacentAds();
605
594
 
@@ -651,33 +640,44 @@
651
640
  $(window).on('action:ajaxify.start.ezoicInfinite', () => cleanup());
652
641
 
653
642
  $(window).on('action:ajaxify.end.ezoicInfinite', () => {
654
- console.log('[AJAXIFY] ajaxify.end - juste update pageKey');
655
643
  state.pageKey = getPageKey();
656
644
  ensureObserver();
657
- // NE RIEN FAIRE d'autre ici
658
- // Les hooks category.loaded/topics.loaded/etc. vont déclencher scheduleRun
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
659
  });
660
660
 
661
661
  $(window).on('action:category.loaded.ezoicInfinite', () => {
662
662
  ensureObserver();
663
663
  // category.loaded = infinite scroll, Ezoic déjà chargé normalement
664
- setTimeout(scheduleRun, 300);
664
+ waitForContentThenRun();
665
665
  });
666
666
 
667
667
  $(window).on('action:topics.loaded.ezoicInfinite', () => {
668
668
  ensureObserver();
669
- setTimeout(scheduleRun, 300);
669
+ waitForContentThenRun();
670
670
  });
671
671
 
672
672
  $(window).on('action:topic.loaded.ezoicInfinite', () => {
673
673
  ensureObserver();
674
- setTimeout(scheduleRun, 300);
674
+ waitForContentThenRun();
675
675
  });
676
676
 
677
677
  $(window).on('action:posts.loaded.ezoicInfinite', () => {
678
678
  ensureObserver();
679
679
  // posts.loaded = infinite scroll
680
- setTimeout(scheduleRun, 400);
680
+ waitForContentThenRun();
681
681
  });
682
682
  }
683
683
 
@@ -701,6 +701,47 @@
701
701
  }, { passive: true });
702
702
  }
703
703
 
704
+
705
+ // Fonction qui attend que la page ait assez de contenu avant d'insérer les pubs
706
+ function waitForContentThenRun() {
707
+ const MIN_WORDS = 250;
708
+ let attempts = 0;
709
+ const maxAttempts = 20; // 20 × 200ms = 4s max
710
+
711
+ (function check() {
712
+ 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
+
723
+ // Compter les mots sur la page
724
+ const text = document.body.innerText || '';
725
+ const wordCount = text.split(/\s+/).filter(Boolean).length;
726
+
727
+ if (wordCount >= MIN_WORDS) {
728
+ // Assez de contenu → lancer l'insertion
729
+ scheduleRun();
730
+ return;
731
+ }
732
+
733
+ // Pas assez de contenu
734
+ if (attempts >= maxAttempts) {
735
+ // Timeout après 4s → tenter quand même
736
+ scheduleRun();
737
+ return;
738
+ }
739
+
740
+ // Réessayer dans 200ms
741
+ setTimeout(check, 200);
742
+ })();
743
+ }
744
+
704
745
  // Fonction qui attend que Ezoic soit vraiment chargé
705
746
  function waitForEzoicThenRun() {
706
747
  let attempts = 0;
@@ -712,7 +753,7 @@
712
753
  if (window.ezstandalone && typeof window.ezstandalone.showAds === 'function') {
713
754
  // Ezoic est prêt → lancer l'insertion
714
755
  scheduleRun();
715
- setTimeout(scheduleRun, 300);
756
+ waitForContentThenRun();
716
757
  return;
717
758
  }
718
759
  // Ezoic pas encore prêt