-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (55 loc) · 1.87 KB
/
script.js
File metadata and controls
66 lines (55 loc) · 1.87 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
document.addEventListener('DOMContentLoaded', () => {
const currentYearElement = document.getElementById('currentYear');
if (currentYearElement) {
currentYearElement.textContent = new Date().getFullYear();
}
const copyCards = document.querySelectorAll('.support-card--copy');
const fallbackCopy = (text) => {
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.setAttribute('readonly', '');
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
textarea.remove();
};
copyCards.forEach((card) => {
const button = card.querySelector('.copy-btn');
if (!button) return;
const handleCopy = async (event) => {
event.preventDefault();
const value = card.getAttribute('data-copy');
if (!value) return;
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
await navigator.clipboard.writeText(value);
} else {
fallbackCopy(value);
}
} catch (error) {
fallbackCopy(value);
}
const original = button.textContent;
button.textContent = 'Скопировано';
card.classList.add('is-copied');
window.setTimeout(() => {
button.textContent = original;
card.classList.remove('is-copied');
}, 1800);
};
card.addEventListener('click', handleCopy);
});
const scrollButton = document.getElementById('scrollToTopBtn');
if (!scrollButton) return;
const onScroll = () => {
if (window.scrollY > 600) scrollButton.classList.add('visible');
else scrollButton.classList.remove('visible');
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
scrollButton.addEventListener('click', () => {
window.scrollTo({ top: 0 });
});
});