Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (74 loc) · 3.28 KB
/
Copy pathscript.js
File metadata and controls
89 lines (74 loc) · 3.28 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
// ── Dark mode toggle ────────────────────────────────────────
const toggle = document.getElementById('theme-toggle');
const icon = document.getElementById('theme-icon');
// Respect the user's OS preference on first visit, then use saved preference
const savedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const initialTheme = savedTheme ?? (prefersDark ? 'dark' : 'light');
applyTheme(initialTheme);
toggle.addEventListener('click', () => {
const current = document.documentElement.getAttribute('data-theme');
applyTheme(current === 'dark' ? 'light' : 'dark');
});
function applyTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
icon.textContent = theme === 'dark' ? '🌙' : '☀️';
localStorage.setItem('theme', theme);
}
// ── Footer year ─────────────────────────────────────────────
document.getElementById('year').textContent = new Date().getFullYear();
// ── Union flag background ────────────────────────────────────
function applyUnionFlag(enabled) {
document.body.classList.toggle('union-flag-bg', enabled);
}
applyUnionFlag(Flags.get('union-flag-bg'));
// Keep in sync if the flag is changed in another tab (e.g. flags.html)
window.addEventListener('storage', () => {
applyUnionFlag(Flags.get('union-flag-bg'));
});
// ── Christmas cursor ─────────────────────────────────────────
// Define the festive date window (month is 0-indexed: 11 = December)
const XMAS_START = { month: 11, day: 1 }; // 1 Dec
const XMAS_END = { month: 11, day: 31 }; // 31 Dec
const xmasBtn = document.getElementById('xmas-toggle');
let xmasEnabled = false;
let lastTreeTime = 0;
const TREE_INTERVAL = 40; // ms between spawns while moving — lower = more trees
function isXmasSeason() {
const now = new Date();
const month = now.getMonth();
const day = now.getDate();
const afterStart = month > XMAS_START.month ||
(month === XMAS_START.month && day >= XMAS_START.day);
const beforeEnd = month < XMAS_END.month ||
(month === XMAS_END.month && day <= XMAS_END.day);
return afterStart && beforeEnd;
}
function spawnTree(x, y) {
const el = document.createElement('span');
el.className = 'xmas-tree';
el.textContent = '🎄';
el.style.left = x + 'px';
el.style.top = y + 'px';
document.body.appendChild(el);
el.addEventListener('animationend', () => el.remove());
}
function onMouseMove(e) {
if (!xmasEnabled) return;
const now = Date.now();
if (now - lastTreeTime < TREE_INTERVAL) return;
lastTreeTime = now;
spawnTree(e.clientX, e.clientY);
}
function setXmas(enabled) {
xmasEnabled = enabled;
Flags.set('christmas-cursor', enabled);
xmasBtn.classList.toggle('active', enabled);
xmasBtn.setAttribute('aria-pressed', enabled);
}
if (isXmasSeason()) {
xmasBtn.hidden = false;
setXmas(Flags.get('christmas-cursor'));
xmasBtn.addEventListener('click', () => setXmas(!xmasEnabled));
document.addEventListener('mousemove', onMouseMove);
}