-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (54 loc) · 1.96 KB
/
Copy pathscript.js
File metadata and controls
68 lines (54 loc) · 1.96 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
function generatePassword() {
const length = parseInt(document.getElementById("length").value) || 12;
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=";
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
document.getElementById("password").value = password;
const btn = document.querySelector('.generate-btn i');
btn.style.animation = 'none';
setTimeout(() => {
btn.style.animation = 'rotate 2s linear infinite';
}, 10);
}
function copyPassword() {
const passwordField = document.getElementById("password");
if (!passwordField.value) {
return;
}
passwordField.select();
passwordField.setSelectionRange(0, 99999);
navigator.clipboard.writeText(passwordField.value).then(() => {
showNotification();
const copyIcon = document.querySelector('.copy-icon');
copyIcon.classList.add('copied');
setTimeout(() => {
copyIcon.classList.remove('copied');
}, 500);
});
}
function showNotification() {
const notification = document.getElementById('notification');
notification.classList.add('show');
setTimeout(() => {
notification.classList.remove('show');
}, 2000);
}
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
const icon = document.querySelector('.dark-mode-toggle i');
if (document.body.classList.contains('dark-mode')) {
icon.className = 'fas fa-sun';
localStorage.setItem('darkMode', 'enabled');
} else {
icon.className = 'fas fa-moon';
localStorage.setItem('darkMode', 'disabled');
}
}
if (localStorage.getItem('darkMode') === 'enabled') {
document.body.classList.add('dark-mode');
document.querySelector('.dark-mode-toggle i').className = 'fas fa-sun';
}
generatePassword();