nodebb-plugin-ezoic-infinite 1.6.84 → 1.6.86

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.6.84",
3
+ "version": "1.6.86",
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
@@ -9,8 +9,8 @@
9
9
 
10
10
  let config = null;
11
11
  let isInternalChange = false;
12
- let ezEnabled = false;
13
- let definedIds = new Set();
12
+ let ezIsLoaded = false;
13
+ let lastEnableTime = 0;
14
14
 
15
15
  function getPool() {
16
16
  let p = document.getElementById(POOL_ID);
@@ -28,59 +28,53 @@
28
28
  const id = parseInt(pid, 10);
29
29
  if (isNaN(id)) return;
30
30
 
31
- try {
32
- // 1. On définit TOUJOURS l'ID avant toute autre action
31
+ window.ezstandalone.cmd.push(function() {
33
32
  window.ezstandalone.define(id);
34
- definedIds.add(id);
35
-
36
- // 2. Si c'est la toute première fois de la page
37
- if (!ezEnabled) {
33
+
34
+ // Si pas encore activé globalement
35
+ if (!window.ezstandalone.enabled) {
38
36
  window.ezstandalone.enable();
39
37
  window.ezstandalone.display();
40
- ezEnabled = true;
41
- console.log('[Ezoic-Infinite] Initialized with ID:', id);
38
+ lastEnableTime = Date.now();
42
39
  } else {
43
- // 3. Sinon, on utilise refresh avec un léger délai
44
- // pour s'assurer que le navigateur a fini de dessiner le DIV
45
- setTimeout(() => {
46
- const el = document.getElementById('ezoic-pub-ad-placeholder-' + id);
47
- if (el) {
40
+ // SECURITÉ : On attend au moins 2 secondes après un 'enable'
41
+ // avant d'autoriser un 'refresh' pour éviter l'erreur "same page"
42
+ const timeSinceEnable = Date.now() - lastEnableTime;
43
+ if (timeSinceEnable > 2000) {
44
+ window.ezstandalone.refresh();
45
+ } else {
46
+ // Si on est trop proche du enable, on retente dans 2.5s
47
+ setTimeout(function() {
48
48
  window.ezstandalone.refresh();
49
- console.log('[Ezoic-Infinite] Refresh called for:', id);
50
- }
51
- }, 300);
49
+ }, 2500);
50
+ }
52
51
  }
53
- } catch (e) {
54
- console.warn('[Ezoic-Infinite] JS Error:', e.message);
55
- }
52
+ });
56
53
  }
57
54
 
58
55
  function redistribute() {
59
56
  if (!config || config.excluded) return;
60
57
 
61
- // Ciblage Harmony NodeBB 4
58
+ // Harmony NodeBB 4 - Sélecteurs Accueil et Topics
62
59
  const topicItems = document.querySelectorAll('[component="category/topic"]');
63
60
  const postItems = document.querySelectorAll('[component="post"]');
64
61
 
65
- let items = [], kind = '', interval = 10, showFirst = false;
66
-
62
+ // Page d'accueil / Catégories
67
63
  if (topicItems.length > 0 && config.enableBetweenAds) {
68
- items = Array.from(topicItems);
69
- kind = 'between';
70
- interval = parseInt(config.intervalPosts, 10);
71
- showFirst = config.showFirstTopicAd;
72
- } else if (postItems.length > 0 && config.enableMessageAds) {
73
- items = Array.from(postItems);
74
- kind = 'message';
75
- interval = parseInt(config.messageIntervalPosts, 10);
76
- showFirst = config.showFirstMessageAd;
64
+ processItems(Array.from(topicItems), 'between', config.intervalPosts, config.showFirstTopicAd);
77
65
  }
66
+
67
+ // Topics (Messages)
68
+ if (postItems.length > 0 && config.enableMessageAds) {
69
+ processItems(Array.from(postItems), 'message', config.messageIntervalPosts, config.showFirstMessageAd);
70
+ }
71
+ }
78
72
 
79
- if (items.length === 0) return;
80
-
73
+ function processItems(items, kind, interval, showFirst) {
74
+ const int = parseInt(interval, 10) || 10;
81
75
  items.forEach((item, index) => {
82
76
  const pos = index + 1;
83
- const shouldHaveAd = (pos === 1 && showFirst) || (pos % interval === 0);
77
+ const shouldHaveAd = (pos === 1 && showFirst) || (pos % int === 0);
84
78
 
85
79
  const next = item.nextElementSibling;
86
80
  if (shouldHaveAd && !(next && next.classList.contains(WRAP_CLASS))) {
@@ -88,9 +82,7 @@
88
82
  const available = pool.querySelector(`.${WRAP_CLASS}[data-kind="${kind}"]`);
89
83
  if (available) {
90
84
  isInternalChange = true;
91
- // Insertion physique dans le DOM
92
85
  item.parentNode.insertBefore(available, item.nextSibling);
93
- // Activation Ezoic
94
86
  callEzoic(available.getAttribute('data-placeholder-id'));
95
87
  setTimeout(() => { isInternalChange = false; }, 100);
96
88
  }
@@ -129,6 +121,11 @@
129
121
  });
130
122
  }
131
123
 
124
+ // Correction Page d'accueil : Forcer redistribution quand on finit de charger une page
125
+ window.addEventListener('action:ajaxify.end', function() {
126
+ setTimeout(redistribute, 800);
127
+ });
128
+
132
129
  if (document.readyState === 'loading') {
133
130
  document.addEventListener('DOMContentLoaded', init);
134
131
  } else {
package/public/style.css CHANGED
@@ -1,18 +1,31 @@
1
+ /* Container principal */
1
2
  .nodebb-ezoic-wrap {
2
3
  display: block !important;
3
4
  width: 100% !important;
4
- margin: 30px 0 !important;
5
- min-height: 250px; /* Taille minimum pour forcer le chargement */
5
+ min-width: 100% !important;
6
+ margin: 20px 0 !important;
7
+ min-height: 250px;
6
8
  clear: both;
7
- overflow: visible !important;
9
+ float: none !important;
8
10
  }
9
11
 
10
- .nodebb-ezoic-wrap .ezoic-ad {
11
- min-width: 1px;
12
+ /* Forcer l'affichage dans la liste des catégories/topics (Accueil) */
13
+ [component="category/topic"] {
14
+ margin-bottom: 0 !important;
15
+ }
16
+
17
+ .nodebb-ezoic-wrap[data-kind="between"] {
18
+ background: transparent;
19
+ border-top: 1px solid rgba(0,0,0,0.05);
20
+ padding: 20px 0;
21
+ }
22
+
23
+ /* Cache si vraiment aucun contenu injecté après 5s */
24
+ .nodebb-ezoic-wrap:empty {
12
25
  min-height: 1px;
13
26
  }
14
27
 
15
- /* Évite que les pubs se collent */
28
+ /* Empêche les doublons */
16
29
  .nodebb-ezoic-wrap + .nodebb-ezoic-wrap {
17
30
  display: none !important;
18
31
  }