Skip to content

Instantly share code, notes, and snippets.

@balbuf
Forked from robwalkerco/zenfolio-photo-downloader.js
Last active December 10, 2022 23:16
Show Gist options
  • Save balbuf/83eede995eb4e07226a20e36a36c9c6f to your computer and use it in GitHub Desktop.
Save balbuf/83eede995eb4e07226a20e36a36c9c6f to your computer and use it in GitHub Desktop.
Zenfolio photo downloader
(async () => {
const link = document.createElement('a');
document.body.appendChild(link);
// loop through matching images
for (const image of document.querySelectorAll('.pv-inner img:first-child')) {
const path = image.style.backgroundImage.split('"')[1].replace(/-\d.jpg/, '-5.jpg');
// filename of the image
link.download = new URL(path).pathname.replace(/^.*\//, '');
// fetch the image, convert it to a data URL, set as the href of the link element
link.href = await fetch(path)
.then(response => response.blob())
.then(blob => new Promise(resolve => {
const reader = new FileReader() ;
reader.onload = () => resolve(reader.result);
reader.readAsDataURL(blob);
}));
// trigger the link to download the image
link.click();
}
// cleanup
document.body.removeChild(link);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment