Last active
March 13, 2025 11:24
-
-
Save sfrdmn/8834747 to your computer and use it in GitHub Desktop.
Bookmarklet to download all images on a page
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
;(function() { | |
var images = [].slice.call(document.querySelectorAll('img')) | |
try { | |
images.forEach(function(img) { | |
downloadImage(img) | |
}) | |
} catch (e) { | |
alert("Download failed."); | |
console.log('Download failed.', e); | |
} | |
function downloadImage(img) { | |
var link = document.createElement('a') | |
link.setAttribute('href', img.src) | |
link.setAttribute('download', '') | |
link.click() | |
} | |
}).call(window); |
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
javascript:;(function() {var images = [].slice.call(document.querySelectorAll('img'));try {images.forEach(function(img){downloadImage(img)})} catch (e) {alert('Download failed.');console.log('Download failed.', e)}function downloadImage(img) {var link = document.createElement('a');link.setAttribute('href', img.src);link.setAttribute('download', '');link.click()}}).call(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I adjusted this to wait a half second between requests and it runs a bit more reliably. I also include an example selector with a class specified. In
var sel-'img.image-large'
, you can narrow your downloads to just those images with a particular class. Make sure to change the class name after the.
to meet your specific case:(function() {var sel='img.image-large',i=0; var images = [].slice.call(document.querySelectorAll(sel));try {images.forEach(function(img){downloadImage(img,i++)})} catch (e) {alert('Download failed.');console.log('Download failed.', e)}function downloadImage(img) {var link = document.createElement('a');link.setAttribute('href', img.src);link.setAttribute('download', ''); setTimeout( ()=>{link.click()}, i*500 ) }}).call(window);
A variant of the code above removing filtering by class... With
var sel='img'
, all images will download:(function() {var sel='img',i=0; var images = [].slice.call(document.querySelectorAll(sel));try {images.forEach(function(img){downloadImage(img,i++)})} catch (e) {alert('Download failed.');console.log('Download failed.', e)}function downloadImage(img) {var link = document.createElement('a');link.setAttribute('href', img.src);link.setAttribute('download', ''); setTimeout( ()=>{link.click()}, i*500 ) }}).call(window);
To be clear, just paste one of these "one-liners" into the console of a browser page and watch all the images of that page download in (fairly) rapid succession, one every 0.5 seconds to let the browser "breathe" a bit between downloads.