nodebb-plugin-ezoic-infinite 1.6.88 → 1.6.89

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 +40 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.6.88",
3
+ "version": "1.6.89",
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,7 +10,8 @@
10
10
  let config = null;
11
11
  let isInternalChange = false;
12
12
  let definedIds = new Set();
13
- let ezoicEnabledOnThisPage = false;
13
+ let pendingIds = new Set();
14
+ let refreshTimer = null;
14
15
 
15
16
  function getPool() {
16
17
  let p = document.getElementById(POOL_ID);
@@ -23,40 +24,51 @@
23
24
  return p;
24
25
  }
25
26
 
26
- function callEzoic(id) {
27
- if (typeof window.ezstandalone === 'undefined') return;
28
- const pid = parseInt(id, 10);
29
- if (isNaN(pid)) return;
27
+ // Cette fonction centralise les appels pour éviter de spammer Refresh()
28
+ function triggerEzoic() {
29
+ if (typeof window.ezstandalone === 'undefined' || pendingIds.size === 0) return;
30
30
 
31
31
  window.ezstandalone.cmd.push(function() {
32
- // On définit l'ID s'il est nouveau
33
- if (!definedIds.has(pid)) {
34
- window.ezstandalone.define(pid);
35
- definedIds.add(pid);
36
- }
32
+ const idsToProcess = Array.from(pendingIds);
33
+ pendingIds.clear();
37
34
 
38
- // Protection contre l'erreur "cannot call refresh on same page enable"
39
- if (!window.ezstandalone.enabled && !ezoicEnabledOnThisPage) {
35
+ // 1. Définir les nouveaux IDs
36
+ window.ezstandalone.define(idsToProcess);
37
+
38
+ // 2. Si c'est le tout premier appel de la page
39
+ if (!window.ezstandalone.enabled) {
40
40
  window.ezstandalone.enable();
41
41
  window.ezstandalone.display();
42
- ezoicEnabledOnThisPage = true;
43
42
  } else {
44
- // Délai de sécurité de 500ms pour laisser Ezoic finir son cycle initial
45
- setTimeout(function() {
46
- try {
43
+ // 3. Sinon, on utilise Refresh MAIS seulement si on n'est pas
44
+ // dans la même micro-seconde que l'initialisation
45
+ try {
47
46
  window.ezstandalone.refresh();
48
- } catch (e) {
49
- console.debug('[Ezoic] Refresh deferred');
50
- }
51
- }, 500);
47
+ } catch (e) {
48
+ console.warn('[Ezoic] Refresh skipped to prevent conflict');
49
+ }
52
50
  }
53
51
  });
54
52
  }
55
53
 
54
+ function callEzoic(id) {
55
+ const pid = parseInt(id, 10);
56
+ if (isNaN(pid)) return;
57
+
58
+ // On ajoute l'ID à la liste des IDs à traiter
59
+ pendingIds.add(pid);
60
+ definedIds.add(pid);
61
+
62
+ // On attend 200ms que les autres pubs du même scroll arrivent
63
+ // avant de lancer l'appel Ezoic unique. C'est le "Debounce".
64
+ clearTimeout(refreshTimer);
65
+ refreshTimer = setTimeout(triggerEzoic, 200);
66
+ }
67
+
56
68
  function redistribute() {
57
69
  if (!config || config.excluded) return;
58
70
 
59
- // Sélecteurs V17 (Harmony)
71
+ // Sélecteurs Harmony
60
72
  const topicItems = document.querySelectorAll('li[component="category/topic"]');
61
73
  const postItems = document.querySelectorAll('[component="post"]');
62
74
 
@@ -120,10 +132,14 @@
120
132
  });
121
133
  }
122
134
 
123
- // Reset lors de la navigation NodeBB (SPA)
135
+ // Crucial pour les SPA : Nettoyer l'état d'Ezoic lors d'un changement de page
124
136
  window.addEventListener('action:ajaxify.start', function() {
125
- ezoicEnabledOnThisPage = false;
126
- definedIds.clear();
137
+ if (typeof window.ezstandalone !== 'undefined' && window.ezstandalone.enabled) {
138
+ // Optionnel : window.ezstandalone.destroy();
139
+ // Mais souvent il vaut mieux juste laisser Ezoic gérer
140
+ }
141
+ definedIds.clear();
142
+ pendingIds.clear();
127
143
  });
128
144
 
129
145
  window.addEventListener('action:ajaxify.end', function() {