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