-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
61 lines (46 loc) · 1.72 KB
/
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
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
function generate(){
let arr = ''
document.querySelector('input[type="text"]').value= "passsword"
if(document.getElementById('upperCB').checked){
arr+= 'QWERTYUIOPASDFGHJKLZXCVBNNM'
}
if(document.getElementById('lowerCB').checked){
arr+= 'qwertyuiopasdfghjklzxcvbnm'
}
if(document.getElementById('numberCB').checked){
arr+= '0123456789'
}
if(document.getElementById('specialCB').checked){
arr+= '!@#$%^&*()'
}
const length = document.querySelector('input[type="range"]').value;
console.log(length)
if(length<1 || arr.length===0){
return
}
let password = ''
for(let i=0;i<length;i++){
const position = Math.floor(Math.random()*arr.length)
password +=arr[position]
}
console.log(arr)
console.log(password)
document.querySelector('input[type="text"]').value = password;
[...document.querySelectorAll('input[type="checkbox"],button.generate')].forEach(element => {
element.addEventListener('click',generate);
})
document.querySelector('input[type="range"]').addEventListener('input',()=>{
document.querySelector('div.range-main span').innerHTML = document.querySelector('input[type="range"]').value
generate();
})
document.querySelector('div.input-main button').addEventListener('click',()=>{
const pass = document.querySelector('input[type="text"]').value
navigator.clipboard.writeText(pass).then(()=>{
document.querySelector('div.input-main button').innerHTML = "Copied!"
setTimeout(()=>{
document.querySelector('div.input-main button').innerHTML = "Copy"
},1000)
})
})
}
generate()