See the Pen Line Sticker Downloader LINEスタンプダウンロード by John Doe (@04) on CodePen.
スマホの場合は右上からリンクコピーできるよ
ソースコード
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts"
import { JSZip } from "https://deno.land/x/jszip/mod.ts"
const headers = { 'Access-Control-Allow-Origin': '*' }
Deno.serve(async (req: Request) => {
const m = req.url.match(/\d+/)
if (!m) return new Response()
const r = await fetch(`https://store.line.me/stickershop/product/${m[0]}/ja`)
if (!r.ok) return new Response()
const document = new DOMParser().parseFromString(await r.text(), 'text/html')
const stickers = [...document.querySelectorAll('li[data-preview]')].map(li => JSON.parse(li.dataset.preview))
if (req.url.includes('.zip')) {
const zip = new JSZip()
const static_promises = stickers.map(async s => s.staticUrl && zip.addFile(s.id + '.static.png', await fetch(s.staticUrl).then(r=>r.blob())))
const animation_promises = stickers.map(async s => s.animationUrl && zip.addFile(s.id + '.animation.png', await fetch(s.animationUrl).then(r=>r.blob())))
const popup_promises = stickers.map(async s => s.popupUrl && zip.addFile(s.id + '.popup.png', await fetch(s.popupUrl).then(r=>r.blob())))
const sound_promises = stickers.map(async s => s.soundUrl && zip.addFile(s.id + '.sound.m4a', await fetch(s.soundUrl).then(r=>r.blob())))
await Promise.all([...static_promises, ...animation_promises, ...popup_promises, ...sound_promises])
const zipFile = await zip.generateAsync({ type: 'uint8array' })
return new Response(zipFile, {
headers: {
'content-type': 'application/zip',
'content-disposition': `attachment; filename=${m[0]}.line.zip`,
...headers
}
})
} else {
return Response.json(stickers, { headers })
}
});