-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (32 loc) · 1.15 KB
/
script.js
File metadata and controls
45 lines (32 loc) · 1.15 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
const btnE1 = document.querySelector(".btn");
const inputE1 = document.getElementById("input");
const copyIconE1 = document.querySelector(".fa-copy");
const alertContainerE1 = document.querySelector(".alert-container");
btnE1.addEventListener("click",()=>{
createPassword();
});
copyIconE1.addEventListener("click",()=>{
copypassword();
if(inputE1.value){
alertContainerE1.classList.remove("active");
setTimeout(() => {
alertContainerE1.classList.add("active");
}, 2000);
}
});
function createPassword(){
const chars = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+?:{}[]ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let password = "";
let passwordLength = 12;
for(let i=0; i<passwordLength; i++){
const randomNumber = Math.floor(Math.random() * chars.length);
password += chars.substring(randomNumber, randomNumber + 1);
}
inputE1.value = password;
alertContainerE1.innerText = password + " is copied";
}
function copypassword(){
inputE1.select();
inputE1.setSelectionRange(0, 9999);
navigator.clipboard.writeText(inputE1.value);
}