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
|
(() => {
const toggleButton = document.getElementById("theme-toggle");
const html = document.documentElement;
const sessionTheme = sessionStorage.getItem("theme");
const systemPrefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;
const initialTheme = sessionTheme || (systemPrefersDark ? "dark" : "light");
if (initialTheme === "dark") {
html.setAttribute("data-theme", "dark");
toggleButton.checked = true;
}
toggleButton.addEventListener("change", () => {
const theme = html.getAttribute("data-theme");
if (theme === "dark") {
html.removeAttribute("data-theme");
sessionStorage.setItem("theme", "light");
toggleButton.checked = false;
} else {
html.setAttribute("data-theme", "dark");
sessionStorage.setItem("theme", "dark");
toggleButton.checked = true;
}
});
})();
(() => {
const colors = [
"#ff69b4",
"#b19cd9",
"#8b6f47",
"#ff85c0",
"#c4b5fd",
"#d4a574",
];
const shapes = ["❀", "✿", "✽", "✾", "✻", "❊", "❋", "✼"];
document.addEventListener("mousemove", (e) => {
createParticle(e.clientX, e.clientY);
});
const createParticle = (x, y) => {
const particle = document.createElement("div");
particle.className = "fairy-dust";
const shape = shapes[Math.floor(Math.random() * shapes.length)];
const size = Math.random() * 8 + 6;
const color = colors[Math.floor(Math.random() * colors.length)];
const offsetX = (Math.random() - 0.5) * 20;
const offsetY = (Math.random() - 0.5) * 20;
const rotation = Math.random() * 360;
particle.textContent = shape;
particle.style.cssText = `
position: fixed;
left: ${x + offsetX}px;
top: ${y + offsetY}px;
font-size: ${size}px;
color: ${color};
opacity: 0.4;
pointer-events: none;
z-index: 9001; /* it's over 9000 */
line-height: 1;
transform: rotate(${rotation}deg);
animation: fairy-float 0.8s ease-out forwards;
`;
document.body.appendChild(particle);
setTimeout(() => particle.remove(), 800);
};
})();
|