-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
342 lines (320 loc) · 19.1 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<head>
<title>Check Duplicate</title>
<link rel="icon" type="image/x-icon" href="./assets/icon.png">
<style>
:root {
--background: #151515;
--text: #f0f0f0;
--second: #303030;
--table: #515151;
--accent: #2c4961;
--hover: 150%;
--active: 175%;
--different: #572018;
--same: #214a27;
}
body {
font-family: 'Work Sans', sans-serif;
color: var(--text);
background-color: var(--background);
padding: 15px;
}
progress {
width: 100%;
height: 18px;
border-radius: 8px;
color: var(--second);
}
progress::-webkit-progress-bar {
border-radius: 8px;
}
progress::-webkit-progress-value {
border-radius: 8px;
}
progress::-moz-progress-bar {
border-radius: 8px;
}
progress::-moz-progress-bar {
background: var(--accent);
}
progress::-webkit-progress-value {
background: var(--accent);
}
.secondContainer {
padding: 10px;
background-color: var(--second);
border-radius: 8px;
}
table>tbody>tr>* {
padding: 10px;
border-radius: 8px;
}
table>tbody>tr {
background-color: var(--table);
border-radius: 8px;
}
a {
color: var(--text);
text-decoration: underline;
}
button {
width: 100%;
background-color: var(--accent);
border-radius: 8px;
padding: 10px;
font-family: 'Work Sans', sans-serif;
color: var(--text);
border: 1px solid var(--text);
transition: filter 0.15s ease-in-out
}
button:hover {
cursor: pointer;
filter: brightness(var(--hover));
}
button:active {
filter: brightness(var(--active));
}
.marginChild>* {
margin-right: 10px;
}
a:hover {
cursor: pointer;
}
input[type="checkbox"] {
-webkit-appearance: none;
appearance: none;
background-color: var(--background);
margin: 5px;
min-width: 20px;
min-height: 20px;
max-width: 20px;
max-height: 20px;
border: 2px solid var(--accent);
border-radius: 4px;
margin-right: 10px;
cursor: pointer;
position: relative;
}
input[type="checkbox"]:checked {
background-color: var(--accent);
}
input[type="checkbox"]:checked:after {
content: '';
position: absolute;
left: 10%;
top: 10%;
width: 80%;
height: 80%;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M20.285 6.289a1 1 0 0 0-1.414 0l-11.36 11.36-4.95-4.95a1 1 0 1 0-1.414 1.414l5.657 5.657a1 1 0 0 0 1.414 0l12.067-12.067a1 1 0 0 0 0-1.414z"/></svg>') no-repeat center center;
background-size: contain;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;700&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="./manifest.json" />
<link rel="apple-touch-icon" href="./assets/icon.png" />
<meta name="apple-mobile-web-app-status-bar" content="#151515" />
<meta name="theme-color" content="#2c4961" />
</head>
<body>
<!--Everything is only in the HTML webpage so that it can be easily downloaded and used offline even without PWA-->
<div style="display: flex; align-items: center;">
<img width="72" height="72" id="icon" style="margin-right: 10px;">
<h1>Check Duplicate</h1>
</div>
<i>Check if a file is a duplicate or not by getting their SHA256 hash, with everything done locally.</i><br><br>
<button id="filePicker">Choose files</button><br><br>
<div style="display: flex; align-items: center;">
<input type="checkbox" checked id="incremental"><label for="incremental">Use a stream instead of ArrayBuffer
(suggested
for
big files)</label>
</div><br>
<div style="display: flex; align-items: center;">
<input type="checkbox" id="directory"><label for="directory">Select a directory instead of single files</label>
</div>
<br><br>
<progress value="0" max="1" id="progress"></progress>
<h3 style="text-align: center;">Unique files: <span id="update">0</span></h3>
<div class="secondContainer">
<h2 style="margin-left: 4px;">File hash:</h2>
<div style="overflow: auto; border-radius: 8px;">
<table style="width: 100%; border-collapse: separate; border-spacing: 4px;">
<tbody id="addHash">
<tr>
<th>Name:</th>
<th>Hash:</th>
</tr>
</tbody>
</table>
</div>
<br>
<div style="display: flex;">
<button id="export" style="margin-right: 5px;">Export as a CSV table</button>
<button id="compare" style="margin-left: 5px;">Compare from a previous CSV table</button>
</div><br>
<a download="FileHash.csv" id="downloadCsv" style="display: none;">Retry download</a>
</div><br><br>
<div class="marginChild">
<a id="htmlDownload" download="CheckDuplicate.html">Download webpage as HTML</a><a id="changeTheme">Change
theme</a><a href="https://github.com/Dinoosauro/check-duplicate">View on GitHub</a>
</div><br>
<i>Icon generated with Bing Image Creator, powered by DALL-E 3. Generating SHA256 from a Stream is also possible
thanks to the <a href="https://github.com/emn178/js-sha256?tab=MIT-1-ov-file#readme" target="_blank">js-sha256
library.</a></i>
<script src="https://cdn.jsdelivr.net/npm/js-sha256@0.11.0/src/sha256.min.js"></script>
<script>
if ('serviceWorker' in navigator) {
let registration;
const registerServiceWorker = async () => {
registration = await navigator.serviceWorker.register('./service-worker.js', { scope: window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1) });
};
registerServiceWorker();
}
let finalArr = [];
document.getElementById("filePicker").addEventListener("click", () => {
let file = document.createElement("input");
file.type = "file";
file.multiple = true;
file.webkitdirectory = document.getElementById("directory").checked;
file.onchange = async () => {
document.getElementById("progress").value = 0;
document.getElementById("progress").max = file.files.length;
for (let item of file.files) {
document.title = `[${document.getElementById("progress").value}/${document.getElementById("progress").max}] – Check Duplicate`;
let hashHex = "";
if ((window.sha256 ?? "") !== "" && document.getElementById("incremental").checked) {
hashHex = await new Promise((resolve) => {
let hash = sha256.create();
let reader = item.stream().getReader();
function read() {
reader.read().then(({ done, value }) => {
if (!done) {
hash.update(value);
read();
} else {
resolve(hash.digest('hex'));
}
});
}
read();
})
} else {
hashHex = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", await item.arrayBuffer())));
}
hashHex = hashHex.map((b) => b.toString(16).padStart(2, "0")).join("");
document.getElementById("progress").value++;
finalArr.push(hashHex);
let container = document.createElement("tr");
let nameDom = document.createElement("td");
let nameUrl = document.createElement("a");
nameUrl.textContent = (item.webkitRelativePath ?? "") !== "" ? item.webkitRelativePath : item.name;
nameUrl.addEventListener("click", async () => {
if (nameUrl.download !== "") return;
nameUrl.download = item.name;
nameUrl.href = URL.createObjectURL(new Blob([await item.arrayBuffer()]));
nameUrl.click();
})
nameDom.append(nameUrl);
let hashDom = document.createElement("td");
let hashContent = document.createElement("l");
hashContent.textContent = hashHex;
hashDom.append(hashContent);
container.append(nameDom, hashDom);
document.getElementById("addHash").append(container);
document.getElementById("update").textContent = Array.from(new Set(finalArr)).length
}
document.title = `Check Duplicate`;
}
file.click();
});
document.getElementById("export").addEventListener("click", () => {
let finalStr = "";
for (let item of document.querySelectorAll("tr")) {
for (let cell of item.querySelectorAll("th, td > a, td > l")) finalStr += `"${cell.textContent.replaceAll(`"`, `""`)}",`;
finalStr = `${finalStr.substring(0, finalStr.length - 1)}\n`;
}
document.getElementById("downloadCsv").href = URL.createObjectURL(new Blob([finalStr]));
document.getElementById("downloadCsv").click();
document.getElementById("downloadCsv").style.display = "";
});
document.getElementById("compare").addEventListener("click", () => {
let input = document.createElement("input");
input.type = "file";
input.onchange = async () => {
let text = (await input.files[0].text()).split("\n").map(text => {
function fixQuotation(newText) {
if (newText.startsWith("\"")) newText = newText.substring(1);
if (newText.endsWith("\"")) newText = newText.substring(0, newText.lastIndexOf("\""));
newText = newText.replaceAll(`""`, `"`);
return newText;
}
const splitText = text.split(",");
return splitText.length > 1 ? [fixQuotation(splitText[0]), fixQuotation(splitText[1])] : [null, null];
});
const availableRows = Array.from(document.querySelectorAll("tr"));
let addedHash = false;
for (let i = 1; i < text.length; i++) {
const rowIndex = availableRows.findIndex(e => e.querySelector("a")?.textContent === text[i][0]);
if (rowIndex !== -1) {
if (!addedHash) {
let cell = document.createElement("th");
cell.textContent = input.files[0].name;
document.getElementById("addHash").querySelector("tr").append(cell);
addedHash = true;
}
let cell = document.createElement("td");
let l = document.createElement("l");
l.textContent = text[i][1];
let rowContent = Array.from(availableRows[rowIndex].querySelectorAll("l"));
rowContent.push(l);
availableRows[rowIndex].style.setProperty("--table", `var(${rowContent.every(item => item.textContent === rowContent[0].textContent) ? "--same" : "--different"})`)
cell.append(l);
availableRows[rowIndex].append(cell);
}
};
}
input.click();
})
let theme = {
isDark: true,
dark: {
background: "#151515",
text: "#f0f0f0",
second: "#303030",
table: "#515151",
accent: "#2c4961",
hover: "150%",
active: "175%",
different: "#572018",
same: "#214a27"
}, light: {
background: "#f0f0f0",
text: "#151515",
second: "#d2d2d2",
table: "#afafaf",
accent: "#80aacc",
hover: "50%",
active: "25%",
different: "#e37b6d",
same: "#a0dea9"
}
}
let icon = `<svg stroke-miterlimit="10" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round" viewBox="0 0 1024 1024" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:vectornator="http://vectornator.io"><g vectornator:layerName="Senza Titolo"><g vectornator:layerName="g" fill="#212121" stroke="#303030" stroke-linecap="butt" stroke-width="5"><path d="M492.003 78.344C443.712 82.05 409.4 88.828 368.098 102.7c-72.648 24.252-137.777 67.142-187.339 123.269-29.123 33.042-47.55 59.941-65.024 94.888-54.75 109.608-60.363 238.702-15.355 352.546 22.345 56.445 54.115 103.677 99.971 148.262 24.357 23.722 45.855 40.242 76.037 58.563 66.4 40.243 140.743 61.952 224.087 65.447 56.657 2.33 132.695-11.755 187.446-34.735 79.637-33.359 148.367-89.593 195.07-159.7 38.548-57.822 60.787-119.562 69.365-193.27 2.118-18.215 1.801-74.66-.635-93.193-6.778-53.268-20.545-98.806-43.949-145.085-22.451-44.267-49.456-80.909-86.204-116.703-33.253-32.3-62.376-52.951-105.583-74.873-25.311-12.814-38.337-18.32-63.012-26.687-32.935-11.013-62.482-17.58-95.417-21.074-14.403-1.588-55.175-2.86-65.553-2.012Zm54.539 48.185c58.458 5.295 119.563 25.628 171.349 56.763 65.023 39.184 117.021 95.947 150.062 163.935 35.477 73.072 46.703 150.275 33.253 230.336-23.722 140.743-122.74 254.587-261.47 300.76-85.357 28.381-174.102 27.852-259.353-1.483-46.914-16.203-95.841-44.267-131.424-75.402-28.805-25.204-45.961-44.69-67.247-76.672-30.605-45.855-51.892-101.348-59.728-155.675-11.438-78.579.423-153.981 35.053-223.452 22.451-45.114 50.091-81.862 89.275-118.398 35.477-33.041 85.145-62.27 135.342-79.532 55.174-18.956 110.984-26.157 164.888-21.18Z" vectornator:layerName="path"/><path d="M324.361 239.738c-5.083 1.164-10.378 5.295-13.132 10.06l-2.435 4.236-.53 99.442-.529 99.441-6.566 1.377c-16.839 3.389-33.041 17.05-39.925 33.782-4.871 11.544-4.871 11.649-4.871 121.363 0 90.546.211 104.843 1.694 111.832 4.236 20.545 17.05 37.595 34.841 46.279 15.144 7.519-1.27 6.99 218.581 6.99 220.91 0 204.496.529 220.275-7.308 9.849-4.765 21.498-15.461 26.899-24.569 2.224-3.706 5.295-10.59 6.883-15.25l2.86-8.472.317-105.583c.318-117.551.53-114.056-6.777-128.988-7.307-14.826-24.781-28.488-39.184-30.5l-5.189-.741-.529-61.952-.53-61.953-3.283-6.354c-3.812-7.201-8.154-11.755-48.079-51.044-16.733-16.415-29.97-28.594-32.83-30.076l-4.765-2.542-149.851-.212c-82.391 0-151.439.212-153.345.742Zm280.427 64.282c0 18.215.424 32.088 1.165 34.524.635 2.223 2.753 5.93 4.871 8.26 6.037 6.672 9.743 7.307 43.42 7.307h28.911v99.547H341.094V273.626h263.694v30.394Zm49.244 2.647 13.767 14.085-14.72.318c-8.048.106-14.826.106-15.038 0-.106-.212-.424-7.096-.635-15.356-.318-13.132-.106-14.826 1.271-14.085.953.53 7.836 7.202 15.355 15.038Zm62.376 180.986c5.507 1.482 13.661 9.319 16.415 15.779l2.224 5.295-.212 103.572-.318 103.465-3.494 7.096c-3.919 7.942-7.625 11.649-16.097 15.567l-5.825 2.754H316.207l-6.672-3.072c-7.095-3.282-12.39-8.366-16.309-15.673l-2.436-4.554-.317-104.842c-.212-95.311-.106-105.266 1.482-109.502 2.966-7.731 9.214-13.555 17.368-16.097 4.342-1.271 402.214-1.165 407.085.212Z" vectornator:layerName="path"/><path d="M383.878 312.81c-6.248 2.435-7.519 10.696-2.648 16.097l3.071 3.494 78.579.318c53.269.212 79.85-.106 82.709-.847 8.472-2.33 10.59-11.332 4.13-17.262l-3.177-2.86-80.273.106c-44.055 0-81.226.424-82.391.954ZM383.878 360.465c-6.248 2.436-7.519 10.696-2.648 16.097l3.071 3.495 78.579.318c53.269.211 79.85-.106 82.709-.848 2.965-.847 4.872-2.224 6.248-4.553 3.072-4.872 2.648-7.837-1.482-11.967l-3.601-3.601-80.273.106c-44.267 0-81.438.424-82.603.953ZM385.678 408.121c-7.307 1.694-9.849 10.272-4.977 16.414l2.541 3.178 126.447.317c93.511.212 127.081-.106 129.305-.953 6.778-2.859 8.261-11.12 2.754-16.415l-3.177-3.071-124.646-.212c-68.519 0-126.235.318-128.247.742ZM499.416 522.494c-23.298 3.495-44.372 15.356-58.775 33.147-20.757 25.523-25.205 65.447-10.59 95.523 15.25 31.665 46.596 51.363 81.65 51.363 36.642 0 68.73-20.439 83.45-53.163 12.602-28.276 10.061-62.27-6.566-87.369-19.38-29.122-54.433-44.69-89.169-39.501Zm59.517 49.456c4.871 2.224 7.731 7.096 7.731 12.814 0 5.189 0 5.189-24.887 30.923-33.783 34.842-30.288 31.771-35.583 31.771-2.542-.106-5.719-.636-6.99-1.377-4.342-2.436-42.254-40.666-43.737-44.055-3.601-8.79 5.931-18.956 15.568-16.52 1.588.317 9.107 6.883 17.791 15.461l15.038 14.72 11.014-11.331a12022.42 12022.42 0 0 0 20.439-21.18c12.496-13.026 16.203-14.721 23.616-11.226Z" vectornator:layerName="path"/></g></g></svg>`;
document.getElementById("changeTheme").addEventListener("click", () => {
theme.isDark = !theme.isDark;
for (let item in theme.dark) document.documentElement.style.setProperty(`--${item}`, theme[theme.isDark ? "dark" : "light"][item]);
localStorage.setItem("CheckDuplicate-Theme", theme.isDark ? "b" : "a");
changeIcon();
})
function changeIcon() {
document.getElementById("icon").src = URL.createObjectURL(new Blob([icon.replace("#212121", getComputedStyle(document.body).getPropertyValue("--accent")).replace("#303030", getComputedStyle(document.body).getPropertyValue("--text"))], { type: "image/svg+xml" }));
}
changeIcon();
if (localStorage.getItem("CheckDuplicate-Theme") === "a") document.getElementById("changeTheme").click();
document.getElementById("htmlDownload").href = URL.createObjectURL(new Blob([document.documentElement.outerHTML]));
let appVersion = "1.2.0"
fetch("./update.txt", { cache: "no-store" }).then((res) => res.text().then((text) => { if (text.replace("\n", "") !== appVersion) if (confirm(`There's a new version of Check Duplicate. Do you want to update? [${appVersion} --> ${text.replace("\n", "")}]`)) { caches.delete("checkduplicate-cache"); location.reload(true); } }).catch((e) => { console.error(e) })).catch((e) => console.error(e));
</script>
</body>