nodebb-plugin-ezoic-infinite 1.6.90 → 1.6.92

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 +48 -43
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.6.90",
3
+ "version": "1.6.92",
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,13 +9,9 @@
9
9
 
10
10
  let config = null;
11
11
  let isInternalChange = false;
12
- let definedIds = new Set();
12
+ let activeIdsOnPage = new Set();
13
13
  let pendingIds = new Set();
14
- let refreshTimer = null;
15
-
16
- if (typeof window.ezoicFirstEnableDone === 'undefined') {
17
- window.ezoicFirstEnableDone = false;
18
- }
14
+ let triggerTimer = null;
19
15
 
20
16
  function getPool() {
21
17
  let p = document.getElementById(POOL_ID);
@@ -35,22 +31,21 @@
35
31
  const idsToProcess = Array.from(pendingIds);
36
32
  pendingIds.clear();
37
33
 
34
+ // 1. Définir les IDs (requis par Ezoic avant l'affichage)
38
35
  window.ezstandalone.define(idsToProcess);
39
36
 
40
- if (!window.ezstandalone.enabled && !window.ezoicFirstEnableDone) {
37
+ if (!window.ezstandalone.enabled) {
38
+ // PREMIER CHARGEMENT
41
39
  window.ezstandalone.enable();
42
- window.ezstandalone.display();
43
- window.ezoicFirstEnableDone = true;
40
+ window.ezstandalone.showAds(); // Appelle tout ce qui est présent
44
41
  } else {
45
- // Délai de sécurité pour éviter le conflit "same page enable"
46
- setTimeout(function() {
47
- try {
48
- window.ezstandalone.refresh();
49
- } catch (e) {
50
- console.debug('[Ezoic] Refresh deferred');
51
- }
52
- }, 1000);
42
+ // NOUVEAU CONTENU (INFINITE SCROLL)
43
+ // La doc dit : ezstandalone.showAds(104, 105);
44
+ window.ezstandalone.showAds.apply(null, idsToProcess);
53
45
  }
46
+
47
+ // On garde trace pour le nettoyage futur
48
+ idsToProcess.forEach(id => activeIdsOnPage.add(id));
54
49
  });
55
50
  }
56
51
 
@@ -58,34 +53,42 @@
58
53
  const pid = parseInt(id, 10);
59
54
  if (isNaN(pid)) return;
60
55
  pendingIds.add(pid);
61
- definedIds.add(pid);
56
+
57
+ // On attend un peu pour grouper si plusieurs pubs arrivent en même temps
58
+ clearTimeout(triggerTimer);
59
+ triggerTimer = setTimeout(triggerEzoic, 200);
60
+ }
62
61
 
63
- clearTimeout(refreshTimer);
64
- refreshTimer = setTimeout(triggerEzoic, 300);
62
+ // "Changing Pages" : Nettoyage complet lors de la navigation NodeBB
63
+ function onPageChangeStart() {
64
+ if (typeof window.ezstandalone !== 'undefined') {
65
+ window.ezstandalone.cmd.push(function() {
66
+ // On nettoie tout avant de charger la nouvelle page
67
+ if (typeof window.ezstandalone.destroyAll === 'function') {
68
+ window.ezstandalone.destroyAll();
69
+ }
70
+ activeIdsOnPage.clear();
71
+ });
72
+ }
65
73
  }
66
74
 
67
75
  function redistribute() {
68
76
  if (!config || config.excluded) return;
69
77
 
70
- // 1. PAGE D'ACCUEIL (Liste des catégories)
71
- const categoryItems = document.querySelectorAll('.category-item, [component="categories/category"]');
72
-
73
- // 2. PAGE CATEGORIE (Liste des topics)
74
- const topicItems = document.querySelectorAll('li[component="category/topic"]');
75
-
76
- // 3. PAGE TOPIC (Messages / Posts)
77
- const postItems = document.querySelectorAll('[component="post"]');
78
+ const selectors = {
79
+ 'home': '.category-item, [component="categories/category"]',
80
+ 'topic-list': 'li[component="category/topic"]',
81
+ 'message': '[component="post"]'
82
+ };
78
83
 
79
- if (categoryItems.length > 0 && config.enableCategoryAds) {
80
- process(Array.from(categoryItems), 'home', config.intervalCategories, config.showFirstCategoryAd);
84
+ if (config.enableCategoryAds) {
85
+ process(Array.from(document.querySelectorAll(selectors.home)), 'home', config.intervalCategories, config.showFirstCategoryAd);
81
86
  }
82
-
83
- if (topicItems.length > 0 && config.enableBetweenAds) {
84
- process(Array.from(topicItems), 'topic-list', config.intervalPosts, config.showFirstTopicAd);
87
+ if (config.enableBetweenAds) {
88
+ process(Array.from(document.querySelectorAll(selectors['topic-list'])), 'topic-list', config.intervalPosts, config.showFirstTopicAd);
85
89
  }
86
-
87
- if (postItems.length > 0 && config.enableMessageAds) {
88
- process(Array.from(postItems), 'message', config.messageIntervalPosts, config.showFirstMessageAd);
90
+ if (config.enableMessageAds) {
91
+ process(Array.from(document.querySelectorAll(selectors.message)), 'message', config.messageIntervalPosts, config.showFirstMessageAd);
89
92
  }
90
93
  }
91
94
 
@@ -94,16 +97,17 @@
94
97
  items.forEach((item, index) => {
95
98
  const pos = index + 1;
96
99
  const shouldHaveAd = (pos === 1 && showFirst) || (pos % int === 0);
97
-
98
100
  const next = item.nextElementSibling;
101
+
99
102
  if (shouldHaveAd && !(next && next.classList.contains(WRAP_CLASS))) {
100
103
  const pool = getPool();
101
104
  const available = pool.querySelector(`.${WRAP_CLASS}[data-kind="${kind}"]`);
105
+
102
106
  if (available) {
103
107
  isInternalChange = true;
104
108
  item.parentNode.insertBefore(available, item.nextSibling);
105
109
  callEzoic(available.getAttribute('data-placeholder-id'));
106
- setTimeout(() => { isInternalChange = false; }, 100);
110
+ setTimeout(() => { isInternalChange = false; }, 50);
107
111
  }
108
112
  }
109
113
  });
@@ -115,11 +119,10 @@
115
119
  .then(data => {
116
120
  config = data;
117
121
  const pool = getPool();
118
-
119
122
  const setup = (raw, kind) => {
120
123
  if (!raw) return;
121
124
  raw.split(/[\s,]+/).filter(Boolean).forEach(id => {
122
- if (!document.querySelector(`[data-placeholder-id="${id}"]`)) {
125
+ if (!pool.querySelector(`[data-placeholder-id="${id}"]`)) {
123
126
  const d = document.createElement('div');
124
127
  d.className = WRAP_CLASS;
125
128
  d.setAttribute('data-kind', kind);
@@ -129,8 +132,6 @@
129
132
  }
130
133
  });
131
134
  };
132
-
133
- // On initialise les 3 pools séparés
134
135
  setup(config.categoryPlaceholderIds, 'home');
135
136
  setup(config.placeholderIds, 'topic-list');
136
137
  setup(config.messagePlaceholderIds, 'message');
@@ -144,7 +145,11 @@
144
145
  });
145
146
  }
146
147
 
147
- window.addEventListener('action:ajaxify.end', () => setTimeout(redistribute, 800));
148
+ // Événements NodeBB
149
+ window.addEventListener('action:ajaxify.start', onPageChangeStart);
150
+ window.addEventListener('action:ajaxify.end', () => {
151
+ setTimeout(redistribute, 500);
152
+ });
148
153
 
149
154
  if (document.readyState === 'loading') {
150
155
  document.addEventListener('DOMContentLoaded', init);