-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
152 lines (118 loc) · 3.93 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const dark = document.getElementById("darkMode")
const ball = document.getElementById("ball")
const back = document.getElementById("back")
const teste = document.getElementById("teste")
const btnCopy = document.getElementById("copiar")
const result = document.getElementById("pw")
const barra = document.getElementById("barra")
const nivel = document.getElementById("nivel")
const gerar = document.getElementById("gerar")
const titulo = document.getElementById("h1")
const Qnt = document.getElementById("tam")
const uppercase = document.getElementById("Up")
const lowercase = document.getElementById("Dw")
const numbers = document.getElementById("Num")
const simbols = document.getElementById("Sim")
// -----------------------------------------
dark.addEventListener("click", () =>{
ball.classList.toggle("ball_after")
ball.style.transition = ".3s"
back.classList.toggle("todos_after")
dark.classList.toggle("darkMode_after")
})
function desa(){
titulo.style.opacity = "0%";
titulo.style.transition = ".3s";
}
btnCopy.addEventListener("click", function(){
titulo.style.opacity = "100%";
titulo.style.transition = ".3s";
setTimeout(desa, 3000);
})
const getLowercase = () =>{
const charLower = "abcdefghijklmnopqrstuvwxyz";
return charLower[Math.floor(Math.random() * charLower.length)];
}
const getUppercase = () =>{
const charUpper = 'ABCDEFGHIJKLMNOPWRSTUVWXYZ';
return charUpper[Math.floor(Math.random() * charUpper.length)];
}
const getNumbers = () =>{
const charNumbers = '0123456789';
return charNumbers[Math.floor(Math.random() * charNumbers.length)];
}
const getSymbols = () =>{
const charSymbols = "!@#$%&./-";
return charSymbols[Math.floor(Math.random() * charSymbols.length)];
}
const randomChart = {
Upp: getUppercase,
Low: getLowercase,
Nums: getNumbers,
Symb: getSymbols,
};
gerar.addEventListener("click", () =>{
const lengths = Qnt.value;
const Upp = uppercase.checked;
const Low = lowercase.checked;
const Nums = numbers.checked;
const Symb = simbols.checked;
result.value = generatPassoword(
Upp, Symb, Low, Nums, lengths
);
})
function generatPassoword(Upp ,Symb ,Low ,Nums ,lengths){
let geners = '';
let typesCount = Upp + Symb + Low + Nums;
const arraii = [{ Upp }, { Nums }, { Low }, { Symb }].filter(
(items) => {
return Object.values(items)[0]
}
);
for (let i = 0; i < lengths; i++){
arraii.forEach((type) => {
const fumaca = Object.keys(type)[0];
geners += randomChart[fumaca]();
});
}
const finish = geners.slice(0, lengths);
if(finish.length == 0){
nivel.style.opacity = "0"
nivel.style.transition = ".1s"
}
if(finish.length > 0){
nivel.style.opacity = "100%"
}
if(finish.length < 8){
barra.style.width = "0%";
barra.style.width = "33.3%";
barra.style.transition = ".4s";
barra.style.backgroundColor = "#ff0026";
barra.style.boxShadow = "0 0 10px #ff002677";
}
if(finish.length >= 8){
barra.style.width = "0%";
barra.style.width = "66.6%";
barra.style.transition = ".4s";
barra.style.backgroundColor = "#ffbf00";
barra.style.boxShadow = "0 0 10px #ffbf0077";
}
if(finish.length >= 8 && Nums && Symb && Upp && Symb){
barra.style.width = "0%";
barra.style.width = "100%";
barra.style.transition = ".4s";
barra.style.backgroundColor = "#00c700";
barra.style.boxShadow = "0 0 10px #00c70077";
}
if(finish.length >= 14){
barra.style.width = "0%";
barra.style.width = "100%";
barra.style.transition = ".4s";
barra.style.backgroundColor = "#00c700";
barra.style.boxShadow = "0 0 10px #00c70077";
}
return finish;
}
btnCopy.addEventListener("click", () =>{
navigator.clipboard.writeText(result.value);
})