-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (60 loc) · 2.31 KB
/
script.js
File metadata and controls
70 lines (60 loc) · 2.31 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
// Theme: dark by default, persist preference
const darkModeToggle = document.getElementById('darkModeToggle');
const body = document.body;
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
body.classList.remove('dark-mode');
} else {
body.classList.add('dark-mode');
}
if (darkModeToggle) {
darkModeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
localStorage.setItem('theme', body.classList.contains('dark-mode') ? 'dark' : 'light');
});
}
// Discord copy + toast
const discordLink = document.getElementById('discord-link');
const namePopup = document.getElementById('name-popup');
const DISCORD_USERNAME = 'arkanegd';
const notification = document.createElement('div');
notification.className = 'notification';
document.body.appendChild(notification);
function showToast(message) {
notification.textContent = message;
notification.classList.add('show');
clearTimeout(showToast._t);
showToast._t = setTimeout(() => notification.classList.remove('show'), 2000);
}
discordLink.addEventListener('click', async (e) => {
e.preventDefault();
try {
await navigator.clipboard.writeText(DISCORD_USERNAME);
showToast('Discord username copied to clipboard!');
} catch (err) {
console.error('Failed to copy username:', err);
showToast('Failed to copy username');
}
});
namePopup.addEventListener('click', () => {
showToast('Also known as Celestia! 🏳️⚧️');
});
// Subtle 3D tilt interaction for cards and avatar
const tiltElements = document.querySelectorAll('.tilt');
const constrain = 14; // lower is more tilt
function applyTilt(event, element) {
const rect = element.getBoundingClientRect();
const relX = event.clientX - rect.left;
const relY = event.clientY - rect.top;
const rx = ((relY - rect.height / 2) / rect.height) * -constrain;
const ry = ((relX - rect.width / 2) / rect.width) * constrain;
element.style.transform = `perspective(700px) rotateX(${rx}deg) rotateY(${ry}deg)`;
}
function resetTilt(element) {
element.style.transform = 'perspective(700px) rotateX(0deg) rotateY(0deg)';
}
tiltElements.forEach((el) => {
el.addEventListener('mousemove', (e) => applyTilt(e, el));
el.addEventListener('mouseleave', () => resetTilt(el));
el.addEventListener('mouseenter', () => el.style.willChange = 'transform');
});