diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-13 00:33:26 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-13 00:33:26 -0800 |
| commit | 15369496ecc4f8bd2b170b9afc2c2c0558ae97ad (patch) | |
| tree | d85298931252062835557907dc0efdd705f78002 /static/js | |
| download | adelie-15369496ecc4f8bd2b170b9afc2c2c0558ae97ad.tar.gz adelie-15369496ecc4f8bd2b170b9afc2c2c0558ae97ad.zip | |
Init adelie
Diffstat (limited to 'static/js')
| -rw-r--r-- | static/js/script.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/static/js/script.js b/static/js/script.js new file mode 100644 index 0000000..d04c09d --- /dev/null +++ b/static/js/script.js @@ -0,0 +1,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); + }; +})(); |
