generated at
web browserで複数のファイルを一括downloadする
javascript
一旦圧縮してからdownloadするのが無難そう
圧縮にはJSZipを使う
dependencies
ts
type Data = { data: Blob; fileName: string; }[];
script.js
import {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

#2021-04-06 18:02:53
#2021-03-01 17:17:46