-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (75 loc) · 2.37 KB
/
main.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
const copyBtn = document.getElementById("pg-btn");
const P_lengthEl = document.getElementById("length");
const upperEl = document.getElementById("upper");
const lowerEl = document.getElementById("lower");
const numberEl = document.getElementById("number");
const symbolEl = document.getElementById("symbol");
const passwordTxt = document.getElementById("password_txt");
const generatorBtn = document.getElementById("generator");
copyBtn.addEventListener("click", function() {
// CREATE TEXTAREA AND SET VALUE passwordTxt HTML
const textarea = document.createElement("textarea");
// if (!passwordTxt) {
// return;
// }
textarea.value = passwordTxt.innerHTML;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
// COPY POPUP ALERT
const copyBox = document.createElement("div");
copyBox.classList.add("copyBox");
document.body.appendChild(copyBox);
copyBox.innerHTML = "COPY SUCCESSFULLY"
setInterval(() => {
copyBox.remove();
}, 2000);
})
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
const numbers = "123456789";
const symbol = "!@#$%^&*()_+=~<>";
function getUpperCase() {
return upperCase[Math.floor(Math.random() * upperCase.length)];
}
function getLowerCase() {
return lowerCase[Math.floor(Math.random() * lowerCase.length)];
}
function getNumbers() {
return numbers[Math.floor(Math.random() * numbers.length)];
}
function getSymbol() {
return symbol[Math.floor(Math.random() * symbol.length)];
}
// console.log(getSymbol());
function generatePassword() {
const lent = P_lengthEl.value;
password = "";
for (a = 0; a < lent; a++) {
const x = getPasswordValue();
password += x;
}
passwordTxt.innerHTML = password;
}
function getPasswordValue() {
let valueArray = [];
if (upperEl.checked) {
valueArray.push(getUpperCase())
}
if (lowerEl.checked) {
valueArray.push(getLowerCase())
}
if (numberEl.checked) {
valueArray.push(getNumbers())
}
if (symbolEl.checked) {
valueArray.push(getSymbol())
}
if (valueArray.length === 0) {
return "12"
} else {
return valueArray[Math.floor(Math.random() * valueArray.length)];
}
}
generatorBtn.addEventListener("click", generatePassword);