-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
44 lines (43 loc) · 1.86 KB
/
index.html
File metadata and controls
44 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="generateZIP()">Download Zip File</button>
<script src="js/jszip.js"></script>
<script src="js/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
<script>
async function generateZIP(){
var zip = new JSZip();
var count = 0;
var zipFilename = "images_bundle.zip";
// we will download these images in zip file
var images = [
"https://upload.wikimedia.org/wikipedia/commons/9/91/JavaScript_screenshot.png",
"https://images.milanuncios.com/api/v1/ma-ad-media-pro/images/296b1d59-04bf-46e4-a449-6815a222dbf5?rule=hw545",
"https://lets-code-more.s3.amazonaws.com/static/assets/imgs/theme/COMPUTER.jpg",
"https://lets-code-more.s3.amazonaws.com/media/blog_images/javascript.jpg"
]
images.forEach(async function (imgURL, i) {
console.log(i)
var filename = "image" + i + '.jpg'
var image = await fetch(imgURL)
var imageBlog = await image.blob()
var img = zip.folder("images");
// loading a file and add it in a zip file
img.file(filename, imageBlog, { binary: true });
count ++
if (count == images.length) {
zip.generateAsync({ type: 'blob' }).then(function (content) {
saveAs(content, zipFilename);
});
}
})
}
</script>
</body>
</html>