Last active
November 7, 2023 14:36
-
-
Save aice09/65ce63c429134d684148daca3648c15c to your computer and use it in GitHub Desktop.
Download multiple files at a time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var itemurl=`https://cdn.hxmanga.com/file/majekayoo/record-of-ragnarok/Chapter-68/` | |
for(let i=1; i<=42; i++){ | |
setTimeout(() => { | |
//let num = i < 10 ? '0' + i : i; | |
//if less than 100 add 1 zeros to the left and if less than 10 add 2 zeros to the left | |
let num = i.toString().padStart(3, '0'); | |
fetch(itemurl+`${num}.jpg`) | |
.then(resp => resp.blob()) | |
.then(blob => { | |
const url = window.URL.createObjectURL(blob); | |
const a = document.createElement('a'); | |
a.style.display = 'none'; | |
a.href = url; | |
// the filename you want | |
a.download = `rog-${i}.jpg`; | |
document.body.appendChild(a); | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
}) | |
.catch(() => alert('oh no!')); | |
}, i*1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment