-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathhash-generator.html
More file actions
775 lines (676 loc) · 24.2 KB
/
Copy pathhash-generator.html
File metadata and controls
775 lines (676 loc) · 24.2 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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
<!--
Hash Generator
Single-file client-side tool to generate MD5, SHA-1, SHA-256, SHA-384, and
SHA-512 hashes for text or files, entirely offline.
Built for One File Tools.
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hash Generator - One File Tools</title>
<meta name="description" content="Generate SHA-1, SHA-256 and SHA-512 hashes instantly in your browser." />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet" />
<style>
:root {
--bg: #030712;
--grid-line: #111827;
--panel: rgba(17, 24, 39, 0.7);
--panel-border: #1f2937;
--accent: #f59e0b;
--accent-hover: #d97706;
--accent-glow: rgba(245, 158, 11, 0.15);
--text: #f9fafb;
--text-muted: #9ca3af;
--text-dim: #4b5563;
--radius-sm: 12px;
--radius-md: 20px;
--font-sans: "Inter", system-ui, sans-serif;
--font-mono: "JetBrains Mono", monospace;
--font-display: "Space Grotesk", sans-serif;
--color-weak: #ef4444;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: var(--font-sans);
background-color: var(--bg);
background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
background-size: 32px 32px;
color: var(--text);
padding: 48px 20px 80px;
min-height: 100vh;
display: flex;
justify-content: center;
}
.app {
width: 100%;
max-width: 860px;
}
.hero {
text-align: center;
margin-bottom: 28px;
}
.eyebrow {
font-family: var(--font-mono);
font-size: 12px;
letter-spacing: 0.2em;
color: var(--accent);
text-transform: uppercase;
margin-bottom: 12px;
font-weight: 500;
}
.wordmark {
font-family: var(--font-display);
font-weight: 700;
font-size: clamp(26px, 5vw, 38px);
letter-spacing: -0.02em;
margin-bottom: 12px;
}
.tagline {
color: var(--text-muted);
font-size: 15px;
line-height: 1.5;
max-width: 580px;
margin: 0 auto;
}
.studio {
background: var(--panel);
backdrop-filter: blur(20px);
border: 1px solid var(--panel-border);
border-radius: var(--radius-md);
padding: 24px;
box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.5);
margin-bottom: 24px;
}
.mode-tabs {
display: flex;
gap: 6px;
margin-bottom: 18px;
}
.mode-tab {
flex: 1;
background: rgba(31, 41, 55, 0.5);
border: 1px solid var(--panel-border);
color: var(--text-muted);
border-radius: 8px;
padding: 10px 14px;
font-family: var(--font-sans);
font-size: 14px;
font-weight: 600;
cursor: pointer;
}
.mode-tab.active {
background: var(--accent);
color: #030712;
border-color: var(--accent);
}
.mode-tab:hover:not(.active) {
background: rgba(55, 65, 81, 0.7);
}
.mode-tab:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.section-label {
font-family: var(--font-mono);
font-size: 12px;
font-weight: 600;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.1em;
display: block;
margin-bottom: 14px;
}
textarea {
width: 100%;
background: rgba(17, 24, 39, 0.8);
border: 1px solid var(--panel-border);
border-radius: 8px;
color: var(--text);
font-family: var(--font-mono);
font-size: 14px;
padding: 12px 14px;
resize: vertical;
min-height: 140px;
line-height: 1.6;
}
textarea:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-glow);
}
.dropzone {
border: 2px dashed var(--panel-border);
border-radius: var(--radius-sm);
padding: 30px;
text-align: center;
cursor: pointer;
transition: all 0.2s;
background: rgba(3, 7, 18, 0.4);
}
.dropzone:hover,
.dropzone.dragover {
border-color: var(--accent);
background: rgba(245, 158, 11, 0.05);
}
.dropzone:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.dropzone p {
color: var(--text-muted);
font-size: 14px;
}
.dropzone .hint {
color: var(--text-dim);
font-size: 12px;
margin-top: 6px;
}
.file-meta {
margin-top: 14px;
display: none;
}
.file-meta.visible {
display: block;
}
.file-meta-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 10px;
}
.info-card {
background: rgba(3, 7, 18, 0.5);
border: 1px solid var(--panel-border);
border-radius: var(--radius-sm);
padding: 10px 12px;
}
.info-card .label {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 3px;
}
.info-card .value {
font-family: var(--font-mono);
font-size: 13px;
color: var(--text);
word-break: break-word;
}
.actions {
display: flex;
gap: 10px;
margin-top: 14px;
flex-wrap: wrap;
}
.btn-ghost {
background: rgba(31, 41, 55, 0.6);
border: 1px solid var(--panel-border);
color: var(--text);
border-radius: 8px;
padding: 10px 16px;
font-family: var(--font-sans);
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.btn-ghost:hover {
background: rgba(55, 65, 81, 0.8);
}
.btn-ghost:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.hash-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.hash-row {
background: rgba(3, 7, 18, 0.5);
border: 1px solid var(--panel-border);
border-radius: var(--radius-sm);
padding: 12px 14px;
}
.hash-row .algo-name {
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 6px;
}
.hash-value-row {
display: flex;
gap: 8px;
align-items: center;
}
.hash-value {
flex: 1;
font-family: var(--font-mono);
font-size: 13px;
color: var(--accent);
word-break: break-all;
min-height: 18px;
}
.hash-value.empty {
color: var(--text-dim);
}
.copy-btn-sm {
background: rgba(31, 41, 55, 0.6);
border: 1px solid var(--panel-border);
color: var(--text-muted);
border-radius: 6px;
padding: 6px 10px;
font-size: 11px;
font-family: var(--font-sans);
cursor: pointer;
flex-shrink: 0;
}
.copy-btn-sm:hover {
background: rgba(55, 65, 81, 0.9);
color: var(--text);
}
.copy-btn-sm:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.progress-note {
font-family: var(--font-mono);
font-size: 12px;
color: var(--text-dim);
margin-top: 10px;
}
.footer-note {
text-align: center;
color: var(--text-dim);
font-size: 13px;
margin-top: 8px;
}
.footer-note a {
color: var(--text-muted);
}
.toast {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: var(--text);
color: var(--bg);
padding: 12px 22px;
border-radius: 99px;
font-family: var(--font-sans);
font-weight: 600;
font-size: 14px;
opacity: 0;
transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
z-index: 100;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.toast.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
@media (max-width: 640px) {
.studio {
padding: 18px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="hero">
<div class="eyebrow">Developer Utilities</div>
<h1 class="wordmark">Hash Generator</h1>
<p class="tagline">Generate MD5, SHA-1, SHA-256, SHA-384, and SHA-512 hashes for text or files — entirely offline, nothing ever leaves your browser.</p>
</header>
<main class="studio">
<div class="mode-tabs" role="tablist">
<button class="mode-tab active" id="tabText" type="button" role="tab" aria-selected="true">Text</button>
<button class="mode-tab" id="tabFile" type="button" role="tab" aria-selected="false">File</button>
</div>
<div id="textPanel">
<label class="section-label" for="textInput">Text to hash</label>
<textarea id="textInput" spellcheck="false" placeholder="Type or paste text…"></textarea>
</div>
<div id="filePanel" style="display: none">
<div class="dropzone" id="dropzone" tabindex="0" role="button" aria-label="Upload a file, or press Enter to browse">
<p>Click, press Enter, or drag a file here</p>
<p class="hint">Stays on your device — never uploaded</p>
</div>
<input type="file" id="fileInput" style="position: absolute; width: 1px; height: 1px; opacity: 0" />
<div class="file-meta" id="fileMeta">
<div class="file-meta-grid">
<div class="info-card">
<div class="label">Name</div>
<div class="value" id="fileName">—</div>
</div>
<div class="info-card">
<div class="label">Size</div>
<div class="value" id="fileSize">—</div>
</div>
<div class="info-card">
<div class="label">Type</div>
<div class="value" id="fileType">—</div>
</div>
</div>
</div>
<div class="progress-note" id="progressNote"></div>
</div>
<div class="actions">
<button class="btn-ghost" id="btnClear" type="button">Clear</button>
</div>
</main>
<main class="studio">
<span class="section-label">Hashes</span>
<div class="hash-list" id="hashList"></div>
</main>
<p class="footer-note">Part of <a href="https://github.com/praveenscience/One-File-Tools">One File Tools</a>. All hashing happens locally using the Web Crypto API (and a bundled MD5 implementation, since MD5 isn't part of that API).</p>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script>
/* ==========================================================
Hash Generator
Vanilla JS. SHA-1/256/384/512 via the native Web Crypto API
(crypto.subtle.digest). MD5 is NOT part of Web Crypto (it's
considered cryptographically broken and was excluded from
the standard), so a small, well-known public-domain MD5
implementation is bundled inline below.
========================================================== */
const tabText = document.getElementById("tabText");
const tabFile = document.getElementById("tabFile");
const textPanel = document.getElementById("textPanel");
const filePanel = document.getElementById("filePanel");
const textInput = document.getElementById("textInput");
const dropzone = document.getElementById("dropzone");
const fileInput = document.getElementById("fileInput");
const fileMeta = document.getElementById("fileMeta");
const fileName = document.getElementById("fileName");
const fileSize = document.getElementById("fileSize");
const fileType = document.getElementById("fileType");
const progressNote = document.getElementById("progressNote");
const btnClear = document.getElementById("btnClear");
const hashList = document.getElementById("hashList");
const toast = document.getElementById("toast");
const ALGORITHMS = [
{ id: "md5", label: "MD5" },
{ id: "sha1", label: "SHA-1", webCryptoName: "SHA-1" },
{ id: "sha256", label: "SHA-256", webCryptoName: "SHA-256" },
{ id: "sha384", label: "SHA-384", webCryptoName: "SHA-384" },
{ id: "sha512", label: "SHA-512", webCryptoName: "SHA-512" }
];
let mode = "text"; // "text" | "file"
let currentFile = null;
let debounceTimer = null;
// ---- MD5 (public-domain implementation, adapted for ArrayBuffer input) ----
// Based on the well-known RSA Data Security MD5 algorithm reference
// implementation approach (as used in numerous public-domain JS ports).
function md5(bytes) {
function toWords(byteArray) {
const words = [];
for (let i = 0; i < byteArray.length; i += 4) {
words[i >> 2] = (byteArray[i] || 0) | ((byteArray[i + 1] || 0) << 8) | ((byteArray[i + 2] || 0) << 16) | ((byteArray[i + 3] || 0) << 24);
}
return words;
}
function rotl(x, c) {
return (x << c) | (x >>> (32 - c));
}
function addUnsigned(a, b) {
return (a + b) | 0;
}
const S = [
[7, 12, 17, 22],
[5, 9, 14, 20],
[4, 11, 16, 23],
[6, 10, 15, 21]
];
const K = new Int32Array([-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, 718787259, -343485551]);
const inputLenBytes = bytes.length;
// Pad per RFC 1321: append 0x80, then zeros, then 64-bit little-endian
// bit length, to a total length that's a multiple of 64 bytes.
const padded = new Uint8Array(((inputLenBytes + 8) >> 6) * 64 + 64);
padded.set(bytes);
padded[inputLenBytes] = 0x80;
const bitLen = inputLenBytes * 8;
const dv = new DataView(padded.buffer);
dv.setUint32(padded.length - 8, bitLen >>> 0, true);
dv.setUint32(padded.length - 4, Math.floor(bitLen / 4294967296), true);
const words = toWords(padded);
let a0 = 1732584193,
b0 = -271733879,
c0 = -1732584194,
d0 = 271733878;
function F(x, y, z) {
return (x & y) | (~x & z);
}
function G(x, y, z) {
return (x & z) | (y & ~z);
}
function H(x, y, z) {
return x ^ y ^ z;
}
function I(x, y, z) {
return y ^ (x | ~z);
}
for (let chunkStart = 0; chunkStart < words.length; chunkStart += 16) {
let a = a0,
b = b0,
c = c0,
d = d0;
for (let i = 0; i < 64; i++) {
let f, g;
if (i < 16) {
f = F(b, c, d);
g = i;
} else if (i < 32) {
f = G(b, c, d);
g = (5 * i + 1) % 16;
} else if (i < 48) {
f = H(b, c, d);
g = (3 * i + 5) % 16;
} else {
f = I(b, c, d);
g = (7 * i) % 16;
}
f = addUnsigned(f, addUnsigned(a, addUnsigned(K[i], words[chunkStart + g] || 0)));
a = d;
d = c;
c = b;
b = addUnsigned(b, rotl(f, S[Math.floor(i / 16)][i % 4]));
}
a0 = addUnsigned(a0, a);
b0 = addUnsigned(b0, b);
c0 = addUnsigned(c0, c);
d0 = addUnsigned(d0, d);
}
function toHexLE(n) {
let hex = "";
for (let i = 0; i < 4; i++) {
hex += ((n >> (i * 8)) & 0xff).toString(16).padStart(2, "0");
}
return hex;
}
return toHexLE(a0) + toHexLE(b0) + toHexLE(c0) + toHexLE(d0);
}
// ---- Helpers ----
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
setTimeout(() => toast.classList.remove("show"), 1800);
}
function bufferToHex(buffer) {
return Array.from(new Uint8Array(buffer))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}
function formatBytes(bytes) {
if (bytes < 1024) return bytes + " B";
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB";
return (bytes / (1024 * 1024)).toFixed(2) + " MB";
}
/** Builds the hash rows UI once; values are updated via updateHashValue(). */
function renderHashRows() {
hashList.innerHTML = "";
ALGORITHMS.forEach((algo) => {
const row = document.createElement("div");
row.className = "hash-row";
const label = document.createElement("div");
label.className = "algo-name";
label.textContent = algo.label;
const valueRow = document.createElement("div");
valueRow.className = "hash-value-row";
const value = document.createElement("div");
value.className = "hash-value empty";
value.id = "hash-" + algo.id;
value.textContent = "—";
const copyBtn = document.createElement("button");
copyBtn.type = "button";
copyBtn.className = "copy-btn-sm";
copyBtn.id = "copy-" + algo.id;
copyBtn.textContent = "Copy";
copyBtn.disabled = true;
copyBtn.addEventListener("click", () => {
const text = value.textContent;
if (!text || value.classList.contains("empty")) return;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard
.writeText(text)
.then(() => showToast(algo.label + " copied!"))
.catch(() => showToast("Copy failed"));
} else {
showToast("Clipboard unavailable");
}
});
valueRow.appendChild(value);
valueRow.appendChild(copyBtn);
row.appendChild(label);
row.appendChild(valueRow);
hashList.appendChild(row);
});
}
/** Sets a single algorithm's displayed hash value (or clears it when hex is null). */
function updateHashValue(algoId, hex) {
const valueEl = document.getElementById("hash-" + algoId);
const copyBtn = document.getElementById("copy-" + algoId);
if (hex) {
valueEl.textContent = hex;
valueEl.classList.remove("empty");
copyBtn.disabled = false;
} else {
valueEl.textContent = "—";
valueEl.classList.add("empty");
copyBtn.disabled = true;
}
}
/** Computes all hashes for the given ArrayBuffer of bytes and updates the UI. */
async function computeAllHashes(buffer) {
if (!buffer || buffer.byteLength === 0) {
ALGORITHMS.forEach((algo) => updateHashValue(algo.id, null));
return;
}
// MD5 runs synchronously on the raw bytes (Web Crypto has no MD5).
updateHashValue("md5", md5(new Uint8Array(buffer)));
// SHA-* run via Web Crypto in parallel.
const shaAlgos = ALGORITHMS.filter((a) => a.webCryptoName);
await Promise.all(
shaAlgos.map(async (algo) => {
const digest = await crypto.subtle.digest(algo.webCryptoName, buffer);
updateHashValue(algo.id, bufferToHex(digest));
})
);
}
/** Debounced trigger for text input, so rapid typing doesn't hash on every keystroke. */
function scheduleTextHash() {
if (debounceTimer) clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
const bytes = new TextEncoder().encode(textInput.value);
computeAllHashes(bytes.buffer);
}, 200);
}
/** Reads a File as an ArrayBuffer and hashes the raw bytes (correct for binary files). */
function hashFile(file) {
currentFile = file;
fileName.textContent = file.name;
fileSize.textContent = formatBytes(file.size);
fileType.textContent = file.type || "unknown";
fileMeta.classList.add("visible");
progressNote.textContent = "Reading and hashing…";
const reader = new FileReader();
reader.onload = async () => {
progressNote.textContent = "";
await computeAllHashes(reader.result);
};
reader.onerror = () => {
progressNote.textContent = "";
showToast("Could not read that file");
};
reader.readAsArrayBuffer(file);
}
// ---- Mode tabs ----
function setMode(nextMode) {
mode = nextMode;
const isText = mode === "text";
tabText.classList.toggle("active", isText);
tabFile.classList.toggle("active", !isText);
tabText.setAttribute("aria-selected", String(isText));
tabFile.setAttribute("aria-selected", String(!isText));
textPanel.style.display = isText ? "block" : "none";
filePanel.style.display = isText ? "none" : "block";
if (isText) {
scheduleTextHash();
} else if (currentFile) {
hashFile(currentFile);
} else {
ALGORITHMS.forEach((algo) => updateHashValue(algo.id, null));
}
}
tabText.addEventListener("click", () => setMode("text"));
tabFile.addEventListener("click", () => setMode("file"));
// ---- Text mode events ----
textInput.addEventListener("input", scheduleTextHash);
// ---- File mode events ----
dropzone.addEventListener("click", () => fileInput.click());
dropzone.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
fileInput.click();
}
});
dropzone.addEventListener("dragover", (event) => {
event.preventDefault();
dropzone.classList.add("dragover");
});
dropzone.addEventListener("dragleave", () => dropzone.classList.remove("dragover"));
dropzone.addEventListener("drop", (event) => {
event.preventDefault();
dropzone.classList.remove("dragover");
if (event.dataTransfer.files.length) hashFile(event.dataTransfer.files[0]);
});
fileInput.addEventListener("change", () => {
if (fileInput.files.length) hashFile(fileInput.files[0]);
});
// ---- Clear ----
btnClear.addEventListener("click", () => {
textInput.value = "";
currentFile = null;
fileInput.value = "";
fileMeta.classList.remove("visible");
progressNote.textContent = "";
ALGORITHMS.forEach((algo) => updateHashValue(algo.id, null));
if (mode === "text") textInput.focus();
});
// ---- Init ----
renderHashRows();
</script>
</body>
</html>