nodebb-plugin-ezoic-infinite 1.6.91 → 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.
- package/package.json +1 -1
- package/public/client.js +58 -30
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
let config = null;
|
|
11
11
|
let isInternalChange = false;
|
|
12
|
+
let activeIdsOnPage = new Set();
|
|
12
13
|
let pendingIds = new Set();
|
|
13
|
-
let
|
|
14
|
+
let triggerTimer = null;
|
|
14
15
|
|
|
15
16
|
function getPool() {
|
|
16
17
|
let p = document.getElementById(POOL_ID);
|
|
@@ -30,16 +31,21 @@
|
|
|
30
31
|
const idsToProcess = Array.from(pendingIds);
|
|
31
32
|
pendingIds.clear();
|
|
32
33
|
|
|
33
|
-
//
|
|
34
|
+
// 1. Définir les IDs (requis par Ezoic avant l'affichage)
|
|
34
35
|
window.ezstandalone.define(idsToProcess);
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
37
|
+
if (!window.ezstandalone.enabled) {
|
|
38
|
+
// PREMIER CHARGEMENT
|
|
39
|
+
window.ezstandalone.enable();
|
|
40
|
+
window.ezstandalone.showAds(); // Appelle tout ce qui est présent
|
|
41
|
+
} else {
|
|
42
|
+
// NOUVEAU CONTENU (INFINITE SCROLL)
|
|
43
|
+
// La doc dit : ezstandalone.showAds(104, 105);
|
|
44
|
+
window.ezstandalone.showAds.apply(null, idsToProcess);
|
|
42
45
|
}
|
|
46
|
+
|
|
47
|
+
// On garde trace pour le nettoyage futur
|
|
48
|
+
idsToProcess.forEach(id => activeIdsOnPage.add(id));
|
|
43
49
|
});
|
|
44
50
|
}
|
|
45
51
|
|
|
@@ -47,29 +53,42 @@
|
|
|
47
53
|
const pid = parseInt(id, 10);
|
|
48
54
|
if (isNaN(pid)) return;
|
|
49
55
|
pendingIds.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
|
+
}
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
}
|
|
53
73
|
}
|
|
54
74
|
|
|
55
75
|
function redistribute() {
|
|
56
76
|
if (!config || config.excluded) return;
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
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
|
+
};
|
|
64
83
|
|
|
65
|
-
if (
|
|
66
|
-
process(Array.from(
|
|
84
|
+
if (config.enableCategoryAds) {
|
|
85
|
+
process(Array.from(document.querySelectorAll(selectors.home)), 'home', config.intervalCategories, config.showFirstCategoryAd);
|
|
67
86
|
}
|
|
68
|
-
if (
|
|
69
|
-
process(Array.from(
|
|
87
|
+
if (config.enableBetweenAds) {
|
|
88
|
+
process(Array.from(document.querySelectorAll(selectors['topic-list'])), 'topic-list', config.intervalPosts, config.showFirstTopicAd);
|
|
70
89
|
}
|
|
71
|
-
if (
|
|
72
|
-
process(Array.from(
|
|
90
|
+
if (config.enableMessageAds) {
|
|
91
|
+
process(Array.from(document.querySelectorAll(selectors.message)), 'message', config.messageIntervalPosts, config.showFirstMessageAd);
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
|
|
@@ -79,14 +98,16 @@
|
|
|
79
98
|
const pos = index + 1;
|
|
80
99
|
const shouldHaveAd = (pos === 1 && showFirst) || (pos % int === 0);
|
|
81
100
|
const next = item.nextElementSibling;
|
|
101
|
+
|
|
82
102
|
if (shouldHaveAd && !(next && next.classList.contains(WRAP_CLASS))) {
|
|
83
103
|
const pool = getPool();
|
|
84
104
|
const available = pool.querySelector(`.${WRAP_CLASS}[data-kind="${kind}"]`);
|
|
105
|
+
|
|
85
106
|
if (available) {
|
|
86
107
|
isInternalChange = true;
|
|
87
108
|
item.parentNode.insertBefore(available, item.nextSibling);
|
|
88
109
|
callEzoic(available.getAttribute('data-placeholder-id'));
|
|
89
|
-
setTimeout(() => { isInternalChange = false; },
|
|
110
|
+
setTimeout(() => { isInternalChange = false; }, 50);
|
|
90
111
|
}
|
|
91
112
|
}
|
|
92
113
|
});
|
|
@@ -101,17 +122,20 @@
|
|
|
101
122
|
const setup = (raw, kind) => {
|
|
102
123
|
if (!raw) return;
|
|
103
124
|
raw.split(/[\s,]+/).filter(Boolean).forEach(id => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
if (!pool.querySelector(`[data-placeholder-id="${id}"]`)) {
|
|
126
|
+
const d = document.createElement('div');
|
|
127
|
+
d.className = WRAP_CLASS;
|
|
128
|
+
d.setAttribute('data-kind', kind);
|
|
129
|
+
d.setAttribute('data-placeholder-id', id);
|
|
130
|
+
d.innerHTML = `<div id="ezoic-pub-ad-placeholder-${id}"></div>`;
|
|
131
|
+
pool.appendChild(d);
|
|
132
|
+
}
|
|
110
133
|
});
|
|
111
134
|
};
|
|
112
135
|
setup(config.categoryPlaceholderIds, 'home');
|
|
113
136
|
setup(config.placeholderIds, 'topic-list');
|
|
114
137
|
setup(config.messagePlaceholderIds, 'message');
|
|
138
|
+
|
|
115
139
|
redistribute();
|
|
116
140
|
|
|
117
141
|
const observer = new MutationObserver(() => {
|
|
@@ -121,7 +145,11 @@
|
|
|
121
145
|
});
|
|
122
146
|
}
|
|
123
147
|
|
|
124
|
-
|
|
148
|
+
// Événements NodeBB
|
|
149
|
+
window.addEventListener('action:ajaxify.start', onPageChangeStart);
|
|
150
|
+
window.addEventListener('action:ajaxify.end', () => {
|
|
151
|
+
setTimeout(redistribute, 500);
|
|
152
|
+
});
|
|
125
153
|
|
|
126
154
|
if (document.readyState === 'loading') {
|
|
127
155
|
document.addEventListener('DOMContentLoaded', init);
|