-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
116 lines (100 loc) · 4.12 KB
/
script.js
File metadata and controls
116 lines (100 loc) · 4.12 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
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
const copyBtn = document.querySelector('.copy__icon');
const copyValue = document.querySelector('.output__text');
const output = document.querySelector('.output');
const outputText = document.querySelector('.output__text');
const rangeInput = document.getElementById('range');
const rangeCount = document.querySelector('.main__length-count');
const checkboxes = document.querySelectorAll('.checkbox__input');
const generateBtn = document.querySelector('.generate__btn');
const checkbox1 = document.getElementById('checkbox-1');
const checkbox2 = document.getElementById('checkbox-2');
const checkbox3 = document.getElementById('checkbox-3');
const checkbox4 = document.getElementById('checkbox-4');
const indicator1 = document.querySelector('.indicator-1');
const indicator2 = document.querySelector('.indicator-2');
const indicator3 = document.querySelector('.indicator-3');
const indicator4 = document.querySelector('.indicator-4');
copyBtn.addEventListener('click', () => {
navigator.clipboard.writeText(copyValue.textContent)
.then( () => {
output.classList.add('activeOutput');
setTimeout(() => output.classList.remove('activeOutput'), 1000);
})
});
checkboxes.forEach(item => {
item.addEventListener('click', () => {
item.classList.toggle('activeInput');
});
});
function changeRangeCount() {
rangeCount.textContent = rangeInput.value;
}
rangeInput.addEventListener('mousemove', changeRangeCount);
rangeInput.addEventListener('touchmove', changeRangeCount);
generateBtn.addEventListener('click', () => {
if(+rangeCount.textContent >= 6 && (checkbox1.classList.contains('activeInput') ||
checkbox2.classList.contains('activeInput') ||
checkbox3.classList.contains('activeInput') ||
checkbox4.classList.contains('activeInput')))
{
outputText.classList.add('activeText');
outputText.textContent = generatePassword(
+rangeCount.textContent,
checkbox1.classList.contains('activeInput'),
checkbox2.classList.contains('activeInput'),
checkbox3.classList.contains('activeInput'),
checkbox4.classList.contains('activeInput')
);
let checks = 0;
checkboxes.forEach(item => {
if (item.classList.contains('activeInput')) {
checks++;
}
})
if (checks === 1) {
indicator1.style.background = '#FF192DFF';
indicator2.style.background = '';
indicator3.style.background = '';
indicator4.style.background = '';
} else if (checks === 2) {
indicator1.style.background = '#FFCC2CFF';
indicator2.style.background = '#FFCC2CFF';
indicator3.style.background = '';
indicator4.style.background = '';
} else if (checks === 3) {
indicator1.style.background = '#FFCC2CFF';
indicator2.style.background = '#FFCC2CFF';
indicator3.style.background = '#FFCC2CFF';
indicator4.style.background = '';
} else if (checks === 4) {
indicator1.style.background = '#a4ffaf';
indicator2.style.background = '#a4ffaf';
indicator3.style.background = '#a4ffaf';
indicator4.style.background = '#a4ffaf';
}
}
});
function generatePassword(length, useLowercase, useUppercase, useNumbers, useSymbols) {
let password = "",
charset = "";
const lowercaseCharset = "abcdefghijklmnopqrstuvwxyz";
const uppercaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numbersCharset = "0123456789";
const symbolsCharset = "!@#$%^&*()-_=+[]{}|;:,.<>/?";
if (useLowercase) {
charset += lowercaseCharset;
}
if (useUppercase) {
charset += uppercaseCharset;
}
if (useNumbers) {
charset += numbersCharset;
}
if (useSymbols) {
charset += symbolsCharset;
}
for (let i = 0; i < length; i++) {
password += charset.charAt(Math.floor(Math.random() * charset.length));
}
return password;
}