Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (42 loc) · 1.45 KB
/
Copy pathscript.js
File metadata and controls
45 lines (42 loc) · 1.45 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
// mobile menu
const toggle = document.querySelector('.menu-toggle');
const menu = document.querySelector('nav ul');
if (toggle && menu) {
toggle.addEventListener('click', () => menu.classList.toggle('open'));
}
// copy-to-clipboard
document.querySelectorAll('pre').forEach(pre => {
const btn = document.createElement('button');
btn.className = 'copy-btn';
btn.textContent = 'copy';
btn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(pre.querySelector('code').innerText);
btn.textContent = 'copied';
setTimeout(() => btn.textContent = 'copy', 1500);
} catch (e) { btn.textContent = 'failed'; }
});
pre.appendChild(btn);
});
// fade-in on scroll
const io = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
io.unobserve(e.target);
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.cloud-card, h2, .note').forEach(el => {
el.classList.add('fade-in');
io.observe(el);
});
// small footer detail: year in copyright
const yr = document.getElementById('year');
if (yr) yr.textContent = new Date().getFullYear();
// mark current page in nav
const here = (location.pathname.split('/').pop() || 'index.html').replace(/\.html$/, '');
document.querySelectorAll('.nav a').forEach(a => {
const target = (a.getAttribute('href') || '').replace(/\.html$/, '');
if (target === here) a.classList.add('active');
});