From e2867cfe1453f06d6bfab769552d39ba8b30df24 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 5 Sep 2022 08:53:50 +0200 Subject: Shortcuts: auto-load at least a few articles (#4532) * Auto-load at least a few articles #fix https://github.com/FreshRSS/FreshRSS/issues/3974 * Fix init * syntax * Aledeg simplification --- p/scripts/main.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index b0a6df01b..90e7d79c8 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -720,10 +720,14 @@ function onScroll() { } }); } - if (context.auto_load_more) { - const streamFooter = document.getElementById('stream-footer'); - if (streamFooter && box_to_follow.offsetHeight > 0 && + let streamFooter; + if (context.auto_load_more && (streamFooter = document.getElementById('stream-footer'))) { + if (box_to_follow.offsetHeight > 0 && box_to_follow.scrollTop + box_to_follow.offsetHeight + (window.innerHeight / 2) >= streamFooter.offsetTop) { + // Too close to the last pre-loaded article + load_more_posts(); + } else if (document.querySelectorAll('.flux.current ~ .flux').length <= 5) { + // Too few pre-loaded articles load_more_posts(); } } -- cgit v1.2.3