Auto-scroll an Infinite-scroll page
Remember when we had pagination in all websites and you could click on “Last Page”? That’s why I miss medieval times… they were simple times.
Nowadays, most blogs, social networks and news site adopted the awesome “infinite scroll”, which is amazing from mobile yet causes a few headaches if you want to retrieve “the first” of something.
For example, let’s say you want to see the first tweet of a Twitter account or the first post of a blog. You need to start scrolling and scrolling and keep scrolling and scrolling.
Unless, JavaScript.
Below is a quick snippet that you can Copy & Paste in any JS Console (Chrome Web Tool, Firefox, Firebug etc…) to keep scrolling until the end of the time.
The snippet uses a 2 seconds timeout to wait for the Ajax call to load before performing a second call.
It’s not dependent on any library, just use a modern browser.
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}ContinueCycle = truewhile(ContinueCycle) {
await sleep(2000);
window.scrollTo(0,document.body.scrollHeight);
}
When you’re satisfied just interrupt the cycle
ContinueCycle = false