repeat the scroll two times to ensure proper webpage load

This commit is contained in:
buzz-lightsnack-2007 2024-05-02 09:33:20 +08:00
parent a3749c71d2
commit f4821010b0

View file

@ -10,11 +10,17 @@ export default class scraper {
function autoscroll() { function autoscroll() {
let SCROLL = {"x": window.scrollX, "y": window.scrollY}; 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) => { // 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); window.scrollTo(POSITION);
}) })
}; };
// Scroll back to user's previous position.
window.scrollTo({"top": SCROLL[`y`], "left": SCROLL[`x`], "behavior": "smooth"});
};
autoscroll(); autoscroll();
if ((typeof scraper_fields).includes("object") && scraper_fields != null && scraper_fields) { if ((typeof scraper_fields).includes("object") && scraper_fields != null && scraper_fields) {