Skip to content

Instantly share code, notes, and snippets.

@hattmarris
Last active April 8, 2016 19:49
Show Gist options
  • Save hattmarris/b2fb66193c6a914cf1eb3b6f2f147498 to your computer and use it in GitHub Desktop.
Save hattmarris/b2fb66193c6a914cf1eb3b6f2f147498 to your computer and use it in GitHub Desktop.
Get images on a page an download them
// Select a NodeList of image elements
var selector = 'ul.pages li img[src]'; // Images with src nested in <li> els in the <ul> with pages class
var images = document.querySelectorAll(selector);
function saveAll(images) {
for(var i=0; i<images.length; i++) {
var image = images[i];
saveImageAs(i+1, images[i].src); // use index+1 as their name for page number approximation
}
}
function saveImageAs(name, src) {
var link = document.createElement('a');
link.href = src;
link.download = name;
document.body.appendChild(link);
link.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment