-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (105 loc) · 4.16 KB
/
script.js
File metadata and controls
122 lines (105 loc) · 4.16 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
117
118
119
120
121
122
document.addEventListener('DOMContentLoaded', () => {
const wordBtn = document.getElementById('wordBtn');
const passwordBtn = document.getElementById('passwordBtn');
const numberBtn = document.getElementById('numberBtn');
const output = document.getElementById('output');
const copyBtn = document.getElementById('copyBtn');
const refreshBtn = document.getElementById('refreshBtn');
let currentType = '';
let words = [];
// Загрузка слов из JSON файла
fetch('words.json')
.then(response => response.json())
.then(data => {
words = data.words;
})
.catch(error => console.error('Error loading words:', error));
const generateWord = () => {
return words[Math.floor(Math.random() * words.length)];
};
const generatePassword = () => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()';
let password = '';
for (let i = 0; i < 12; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
};
const generateNumber = () => {
return Math.floor(Math.random() * 100).toString();
};
const updateOutput = (type) => {
currentType = type;
switch (type) {
case 'word':
output.value = generateWord();
break;
case 'password':
output.value = generatePassword();
break;
case 'number':
output.value = generateNumber();
break;
}
};
wordBtn.addEventListener('click', () => updateOutput('word'));
passwordBtn.addEventListener('click', () => updateOutput('password'));
numberBtn.addEventListener('click', () => updateOutput('number'));
copyBtn.addEventListener('click', () => {
if (output.value) {
navigator.clipboard.writeText(output.value).then(() => {
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Скопировано!';
copyBtn.style.backgroundColor = '#4CAF50';
setTimeout(() => {
copyBtn.textContent = originalText;
copyBtn.style.backgroundColor = '';
}, 1500);
});
}
});
refreshBtn.addEventListener('click', () => {
if (currentType) {
updateOutput(currentType);
}
});
output.addEventListener('click', () => {
if (output.value) {
navigator.clipboard.writeText(output.value).then(() => {
alert('Текст скопирован в буфер обмена!');
});
} else {
alert('Сначала выберите тип генерации!');
}
});
// Анимации для кнопок
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
button.addEventListener('mouseenter', () => {
button.style.transform = 'scale(1.05) rotate(2deg)';
});
button.addEventListener('mouseleave', () => {
button.style.transform = 'scale(1) rotate(0)';
});
});
// Эффект волны при клике на кнопку
const addRippleEffect = (event) => {
const button = event.currentTarget;
const ripple = document.createElement('span');
const rect = button.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = event.clientX - rect.left - size / 2;
const y = event.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = `${size}px`;
ripple.style.left = `${x}px`;
ripple.style.top = `${y}px`;
ripple.classList.add('ripple');
button.appendChild(ripple);
ripple.addEventListener('animationend', () => {
ripple.remove();
});
};
buttons.forEach(button => {
button.addEventListener('click', addRippleEffect);
});
});