-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (28 loc) · 1009 Bytes
/
script.js
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
const pwd = document.getElementById("pwd_txt");
const generate = document.getElementById("generate");
const clipboard = document.getElementById("clipboard");
let pwd_length = document.getElementById("slider");
let copy_text = document.getElementById("copy_text");
let string = "ABCDEFGHIJKLMNOPQRSTUVWXYZacdefghijklnopqrstuvwxyz0123456789";
generate.addEventListener("click", () => {
let password = "";
let checked = document.getElementById("checkbox").checked;
let final_string = string;
if (checked) {
final_string += "@#$%^&*/=+?";
}
for (let i = 0; i < pwd_length.value; i++) {
let pwd = final_string[Math.floor(Math.random() * final_string.length)];
password += pwd;
}
pwd.innerText = password;
final_string = string;
});
clipboard.addEventListener("click", () => {
navigator.clipboard.writeText(pwd.innerText);
copy_text.textContent = "Password Copied!";
copy_text.style.display = "block";
setTimeout(() => {
copy_text.style.display = "none";
}, 2000);
});