-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (46 loc) · 1.6 KB
/
index.js
File metadata and controls
54 lines (46 loc) · 1.6 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
import init, { generate_passphrase } from "./pkg/passgen.js";
const loadWasm = async () => {
await init({
module_path: "./pkg/passgen_bg.wasm",
});
};
loadWasm();
// Utility: Show toast
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.remove("hidden", "opacity-0");
toast.classList.add("opacity-100");
setTimeout(() => {
toast.classList.add("opacity-0");
setTimeout(() => toast.classList.add("hidden"), 300);
}, 2000);
}
// Copy to clipboard
document.getElementById("copyBtn").addEventListener("click", () => {
const password = document.getElementById("password").value;
if (!password.trim()) return;
navigator.clipboard
.writeText(password)
.then(() => showToast("✅ Password copied!"))
.catch(() => showToast("⚠️ Failed to copy"));
});
// Clear password
document.getElementById("clearBtn").addEventListener("click", () => {
document.getElementById("password").value = "";
showToast("🗑️ Password cleared");
});
document.getElementById("generateBtn").addEventListener("click", () => {
const special_charset = document.getElementById("prefix").value;
const password = generate_passphrase({
num_words: 3,
replace_vowels: document.getElementById("replaceVowels").checked,
uppercase: document.getElementById("uppercase").checked,
special_chars: document.getElementById("symbols").checked,
random_chars: document.getElementById("randomChars").checked,
...(special_charset && {
special_charset
}),
});
document.getElementById("password").value = password;
});