nodebb-plugin-ezoic-infinite 1.0.15 → 1.0.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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
@@ -186,16 +186,32 @@
186
186
  }
187
187
 
188
188
  function recycle(fifo, usedSet, selector) {
189
+ // Recycle only ads that are safely outside the viewport (to avoid ads “disappearing” while reading)
190
+ const margin = 1200; // px
191
+ const vpTop = -margin;
192
+
189
193
  fifo.sort((a, b) => a.after - b.after);
190
- while (fifo.length) {
191
- const old = fifo.shift();
194
+
195
+ // Prefer recycling ads far ABOVE the current viewport (user has already passed them)
196
+ for (let i = 0; i < fifo.length; i++) {
197
+ const old = fifo[i];
192
198
  const el = document.querySelector(selector(old));
193
- if (!el) continue;
194
- el.remove();
195
- usedSet.delete(old.id);
196
- destroyPlaceholder(old.id);
197
- return old.id;
199
+ if (!el) {
200
+ fifo.splice(i, 1);
201
+ i--;
202
+ continue;
203
+ }
204
+ const r = el.getBoundingClientRect();
205
+ if (r.bottom < vpTop) {
206
+ fifo.splice(i, 1);
207
+ el.remove();
208
+ usedSet.delete(old.id);
209
+ destroyPlaceholder(old.id);
210
+ return old.id;
211
+ }
198
212
  }
213
+
214
+ // If nothing is safely above, do NOT recycle.
199
215
  return null;
200
216
  }
201
217
 
@@ -221,7 +237,8 @@
221
237
 
222
238
  items.forEach((li, idx) => {
223
239
  const pos = idx + 1;
224
- if (pos % interval !== 0) return;
240
+ const firstEnabled = normalizeBool(cfg.showFirstTopicAd);
241
+ if (!(firstEnabled && pos === 1) && (pos % interval !== 0)) return;
225
242
  if (idx === items.length - 1) return;
226
243
 
227
244
  const next = li.nextElementSibling;
@@ -252,7 +269,8 @@
252
269
 
253
270
  posts.forEach((post, idx) => {
254
271
  const no = idx + 1;
255
- if (no % interval !== 0) return;
272
+ const firstEnabled = normalizeBool(cfg.showFirstMessageAd);
273
+ if (!(firstEnabled && no === 1) && (no % interval !== 0)) return;
256
274
  if (idx === posts.length - 1) return;
257
275
 
258
276
  const next = post.nextElementSibling;
@@ -7,6 +7,10 @@
7
7
  <div class="form-check mb-3">
8
8
  <input class="form-check-input" type="checkbox" id="enableBetweenAds" name="enableBetweenAds" {enableBetweenAds_checked}>
9
9
  <label class="form-check-label" for="enableBetweenAds">Activer les pubs entre les posts</label>
10
+ <div class="form-check mt-2">
11
+ <input class="form-check-input" type="checkbox" name="showFirstTopicAd" />
12
+ <label class="form-check-label">Afficher une pub après le 1er sujet</label>
13
+ </div>
10
14
  </div>
11
15
 
12
16
  <div class="mb-3">
@@ -28,6 +32,10 @@
28
32
  <div class="form-check mb-3">
29
33
  <input class="form-check-input" type="checkbox" id="enableMessageAds" name="enableMessageAds" {enableMessageAds_checked}>
30
34
  <label class="form-check-label" for="enableMessageAds">Activer les pubs “message”</label>
35
+ <div class="form-check mt-2">
36
+ <input class="form-check-input" type="checkbox" name="showFirstMessageAd" />
37
+ <label class="form-check-label">Afficher une pub après le 1er message</label>
38
+ </div>
31
39
  </div>
32
40
 
33
41
  <div class="mb-3">