Last active
August 29, 2015 14:21
-
-
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.
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
(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