Skip to content

Instantly share code, notes, and snippets.

@Scarsz
Created November 6, 2016 23:33
Show Gist options
  • Save Scarsz/6faa65cf74e5702c4266343fa04c8adb to your computer and use it in GitHub Desktop.
Save Scarsz/6faa65cf74e5702c4266343fa04c8adb to your computer and use it in GitHub Desktop.
JavaScript bookmarklet to get links to all imgs on the current page and optionally download them
(function() {
var images = [].slice.call(document.querySelectorAll('img'));
var urls = [];
images.forEach(function(img) {
if (!urls.includes(img.src)) urls.push(img.src);
});
if (confirm("Download all the things?")) {
var link = document.createElement('a');
link.setAttribute('download', '');
urls.forEach(function(img) {
link.setAttribute('href', img);
link.click();
});
}
var x = document.createElement("TEXTAREA");
var t = document.createTextNode(urls.join("\r\n"));
x.appendChild(t);
document.body.appendChild(x);
}).call(window);
javascript:;(function() { var images = [].slice.call(document.querySelectorAll('img')); var urls = []; images.forEach(function(img) { if (!urls.includes(img.src)) urls.push(img.src); }); if (confirm("Download all the things?")) { var link = document.createElement('a'); link.setAttribute('download', ''); urls.forEach(function(img) { link.setAttribute('href', img); link.click(); }); } var x = document.createElement("TEXTAREA"); var t = document.createTextNode(urls.join("\r\n")); x.appendChild(t); document.body.appendChild(x);}).call(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment