Last active
November 17, 2017 17:12
-
-
Save glenndevenish/ca2884d06f484091c027ea74583fe17c to your computer and use it in GitHub Desktop.
Automatically scroll on a page (for getting lazy-loaded pages)
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
/* | |
Automatically scroll on a page (for getting lazy-loaded pages). | |
Run in the console. | |
UPDATE: Now shows percentage | |
*/ | |
var scroll_units = 1000; | |
var scroll_iterations = 30; | |
var scroll_delay = 2000; | |
var iterations = 0; | |
var percent = 0; | |
var percent_string = '#'; | |
var total_percent_units = 50; | |
var percent_spacing = ''; | |
console.clear(); | |
var interval = setInterval( | |
function() { | |
scrollBy(0, scroll_units); | |
percent = ((iterations) / scroll_iterations) * total_percent_units; | |
percent_string = '#'; | |
percent_spacing = ''; | |
for(var i = 0; i < Math.ceil(percent); i++) { | |
percent_string += '#'; | |
} | |
for(var i = 0; i < total_percent_units - Math.ceil(percent); i++) { | |
percent_spacing += ' '; | |
} | |
console.clear() | |
console.log("[" + percent_string + percent_spacing + "] " + (Math.ceil(100 * percent / total_percent_units)).toString() + " percent"); | |
iterations++; | |
if(iterations > scroll_iterations) { | |
clearInterval(interval); | |
} | |
}, scroll_delay) |
If the percentage thing is unnecessary, you can simply use:
var scroll_units = 1000;
var scroll_iterations = 30;
var scroll_delay = 2000;
var iterations = 0;
var interval = setInterval(
function() {
scrollBy(0, scroll_units);
iterations++;
if(iterations > scroll_iterations) {
clearInterval(interval);
}
}, scroll_delay)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can cancel this in the console with
clearInterval(interval)