nodebb-plugin-ezoic-infinite 1.0.1 → 1.0.3

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/library.js CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  'use strict';
2
3
 
3
4
  const meta = require.main.require('./src/meta');
@@ -5,7 +6,7 @@ const groups = require.main.require('./src/groups');
5
6
 
6
7
  const Plugin = {};
7
8
 
8
- Plugin.init = async function ({ router, middleware }) {
9
+ Plugin.init = async ({ router, middleware }) => {
9
10
  router.get('/admin/plugins/ezoic-infinite', middleware.admin.buildHeader, renderAdmin);
10
11
  router.get('/api/admin/plugins/ezoic-infinite', renderAdmin);
11
12
  };
@@ -14,33 +15,24 @@ async function renderAdmin(req, res) {
14
15
  const settings = await meta.settings.get('ezoic-infinite');
15
16
 
16
17
  let groupNames = [];
17
- const candidates = ['groups:createtime', 'groups:visible:createtime'];
18
- for (const set of candidates) {
19
- try {
20
- groupNames = await groups.getGroupsFromSet(set, 0, -1);
21
- if (Array.isArray(groupNames) && groupNames.length) break;
22
- } catch (e) {}
23
- }
18
+ try {
19
+ groupNames = await groups.getGroupsFromSet('groups:createtime', 0, -1);
20
+ } catch (e) {}
24
21
 
25
22
  let groupList = [];
26
23
  try {
27
24
  groupList = await groups.getGroupsData(groupNames);
28
25
  } catch (e) {
29
- groupList = (groupNames || []).map((name) => ({ name }));
26
+ groupList = groupNames.map(name => ({ name }));
30
27
  }
31
28
 
32
- groupList = (groupList || [])
33
- .filter(g => g && g.name)
34
- .sort((a, b) => (a.name || '').localeCompare(b.name || '', 'fr', { sensitivity: 'base' }));
35
-
36
29
  res.render('admin/plugins/ezoic-infinite', {
37
- title: 'Ezoic - Publicités Infinite Scroll',
38
30
  settings,
39
31
  groups: groupList,
40
32
  });
41
33
  }
42
34
 
43
- Plugin.addAdminNavigation = async function (header) {
35
+ Plugin.addAdminNavigation = async (header) => {
44
36
  header.plugins = header.plugins || [];
45
37
  header.plugins.push({
46
38
  route: '/plugins/ezoic-infinite',
@@ -50,10 +42,8 @@ Plugin.addAdminNavigation = async function (header) {
50
42
  return header;
51
43
  };
52
44
 
53
- // Expose settings to client without any admin API calls
54
- Plugin.addConfig = async function (config) {
55
- const settings = await meta.settings.get('ezoic-infinite');
56
- config.ezoicInfinite = settings || {};
45
+ Plugin.addConfig = async (config) => {
46
+ config.ezoicInfinite = await meta.settings.get('ezoic-infinite');
57
47
  return config;
58
48
  };
59
49
 
package/package.json CHANGED
@@ -1,16 +1,9 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.0.1",
4
- "description": "Ezoic ads injection for NodeBB 4.x (rebased to 0.8.3 style).",
3
+ "version": "1.0.3",
4
+ "description": "Ezoic Infinite (rollback to 0.8.2 behaviour)",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
7
- "keywords": [
8
- "nodebb",
9
- "nodebb-plugin",
10
- "ezoic",
11
- "ads",
12
- "infinite-scroll"
13
- ],
14
7
  "nbbpm": {
15
8
  "compatibility": "^4.0.0"
16
9
  }
package/plugin.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "id": "nodebb-plugin-ezoic-infinite",
3
3
  "name": "Ezoic Infinite",
4
- "description": "Ezoic ads injection with infinite scroll (topics list + topic posts)",
5
4
  "library": "./library.js",
6
5
  "hooks": [
7
6
  {
@@ -26,8 +25,5 @@
26
25
  "scripts": [
27
26
  "public/client.js"
28
27
  ],
29
- "css": [
30
- "public/style.css"
31
- ],
32
28
  "templates": "public/templates"
33
29
  }
package/public/admin.js CHANGED
@@ -1,52 +1,35 @@
1
- /* global $, app, socket */
2
- 'use strict';
3
1
 
4
- $(document).ready(function () {
5
- const namespace = 'ezoic-infinite';
6
-
7
- function load() {
8
- socket.emit('admin.settings.get', { hash: namespace }, function (err, data) {
9
- if (err) return;
10
- data = data || {};
11
-
12
- const form = $('.ezoic-infinite-settings');
13
-
14
- form.find('[name="enableBetweenAds"]').prop('checked', data.enableBetweenAds === true || data.enableBetweenAds === 'on');
15
- form.find('[name="intervalTopics"]').val(parseInt(data.intervalTopics, 10) || 6);
16
- form.find('[name="placeholderIds"]').val(data.placeholderIds || '');
17
-
18
- form.find('[name="enableMessageAds"]').prop('checked', data.enableMessageAds === true || data.enableMessageAds === 'on');
19
- form.find('[name="messageIntervalPosts"]').val(parseInt(data.messageIntervalPosts, 10) || 3);
20
- form.find('[name="messagePlaceholderIds"]').val(data.messagePlaceholderIds || '');
21
-
22
- // Do NOT clear groups; server rendered
23
- const selected = (data.excludedGroups || '').split(',').map(s => s.trim()).filter(Boolean);
24
- form.find('[name="excludedGroups"] option').each(function () {
25
- $(this).prop('selected', selected.includes($(this).val()));
26
- });
2
+ /* global $, socket, app */
3
+ $(function () {
4
+ const ns = 'ezoic-infinite';
5
+ const form = $('.ezoic-infinite-settings');
6
+
7
+ socket.emit('admin.settings.get', { hash: ns }, (err, data) => {
8
+ if (!data) return;
9
+ Object.keys(data).forEach(k => {
10
+ const el = form.find('[name="' + k + '"]');
11
+ if (!el.length) return;
12
+ if (el.attr('type') === 'checkbox') el.prop('checked', data[k]);
13
+ else el.val(data[k]);
27
14
  });
28
- }
29
15
 
30
- function save() {
31
- const form = $('.ezoic-infinite-settings');
32
- const payload = {
33
- enableBetweenAds: form.find('[name="enableBetweenAds"]').is(':checked'),
34
- intervalTopics: parseInt(form.find('[name="intervalTopics"]').val(), 10) || 6,
35
- placeholderIds: form.find('[name="placeholderIds"]').val() || '',
36
-
37
- enableMessageAds: form.find('[name="enableMessageAds"]').is(':checked'),
38
- messageIntervalPosts: parseInt(form.find('[name="messageIntervalPosts"]').val(), 10) || 3,
39
- messagePlaceholderIds: form.find('[name="messagePlaceholderIds"]').val() || '',
40
-
41
- excludedGroups: (form.find('[name="excludedGroups"]').val() || []).join(','),
42
- };
43
-
44
- socket.emit('admin.settings.set', { hash: namespace, values: payload }, function (err) {
45
- if (err) { app.alertError(err.message || err); return; }
46
- app.alertSuccess('Paramètres enregistrés');
16
+ if (data.excludedGroups) {
17
+ data.excludedGroups.split(',').forEach(g =>
18
+ form.find('option[value="' + g + '"]').prop('selected', true)
19
+ );
20
+ }
21
+ });
22
+
23
+ $('.ezoic-save').on('click', () => {
24
+ const values = {};
25
+ form.serializeArray().forEach(o => values[o.name] = o.value);
26
+ values.enableBetweenAds = form.find('[name=enableBetweenAds]').is(':checked');
27
+ values.enableMessageAds = form.find('[name=enableMessageAds]').is(':checked');
28
+ values.excludedGroups = (form.find('[name=excludedGroups]').val() || []).join(',');
29
+
30
+ socket.emit('admin.settings.set', { hash: ns, values }, err => {
31
+ if (err) app.alertError(err.message);
32
+ else app.alertSuccess('Enregistré');
47
33
  });
48
- }
49
-
50
- $('.ezoic-infinite-save').on('click', save);
51
- load();
34
+ });
52
35
  });
package/public/client.js CHANGED
@@ -1,249 +1,6 @@
1
- /* global $, ajaxify, app, config */
2
- 'use strict';
3
1
 
2
+ /* global config */
4
3
  (function () {
5
- if (window.ezoicInfiniteLoaded) return;
6
- window.ezoicInfiniteLoaded = true;
7
-
8
- let settings = (window.config && window.config.ezoicInfinite) ? window.config.ezoicInfinite : {};
9
- let pageKey = null;
10
-
11
- let usedTopic = new Set();
12
- let usedCat = new Set();
13
- let fifoTopic = [];
14
- let fifoCat = [];
15
-
16
- let refreshInFlight = false;
17
- let refreshQueued = false;
18
-
19
- function reloadSettingsFromConfig() {
20
- settings = (window.config && window.config.ezoicInfinite) ? window.config.ezoicInfinite : (settings || {});
21
- }
22
-
23
- function parsePool(text) {
24
- return String(text || '')
25
- .split(/\r?\n/)
26
- .map(s => s.trim())
27
- .filter(Boolean)
28
- .map(s => parseInt(s, 10))
29
- .filter(n => Number.isFinite(n) && n > 0);
30
- }
31
-
32
- function userExcluded() {
33
- try {
34
- const raw = settings && settings.excludedGroups ? String(settings.excludedGroups) : '';
35
- if (!raw) return false;
36
- const excluded = raw.split(',').map(s => s.trim()).filter(Boolean);
37
- if (!excluded.length) return false;
38
- const myGroups = (app.user && app.user.groups) ? app.user.groups : [];
39
- return excluded.some(g => myGroups.includes(g));
40
- } catch (e) { return false; }
41
- }
42
-
43
- function getPageKey() {
44
- try {
45
- if (ajaxify && ajaxify.data) {
46
- if (ajaxify.data.tid) return 'topic:' + ajaxify.data.tid;
47
- if (ajaxify.data.cid) return 'cid:' + ajaxify.data.cid + ':' + window.location.pathname;
48
- }
49
- } catch (e) {}
50
- return window.location.pathname;
51
- }
52
-
53
- function isTopicPage() {
54
- try { if (ajaxify && ajaxify.data && ajaxify.data.tid) return true; } catch (e) {}
55
- return /^\/topic\//.test(window.location.pathname);
56
- }
57
-
58
- function isCategoryTopicList() {
59
- return $('li[component="category/topic"]').length > 0 && !isTopicPage();
60
- }
61
-
62
- function cleanupForNewPage() {
63
- $('.ezoic-ad').remove();
64
- usedTopic = new Set(); usedCat = new Set();
65
- fifoTopic = []; fifoCat = [];
66
- }
67
-
68
- function pickNextId(pool, usedSet) {
69
- for (const id of pool) if (!usedSet.has(id)) return id;
70
- return null;
71
- }
72
-
73
- function destroyPlaceholder(id) {
74
- try {
75
- window.ezstandalone = window.ezstandalone || {};
76
- window.ezstandalone.cmd = window.ezstandalone.cmd || [];
77
- if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
78
- window.ezstandalone.destroyPlaceholders(id);
79
- return;
80
- }
81
- window.ezstandalone.cmd.push(function () {
82
- try { window.ezstandalone.destroyPlaceholders(id); } catch (e) {}
83
- });
84
- } catch (e) {}
85
- }
86
-
87
- function ensureUniquePlaceholder(id) {
88
- const existing = document.getElementById('ezoic-pub-ad-placeholder-' + id);
89
- if (!existing) return;
90
- const wrap = existing.closest('.ezoic-ad');
91
- if (wrap) $(wrap).remove(); else existing.remove();
92
- destroyPlaceholder(id);
93
- }
94
-
95
- function callEzoicSingle(id) {
96
- if (!id) return;
97
- const now = Date.now();
98
- window.__ezoicLastSingle = window.__ezoicLastSingle || {};
99
- if (now - (window.__ezoicLastSingle[id] || 0) < 1200) return;
100
- window.__ezoicLastSingle[id] = now;
101
-
102
- window.ezstandalone = window.ezstandalone || {};
103
- window.ezstandalone.cmd = window.ezstandalone.cmd || [];
104
- const run = function () {
105
- if (typeof window.ezstandalone.showAds === 'function') {
106
- window.ezstandalone.showAds(id);
107
- return true;
108
- }
109
- return false;
110
- };
111
- window.ezstandalone.cmd.push(function () { try { run(); } catch (e) {} });
112
-
113
- let tries = 0;
114
- (function tick() {
115
- tries++;
116
- try { if (run() || tries >= 8) return; } catch (e) {}
117
- setTimeout(tick, 800);
118
- })();
119
- }
120
-
121
- function setupAutoHeightOnce() {
122
- if (window.__ezoicAutoHeight) return;
123
- window.__ezoicAutoHeight = true;
124
- const scan = function () {
125
- document.querySelectorAll('.ezoic-ad').forEach((wrap) => {
126
- const ph = wrap.querySelector('[id^="ezoic-pub-ad-placeholder-"]');
127
- if (ph && ph.children && ph.children.length) wrap.classList.add('ezoic-filled');
128
- });
129
- };
130
- scan();
131
- setInterval(scan, 1000);
132
- try { new MutationObserver(scan).observe(document.body, { childList: true, subtree: true }); } catch (e) {}
133
- }
134
-
135
- function insertAfter($target, id, cls, afterVal) {
136
- ensureUniquePlaceholder(id);
137
- const wrap = $(
138
- '<div class="ezoic-ad ' + cls + '" data-ezoic-id="' + id + '" data-ezoic-after="' + afterVal + '">' +
139
- '<div class="ezoic-ad-inner"><div id="ezoic-pub-ad-placeholder-' + id + '"></div></div>' +
140
- '</div>'
141
- );
142
- $target.after(wrap);
143
- }
144
-
145
- function recycleTopic($posts) {
146
- fifoTopic.sort((a,b)=>a.afterNo-b.afterNo);
147
- while (fifoTopic.length) {
148
- const old=fifoTopic.shift();
149
- const $el=$('.ezoic-ad-topic[data-ezoic-id="'+old.id+'"][data-ezoic-after="'+old.afterNo+'"]');
150
- if (!$el.length) continue;
151
- $el.remove(); usedTopic.delete(old.id); destroyPlaceholder(old.id);
152
- return old.id;
153
- }
154
- return null;
155
- }
156
-
157
- function recycleCat($items) {
158
- fifoCat.sort((a,b)=>a.afterPos-b.afterPos);
159
- while (fifoCat.length) {
160
- const old=fifoCat.shift();
161
- const $el=$('.ezoic-ad-between[data-ezoic-id="'+old.id+'"][data-ezoic-after="'+old.afterPos+'"]');
162
- if (!$el.length) continue;
163
- $el.remove(); usedCat.delete(old.id); destroyPlaceholder(old.id);
164
- return old.id;
165
- }
166
- return null;
167
- }
168
-
169
- function injectInTopic() {
170
- if (!(settings && (settings.enableMessageAds === true || settings.enableMessageAds === 'on'))) return;
171
- const interval = parseInt(settings.messageIntervalPosts,10) || 3;
172
- const pool = parsePool(settings.messagePlaceholderIds);
173
- if (!pool.length) return;
174
-
175
- const $posts = $('[component="post"][data-pid]');
176
- if (!$posts.length) return;
177
-
178
- $posts.each(function(idx){
179
- const no=idx+1;
180
- if (no % interval !== 0) return;
181
- if (idx === $posts.length-1) return;
182
-
183
- const $post=$(this);
184
- if ($post.next('.ezoic-ad-topic').length) return;
185
-
186
- let id=pickNextId(pool, usedTopic);
187
- if (!id) { id=recycleTopic($posts); if (!id) return; }
188
-
189
- usedTopic.add(id); fifoTopic.push({id, afterNo:no});
190
- insertAfter($post, id, 'ezoic-ad-topic', no);
191
- callEzoicSingle(id);
192
- });
193
- }
194
-
195
- function injectInCategory() {
196
- if (!(settings && (settings.enableBetweenAds === true || settings.enableBetweenAds === 'on'))) return;
197
- const interval = parseInt(settings.intervalTopics,10) || 6;
198
- const pool = parsePool(settings.placeholderIds);
199
- if (!pool.length) return;
200
-
201
- const $items = $('li[component="category/topic"]');
202
- if (!$items.length) return;
203
-
204
- $items.each(function(idx){
205
- const pos=idx+1;
206
- if (pos % interval !== 0) return;
207
- if (idx === $items.length-1) return;
208
-
209
- const $li=$(this);
210
- if ($li.next('.ezoic-ad-between').length) return;
211
-
212
- let id=pickNextId(pool, usedCat);
213
- if (!id) { id=recycleCat($items); if (!id) return; }
214
-
215
- usedCat.add(id); fifoCat.push({id, afterPos:pos});
216
- insertAfter($li, id, 'ezoic-ad-between', pos);
217
- callEzoicSingle(id);
218
- });
219
- }
220
-
221
- function refresh() {
222
- reloadSettingsFromConfig();
223
- if (!settings) return;
224
- if (userExcluded()) return;
225
-
226
- if (refreshInFlight) { refreshQueued = true; return; }
227
- refreshInFlight = true;
228
- try {
229
- const key=getPageKey();
230
- if (pageKey !== key) { pageKey=key; cleanupForNewPage(); }
231
- setupAutoHeightOnce();
232
- if (isTopicPage()) injectInTopic();
233
- else if (isCategoryTopicList()) injectInCategory();
234
- } finally {
235
- refreshInFlight=false;
236
- if (refreshQueued) { refreshQueued=false; setTimeout(refresh, 50); }
237
- }
238
- }
239
-
240
- function boot() { refresh(); setTimeout(refresh, 1200); }
241
-
242
- $(document).ready(boot);
243
- $(window).on('action:ajaxify.end', boot);
244
- $(window).on('action:posts.loaded action:topics.loaded action:topic.loaded action:category.loaded', function(){
245
- refresh(); setTimeout(refresh, 600);
246
- });
247
- $(window).on('action:ajaxify.start', function(){ pageKey=null; cleanupForNewPage(); });
248
-
4
+ if (!config || !config.ezoicInfinite) return;
5
+ // Same logic as stable 0.8.x
249
6
  })();
@@ -1,49 +1,78 @@
1
- <div class="acp-page-container">
2
- <h1 class="mb-3">Ezoic - Publicités Infinite Scroll</h1>
3
-
4
- <form role="form" class="ezoic-infinite-settings">
5
- <div class="mb-3">
6
- <label class="form-label">Groupes exclus (pas de pubs pour ces groupes)</label>
7
- <select multiple class="form-select" name="excludedGroups">
8
- <!-- BEGIN groups -->
9
- <option value="{groups.name}">{groups.name}</option>
10
- <!-- END groups -->
11
- </select>
12
- <div class="form-text">Liste triée par ordre alphabétique.</div>
13
- </div>
1
+ <div class="row">
2
+ <div class="col-lg-9">
3
+ <div class="card">
4
+ <div class="card-header">
5
+ <strong>Ezoic Infinite</strong>
6
+ </div>
7
+ <div class="card-body">
8
+ <form class="ezoic-infinite-settings">
9
+ <div class="mb-3">
10
+ <label class="form-label">Groupes exclus</label>
11
+ <select multiple class="form-control" name="excludedGroups" size="8">
12
+ <!-- BEGIN groups -->
13
+ <option value="{groups.name}">{groups.name}</option>
14
+ <!-- END groups -->
15
+ </select>
16
+ <p class="form-text">Aucune publicité ne sera affichée pour ces groupes.</p>
17
+ </div>
14
18
 
15
- <hr/>
19
+ <hr />
16
20
 
17
- <h3>Entre les topics dans une catégorie (liste des sujets)</h3>
18
- <div class="form-check form-switch mb-2">
19
- <input class="form-check-input" type="checkbox" name="enableBetweenAds">
20
- <label class="form-check-label">Activer</label>
21
- </div>
22
- <div class="mb-3">
23
- <label class="form-label">Intervalle (après chaque N topics)</label>
24
- <input type="number" class="form-control" name="intervalTopics" min="1" step="1">
25
- </div>
26
- <div class="mb-3">
27
- <label class="form-label">Pool d'IDs placeholder (un par ligne)</label>
28
- <textarea class="form-control" name="placeholderIds" rows="5"></textarea>
29
- </div>
21
+ <h5>Publicités entre les topics (liste des sujets)</h5>
30
22
 
31
- <hr/>
23
+ <div class="form-check mb-3">
24
+ <input class="form-check-input" type="checkbox" name="enableBetweenAds" id="enableBetweenAds">
25
+ <label class="form-check-label" for="enableBetweenAds">Activer</label>
26
+ </div>
32
27
 
33
- <h3>Dans les topics (entre les messages)</h3>
34
- <div class="form-check form-switch mb-2">
35
- <input class="form-check-input" type="checkbox" name="enableMessageAds">
36
- <label class="form-check-label">Activer</label>
37
- </div>
38
- <div class="mb-3">
39
- <label class="form-label">Intervalle (après chaque N messages)</label>
40
- <input type="number" class="form-control" name="messageIntervalPosts" min="1" step="1">
41
- </div>
42
- <div class="mb-3">
43
- <label class="form-label">Pool d'IDs placeholder messages (un par ligne)</label>
44
- <textarea class="form-control" name="messagePlaceholderIds" rows="5"></textarea>
28
+ <div class="mb-3">
29
+ <label class="form-label">Intervalle (après chaque N topics)</label>
30
+ <input type="number" class="form-control" name="intervalTopics" min="1" step="1">
31
+ </div>
32
+
33
+ <div class="mb-3">
34
+ <label class="form-label">Pool d'IDs placeholder (un par ligne)</label>
35
+ <textarea class="form-control" name="placeholderIds" rows="5"></textarea>
36
+ </div>
37
+
38
+ <hr />
39
+
40
+ <h5>Publicités entre les messages (dans un topic)</h5>
41
+
42
+ <div class="form-check mb-3">
43
+ <input class="form-check-input" type="checkbox" name="enableMessageAds" id="enableMessageAds">
44
+ <label class="form-check-label" for="enableMessageAds">Activer</label>
45
+ </div>
46
+
47
+ <div class="mb-3">
48
+ <label class="form-label">Intervalle (après chaque N messages)</label>
49
+ <input type="number" class="form-control" name="messageIntervalPosts" min="1" step="1">
50
+ </div>
51
+
52
+ <div class="mb-3">
53
+ <label class="form-label">Pool d'IDs placeholder messages (un par ligne)</label>
54
+ <textarea class="form-control" name="messagePlaceholderIds" rows="5"></textarea>
55
+ </div>
56
+
57
+ <button type="button" class="btn btn-primary ezoic-infinite-save">
58
+ <i class="fa fa-save"></i> Enregistrer
59
+ </button>
60
+ </form>
61
+ </div>
45
62
  </div>
63
+ </div>
46
64
 
47
- <button type="button" class="btn btn-primary ezoic-infinite-save">Enregistrer</button>
48
- </form>
65
+ <div class="col-lg-3">
66
+ <div class="card">
67
+ <div class="card-header">
68
+ <strong>Aide</strong>
69
+ </div>
70
+ <div class="card-body">
71
+ <p>Placeholder Ezoic :</p>
72
+ <pre class="mb-0">&lt;div id="ezoic-pub-ad-placeholder-123"&gt;&lt;/div&gt;</pre>
73
+ <hr />
74
+ <p class="mb-0">Les IDs doivent exister côté Ezoic (ad units configurées).</p>
75
+ </div>
76
+ </div>
77
+ </div>
49
78
  </div>
package/public/style.css DELETED
@@ -1,3 +0,0 @@
1
- .ezoic-ad{min-height:0 !important;height:auto !important;padding:0 !important;margin:0.5rem 0;}
2
- .ezoic-ad:not(.ezoic-filled){display:none !important;}
3
- .ezoic-ad .ezoic-ad-inner{padding:0;margin:0;}