web browserで複数のファイルを一括downloadする
一旦圧縮してからdownloadするのが無難そう
dependencies
tstype Data = {
data: Blob;
fileName: string;
}[];
script.jsimport {installCDN} from '../scrapbox-install-CDN/script.js';
const installed = await installCDN({
id: 'scrapbox-userscript-jszip',
src: '//cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js'
});
export async function zipAll(data, folderName) {
await installed;
let zip = new JSZip();
let folder = folderName ? zip.folder(folderName) : zip;
data.forEach(({data, fileName}) => folder.file(`${fileName}.${data.type.match(/^[^\/]+\/(.*)$/)[1]}`, data));
return {
data: await zip.generateAsync({type: "blob"}),
fileName: `${folderName}.zip`,
};
}
Reference