Last active
April 28, 2022 20:46
-
-
Save hlecuanda/ba7c0a1e9984e8e79dd35ce67bf9b1ef to your computer and use it in GitHub Desktop.
A bookmarklet to download all images on a page, using the FileSystem API
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
javascript:(function(){ | |
const run = async () => { | |
const dirHandle = await window.showDirectoryPicker(); | |
const imgs = document.querySelectorAll("img"); | |
let i = 0; | |
imgs.forEach(async (img) => { | |
const url = img.src; | |
const name = `img-${i}.png`; | |
i++; | |
try { | |
console.log(`Fetching ${url}`); | |
const response = await fetch(url); | |
console.log(`Saving to ${name}`); | |
const file = await dirHandle.getFileHandle(name, { create: true }); | |
const writable = await file.createWritable(); | |
await response.body.pipeTo(writable); | |
} catch (err) { | |
console.log(err); | |
} | |
}); | |
}; | |
run(); | |
})(); |
also, credit where credit is due, this code was shamelessly taken from
https://paul.kinlan.me/bookmarklet-to-download-all-images-on-a-page-with-the-file-system-api/
i had tried a multitude of approaches and plugins for this purpose, and this is the most elegant solution.
TODO: tweak the client side filepicker, filter by image size, so as not to download a gazillion tracker pixels along with actual images i want
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
removed my dumb comment which, being on the first line of code, turned the whole gist into a comment 🤦♂️