-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 1.17 KB
/
Copy pathindex.js
File metadata and controls
39 lines (33 loc) · 1.17 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
const btnEl = document.querySelector('.btn');
const inputIdEl = document.getElementById('input');
const copyIconEl = document.querySelector('.fa-copy');
const alertContainerEl = document.querySelector('.alert-container')
btnEl.addEventListener('click', () => {
createPassword();
});
copyIconEl.addEventListener('click', () => {
copyPassword();
if (inputIdEl.value) {
alertContainerEl.classList.remove('active');
setTimeout(() => {
alertContainerEl.classList.add('active');
}, 2000);
}
});
function createPassword() {
const chars = '0123456789abcdeefghijklmnopqrstuvwxyz!@¬#$%¨^&*()_+?:{}[].,;-~`ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let passwordLength = 14;
let password = '';
for (let i = 0; i < passwordLength; i++) {
const randomNum = Math.floor(Math.random() * chars.length);
password += chars.substring(randomNum, randomNum + 1)
}
inputIdEl.value = password;
alertContainerEl.innerText = '¡ ' + password + ' Copiado!';
};
function copyPassword() {
inputIdEl.select();
/* si quiero usar movil */
inputIdEl.setSelectionRange(0, 9999);
navigator.clipboard.writeText(inputIdEl.value);
};