From f4821010b06a5495106694b4a1ac7cc900618b89 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 2 May 2024 09:33:20 +0800 Subject: [PATCH] repeat the scroll two times to ensure proper webpage load --- scripts/external/scraper.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/external/scraper.js b/scripts/external/scraper.js index c1c6bb6..7c9ee45 100644 --- a/scripts/external/scraper.js +++ b/scripts/external/scraper.js @@ -10,9 +10,15 @@ export default class scraper { function autoscroll() { let SCROLL = {"x": window.scrollX, "y": window.scrollY}; - [{"top": 0, "left": 0, "behavior": "smooth"}, {"top": document.body.scrollHeight, "left": document.body.scrollWidth, "behavior": "smooth"}, {"top": SCROLL[`y`], "left": SCROLL[`x`], "behavior": "smooth"}].forEach((POSITION) => { - window.scrollTo(POSITION); - }) + // Repeat two times to ensure proper webpage load. + for (let TIMES = 1; TIMES <= 2; TIMES++) { + [{"top": 0, "left": 0, "behavior": "smooth"}, {"top": document.body.scrollHeight, "left": document.body.scrollWidth, "behavior": "smooth"}].forEach((POSITION) => { + window.scrollTo(POSITION); + }) + }; + + // Scroll back to user's previous position. + window.scrollTo({"top": SCROLL[`y`], "left": SCROLL[`x`], "behavior": "smooth"}); }; autoscroll();