Skip to content

Instantly share code, notes, and snippets.

@sweshelo
Last active October 28, 2021 16:47
Show Gist options
  • Save sweshelo/13333cc39c72967bfe66cc53ee1b5328 to your computer and use it in GitHub Desktop.
Save sweshelo/13333cc39c72967bfe66cc53ee1b5328 to your computer and use it in GitHub Desktop.
でんこの立ち絵をダウンロードするスクリプト
const parseURL = (dencohName)=>{
const version = 'v=2021102601';
const wrapping = 'default';
const size = 'large';
const part = 'face';
const emotion = 'smile';
const domain = document.domain;
return "https://"+domain+"/"+version+"/img/partner/"+dencohName+"/"+wrapping+"/"+size+"/"+part+"_"+emotion+".png";
}
const main = async ()=>{
await import('https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js');
await import('https://cdnjs.cloudflare.com/ajax/libs/jszip-utils/0.1.0/jszip-utils.min.js');
const zip = new JSZip();
const images = [];
const fileName = [];
fetch("https://scripts.sweshelo.jp/dencoh_name.json", {
mode: 'cors'
})
.then(res => res.json())
.then(res => {
Promise.all(res.map(dencoh =>(
fetch (parseURL(dencoh.name_en)).then(res => {
if(res.ok){
zip.file(dencoh.name_en + ".png", res.blob());
}
})
))).then(()=>{
console.log('yay!');
zip.generateAsync({ type: 'blob' }).then(function(blob){
const e = document.createElement("a");
const url = window.URL.createObjectURL(blob);
document.body.appendChild(e);
e.href = url;
e.click();
console.log('successed!', blob);
});
})
})
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment