nodebb-plugin-ezoic-infinite 1.0.7 → 1.0.8

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 +24 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
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/client.js CHANGED
@@ -40,7 +40,27 @@
40
40
  return document.querySelectorAll('li[component="category/topic"]').length > 0 && !isTopicPage();
41
41
  }
42
42
 
43
+
44
+ function normalizeBool(v) {
45
+ return v === true || v === 1 || v === '1' || v === 'on' || v === 'true' || v === 'yes';
46
+ }
47
+
48
+ function normalizeInterval(v, fallback) {
49
+ const n = parseInt(v, 10);
50
+ return Number.isFinite(n) && n > 0 ? n : fallback;
51
+ }
52
+
53
+ function getPoolValue(v) {
54
+ // Accept string, array of numbers/strings
55
+ if (Array.isArray(v)) return v.join('\n');
56
+ return v;
57
+ }
58
+
43
59
  function parsePool(raw) {
60
+ raw = getPoolValue(raw);
61
+
62
+ raw = getPoolValue(raw);
63
+
44
64
  if (!raw) return [];
45
65
  // accept newline, comma, space, semicolon
46
66
  const arr = String(raw).split(/[\n,;\s]+/)
@@ -153,8 +173,8 @@
153
173
  }
154
174
 
155
175
  function injectBetweenTopics(cfg) {
156
- if (!cfg.enableBetweenAds) return;
157
- const interval = Math.max(1, parseInt(cfg.intervalPosts, 10) || 6);
176
+ if (!normalizeBool(cfg.enableBetweenAds)) return;
177
+ const interval = normalizeInterval(cfg.intervalPosts ?? cfg.intervalTopics, 6);
158
178
  const pool = parsePool(cfg.placeholderIds);
159
179
  if (!pool.length) return;
160
180
 
@@ -184,8 +204,8 @@
184
204
  }
185
205
 
186
206
  function injectBetweenMessages(cfg) {
187
- if (!cfg.enableMessageAds) return;
188
- const interval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
207
+ if (!normalizeBool(cfg.enableMessageAds)) return;
208
+ const interval = normalizeInterval(cfg.messageIntervalPosts, 3);
189
209
  const pool = parsePool(cfg.messagePlaceholderIds);
190
210
  if (!pool.length) return;
191
211