Можно скачать как архив и распаковать куда нужно! 📦
<button id="download" disabled>Создание архива...</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
<script>
(async () => {
const imgs = [
'https://javascript.ru/forum/images/ca_serenity/misc/logo.gif',
'https://javascript.ru/forum/image.php?u=60342&dateline=1502033143'
];
const zip = new JSZip();
const extensions = {
"image/jpeg": ".jpg",
"image/gif": ".gif",
"image/svg+xml": ".svg",
"image/png": ".png",
};
var counter = 1;
for(const src of imgs) {
const response = await fetch(`https://cors-anywhere.herokuapp.com/${src}`);
const blob = await response.blob();
zip.file(
`file-${counter++}${extensions[blob.type]}`,
blob,
{ binary: true }
);
}
zip.generateAsync({ type: "blob" }).then(function(content) {
const button = document.getElementById("download");
const link = document.createElement("a");
link.download = "images.zip";
link.href = URL.createObjectURL(content);
button.textContent = "Скачать изображения";
button.disabled = false;
button.addEventListener("click", event => {
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
});
})();
</script>