nodebb-plugin-ezoic-infinite 1.0.14 → 1.0.16
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 +23 -7
package/package.json
CHANGED
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
|
-
|
|
191
|
-
|
|
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)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
|