Created
July 28, 2020 21:11
-
-
Save vadimstasiev/e404570558ad8f0a9be453f48f0612e9 to your computer and use it in GitHub Desktop.
Fast Infinite Scroll Down - JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I made this to use for selenium to inject and get a page to fully scroll down to the bottom | |
// however as I later found out, certain website elements unload once they get out of the user's view | |
// but this may come in handy for other things, so here it is | |
window.isDoneScrolling = false; | |
let numberOfTries = 0; | |
const maxNumberOfTries = 100; | |
let lastScrollHeight = document.body.scrollHeight; | |
let scrollThePageInterval = setInterval(()=>{window.scrollTo(0, document.body.scrollHeight); | |
if(lastScrollHeight===document.body.scrollHeight){ | |
numberOfTries+=1; | |
} else { | |
lastScrollHeight = document.body.scrollHeight; | |
} | |
if(numberOfTries> maxNumberOfTries){ | |
clearInterval(scrollThePageInterval); | |
console.log("done"); | |
window.isDoneScrolling = true; | |
} | |
}, 200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment