nodebb-plugin-ezoic-infinite 0.9.7 → 0.9.9

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,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const meta = require.main.require('./src/meta');
4
- const groups = require.main.require('./src/groups');
5
4
  const db = require.main.require('./src/database');
6
5
 
7
6
  const SETTINGS_KEY = 'ezoic-infinite';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/admin.js CHANGED
@@ -1,29 +1,75 @@
1
- /* globals ajaxify */
1
+ /* global $, app, socket */
2
2
  'use strict';
3
3
 
4
- (function () {
5
- function init() {
6
- const $form = $('.ezoic-infinite-settings');
7
- if (!$form.length) return;
4
+ $(document).ready(function () {
5
+ const namespace = 'ezoic-infinite';
8
6
 
9
- require(['settings', 'alerts'], function (Settings, alerts) {
10
- Settings.load('ezoic-infinite', $form);
7
+ function load() {
8
+ socket.emit('admin.settings.get', { hash: namespace }, function (err, data) {
9
+ if (err) return;
10
+ data = data || {};
11
11
 
12
- $('#save').off('click.ezoicInfinite').on('click.ezoicInfinite', function (e) {
13
- e.preventDefault();
12
+ const form = $('.ezoic-infinite-settings');
14
13
 
15
- Settings.save('ezoic-infinite', $form, function () {
16
- // Toast vert (NodeBB core)
17
- if (alerts && typeof alerts.success === 'function') {
18
- alerts.success('Enregistré');
19
- } else if (window.app && typeof window.app.alertSuccess === 'function') {
20
- window.app.alertSuccess('Enregistré');
21
- }
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
+ // NodeBB 4.x: charger les groupes via socket côté ACP
23
+ socket.emit('groups.getGroups', {}, function (err2, groups) {
24
+ const $select = form.find('[name="excludedGroups"]');
25
+ $select.empty();
26
+
27
+ if (!err2 && Array.isArray(groups)) {
28
+ groups
29
+ .map(g => g && g.name)
30
+ .filter(Boolean)
31
+ .sort((a, b) => a.localeCompare(b, 'fr', { sensitivity: 'base' }))
32
+ .forEach((name) => {
33
+ $select.append($('<option>').val(name).text(name));
34
+ });
35
+ }
36
+
37
+ const selected = (data.excludedGroups || '').split(',').map(s => s.trim()).filter(Boolean);
38
+ $select.find('option').each(function () {
39
+ $(this).prop('selected', selected.includes($(this).val()));
22
40
  });
23
41
  });
24
42
  });
25
43
  }
26
44
 
27
- $(document).ready(init);
28
- $(window).on('action:ajaxify.end', init);
29
- })();
45
+ function save() {
46
+ const form = $('.ezoic-infinite-settings');
47
+ const payload = {
48
+ enableBetweenAds: form.find('[name="enableBetweenAds"]').is(':checked'),
49
+ intervalTopics: parseInt(form.find('[name="intervalTopics"]').val(), 10) || 6,
50
+ placeholderIds: form.find('[name="placeholderIds"]').val() || '',
51
+
52
+ enableMessageAds: form.find('[name="enableMessageAds"]').is(':checked'),
53
+ messageIntervalPosts: parseInt(form.find('[name="messageIntervalPosts"]').val(), 10) || 3,
54
+ messagePlaceholderIds: form.find('[name="messagePlaceholderIds"]').val() || '',
55
+
56
+ excludedGroups: (form.find('[name="excludedGroups"]').val() || []).join(','),
57
+ };
58
+
59
+ socket.emit('admin.settings.set', { hash: namespace, values: payload }, function (err) {
60
+ if (err) {
61
+ app.alertError(err.message || err);
62
+ return;
63
+ }
64
+ app.alertSuccess('Paramètres enregistrés');
65
+ });
66
+ }
67
+
68
+ $(document).off('click.ezoicInfiniteSave', '.ezoic-infinite-save')
69
+ .on('click.ezoicInfiniteSave', '.ezoic-infinite-save', function (e) {
70
+ e.preventDefault();
71
+ save();
72
+ });
73
+
74
+ load();
75
+ });
package/public/client.js CHANGED
@@ -92,62 +92,19 @@ function pickNextId(pool) {
92
92
  }
93
93
  return null;
94
94
  }
95
- function callEzoic(ids) {
96
- if (!ids || !ids.length) return;
97
95
 
98
- const key = ids.slice().sort((a, b) => a - b).join(',');
99
- const now = Date.now();
100
- if (window.__ezoicLastShowKey === key && now - (window.__ezoicLastShowAt || 0) < 1200) return;
101
- window.__ezoicLastShowKey = key;
102
- window.__ezoicLastShowAt = now;
96
+ function callEzoic(ids) {
97
+ if (!ids || !ids.length) return;
103
98
 
104
- try {
105
- window.ezstandalone = window.ezstandalone || {};
106
- window.ezstandalone.cmd = window.ezstandalone.cmd || [];
107
-
108
- const run = function () {
109
- try {
110
- if (typeof window.ezstandalone.showAds === 'function') {
111
- window.ezstandalone.showAds.apply(window.ezstandalone, ids);
112
- return true;
113
- }
114
- } catch (e) {}
115
- return false;
116
- };
117
-
118
- window.ezstandalone.cmd.push(function () { run(); });
119
-
120
- let tries = 0;
121
- const tick = function () {
122
- tries++;
123
- if (run() || tries >= 10) return;
124
- setTimeout(tick, 800);
125
- };
126
- setTimeout(tick, 800);
127
- } catch (e) {}
128
- }
99
+ window.ezstandalone = window.ezstandalone || {};
100
+ window.ezstandalone.cmd = window.ezstandalone.cmd || [];
129
101
 
130
- if (typeof window.ezstandalone.showAds === 'function') {
131
- window.ezstandalone.showAds.apply(window.ezstandalone, ids);
132
- return true;
133
- }
134
- } catch (e) {}
135
- return false;
136
- };
137
-
138
- // Ensure destroy->show runs AFTER ezstandalone is ready
139
- window.ezstandalone.cmd.push(function () { run(); });
140
-
141
- // retries in case ez loads late
142
- let tries = 0;
143
- const tick = function () {
144
- tries++;
145
- if (run() || tries >= 10) return;
146
- setTimeout(tick, 800);
147
- };
148
- setTimeout(tick, 800);
149
- } catch (e) {}
150
- }
102
+ const run = function () {
103
+ try {
104
+ if (typeof window.ezstandalone.showAds === 'function') {
105
+ window.ezstandalone.showAds.apply(window.ezstandalone, ids);
106
+ return true;
107
+ }
151
108
  } catch (e) {}
152
109
  return false;
153
110
  };