Skip to content

Instantly share code, notes, and snippets.

@glenndevenish
Last active November 17, 2017 17:12
Show Gist options
  • Save glenndevenish/ca2884d06f484091c027ea74583fe17c to your computer and use it in GitHub Desktop.
Save glenndevenish/ca2884d06f484091c027ea74583fe17c to your computer and use it in GitHub Desktop.
Automatically scroll on a page (for getting lazy-loaded pages)
/*
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)
@glenndevenish
Copy link
Author

You can cancel this in the console with clearInterval(interval)

@glenndevenish
Copy link
Author

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