I've been working on a script that scrolls to the dead end of my twitter follower [twitter/following] list automatically. So far, I've achieved this with my newbie knowledge:
var delay=2000
setTimeout(function(){
for(var i = 0; i<10; i++){
window.scrollTo(0,document.body.scrollHeight);
}
},delay)
The problem the scroller stops after one scroll to the bottom and it doesn't scroll further when the page height changes. Is there a way to loop it with a delay so that scroll gets executed repeatedly until it reaches the last follower.
Alternatively, is there a way to do the same by constantly tracking and dynamically updating the height of the page.
I've been working on a script that scrolls to the dead end of my twitter follower [twitter./following] list automatically. So far, I've achieved this with my newbie knowledge:
var delay=2000
setTimeout(function(){
for(var i = 0; i<10; i++){
window.scrollTo(0,document.body.scrollHeight);
}
},delay)
The problem the scroller stops after one scroll to the bottom and it doesn't scroll further when the page height changes. Is there a way to loop it with a delay so that scroll gets executed repeatedly until it reaches the last follower.
Alternatively, is there a way to do the same by constantly tracking and dynamically updating the height of the page.
Share Improve this question edited Mar 30, 2014 at 14:38 Ken asked Mar 30, 2014 at 13:28 KenKen 9022 gold badges15 silver badges34 bronze badges2 Answers
Reset to default 14I think you want to use setInterval
instead of setTimeout
.
setInterval
will fire repeatedly instead of just the one time.
This works for me:
setInterval(function() { window.scrollTo(0, document.body.scrollHeight); },
2000);
If you don't have a request delay when scrolling you can use:
function scrollToBottom() {
// onscroll is only called when scrollHeight changes
// avoiding infinit loop
window.onscroll = () => {
window.scroll(0, window.scrollHeight);
}
window.scroll(0, window.scrollHeight);
}