Skip to content

Instantly share code, notes, and snippets.

@superbiche
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superbiche/90e2f873f21a5777a70a to your computer and use it in GitHub Desktop.
Save superbiche/90e2f873f21a5777a70a to your computer and use it in GitHub Desktop.
Scroll down an infinite scroll page each 5 seconds, stop if bottom reached.
(function() {
var interval = 2000;
var failLimit = 20;
var stopped = 0;
var tick = setInterval(function() {
var ph = document.body.clientHeight;
var top = window.pageYOffset;
var ih = window.innerHeight;
if (ph > top + ih) {
window.scrollTo(0, ph);
console.log('scrolling');
} else {
stopped++;
console.log('Failed scrolling ' + stopped + ' times, trying again in ' + interval/1000 + ' seconds...');
if (stopped >= failLimit) {
console.log('Scroll fail limit of ' + failLimit + ' has happened, stopping loop.');
alert('Page end reached!');
clearInterval(tick);
}
}
}, interval);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment