-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_infinity_scroll.js
More file actions
31 lines (27 loc) · 1.05 KB
/
script_infinity_scroll.js
File metadata and controls
31 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// ======================
// Infinite Scroll Loader
// ======================
// Add a scroll listener to window (or a scrollable container if needed)
window.addEventListener('scroll', async () => {
const nearBottom = window.innerHeight + window.scrollY >= document.body.offsetHeight - 200;
if (!nearBottom) return;
// Basic safety: Avoid re-fetching if data isn't loaded yet
if (!window.Played || !Array.isArray(window.Played)) return;
// Prevent loading more if we've already used all watched IDs
if (usedWatchedIds.size >= window.Played.length) {
console.info("All watched Contents have been used. No more recommendations to fetch.");
return;
}
// Fetch and append new batch
try {
getSugestions(ContentsToCheck, similarsToShow) // Default values for demonstration
.then(recommendations => {
displayRecommendations(recommendations);
})
.catch(error => {
console.error("Infinite scroll error:", error);
});
} catch (err) {
console.error("Failed during infinite scroll trigger:", err);
}
});