-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
101 lines (81 loc) · 3.18 KB
/
Copy pathscript.js
File metadata and controls
101 lines (81 loc) · 3.18 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
// ---------- SLIDER ----------
const lengthSlider = document.getElementById("length");
const lengthValue = document.getElementById("lengthValue");
function updateLengthValue() {
lengthValue.textContent = lengthSlider.value;
}
updateLengthValue();
lengthSlider.addEventListener("input", updateLengthValue);
// ---------- PASSWORD STRENGTH ----------
const passwordInput = document.getElementById("passwordInput");
const strengthText = document.getElementById("strengthText");
const strengthBar = document.getElementById("strengthBar");
passwordInput.addEventListener("input", () => {
const pwd = passwordInput.value;
let score = 0;
if (pwd.length >= 8) score++;
if (/[A-Z]/.test(pwd)) score++;
if (/[a-z]/.test(pwd)) score++;
if (/[0-9]/.test(pwd)) score++;
if (/[^A-Za-z0-9]/.test(pwd)) score++;
const levels = ["Very Weak", "Weak", "Medium", "Strong", "Very Strong"];
const colors = ["red", "orange", "yellow", "lightgreen", "green"];
strengthText.textContent = pwd ? levels[score - 1] || "Very Weak" : "";
strengthBar.style.width = score * 20 + "%";
strengthBar.style.background = colors[score - 1] || "red";
});
// ---------- PASSWORD GENERATOR ----------
function generate() {
const length = parseInt(lengthSlider.value);
const upper = document.getElementById("upper").checked;
const lower = document.getElementById("lower").checked;
const number = document.getElementById("number").checked;
const symbol = document.getElementById("symbol").checked;
let chars = "";
if (upper) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (lower) chars += "abcdefghijklmnopqrstuvwxyz";
if (number) chars += "0123456789";
if (symbol) chars += "!@#$%^&*()_+";
if (!chars) {
alert("Select at least one option!");
return;
}
let password = "";
for (let i = 0; i < length; i++) {
password += chars[Math.floor(Math.random() * chars.length)];
}
document.getElementById("generatedPassword").value = password;
// ✅ ALWAYS RESET COPY BUTTON TO NORMAL
const copyBtn = document.getElementById("copyBtn");
copyBtn.innerHTML = "📋 Copy";
copyBtn.style.background = "#3b82f6";
copyBtn.style.display = "block";
}
// ---------- COPY PASSWORD ----------
// ---------- COPY PASSWORD ----------
function copyPassword() {
const passwordField = document.getElementById("generatedPassword");
const copyBtn = document.getElementById("copyBtn");
if (passwordField.value) {
navigator.clipboard.writeText(passwordField.value).then(() => {
// Save original text BEFORE changing
const originalText = "📋 Copy";
copyBtn.innerHTML = "✅ Copied!";
copyBtn.style.background = "#22c55e";
// RESET after 2 seconds
setTimeout(() => {
copyBtn.innerHTML = originalText;
copyBtn.style.background = "#3b82f6";
}, 2000);
});
}
}
// Show/hide copy button when password changes
document.getElementById("generatedPassword").addEventListener("input", function() {
const copyBtn = document.getElementById("copyBtn");
copyBtn.style.display = this.value ? "block" : "none";
});
// ---------- PWA ---------- (DISABLED FOR ANDROID APP)
// if ("serviceWorker" in navigator) {
// navigator.serviceWorker.register("sw.js");
// }