-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpics.html
48 lines (44 loc) · 2.03 KB
/
pics.html
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
45
46
47
48
<html lang="en">
<body>
<h1>Hello</h1>
<input id="input" type="file" webkitdirectory directory multiple>
<p id="p1"></p>
<button id="filterBtn" style="display: none">Filter</button>
<p id="p2"></p>
<button id="downloadBtn" style="display: none">Download</button>
<p id="p3"></p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.2/jszip.min.js" integrity="sha256-gy5W5/rXWluWXFRvMWFFMVhocfpBe7Tf4SW2WMfjs4E=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js"></script>
<script>
let fileList;
let filteredFiles = [];
document.getElementById("input").addEventListener("change", handleFiles, false);
function handleFiles() {
fileList = this.files;
document.getElementById('p1').innerHTML = `Total: ${this.files.length} elements`;
document.getElementById('filterBtn').style.display = 'block';
}
document.getElementById("filterBtn").addEventListener("click", filter, false);
function filter(){
const newFiles = [...fileList].reduce((acc, cur) =>
acc.some(f =>
Math.abs(cur.lastModified - f.lastModified) <= 2000
) ? acc : [...acc, cur]
, [])
filteredFiles = newFiles;
document.getElementById('p2').innerHTML = `Filtered: ${newFiles.length} elements`;
document.getElementById('downloadBtn').style.display = 'block';
}
document.getElementById("downloadBtn").addEventListener("click", download, false);
function download() {
document.getElementById('p3').innerHTML = 'Download is being prepared, please wait ...';
var zip = new JSZip();
filteredFiles.forEach(file => zip.file(file.name, file))
zip.generateAsync({type:"blob"})
.then(function(content) {
const filesaver = saveAs(content, "filtered_pics.zip");
});
}
</script>
</body>
</html>