Last active
April 8, 2016 19:49
-
-
Save hattmarris/b2fb66193c6a914cf1eb3b6f2f147498 to your computer and use it in GitHub Desktop.
Get images on a page an download them
This file contains hidden or 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
// 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