fixed dark mode

This commit is contained in:
ION606
2025-09-15 10:54:35 -04:00
parent a7f6c9edb5
commit 5f535a61c1
3 changed files with 59 additions and 22 deletions
+14 -18
View File
@@ -28,40 +28,36 @@ function paintAuth() {
}
}
const r = document; // alias to keep things smol
const prefersDark = r.defaultView?.matchMedia?.('(prefers-color-scheme: dark)').matches === true,
stored = localStorage.getItem('theme'),
initial = stored ?? (prefersDark ? 'dark' : 'light');
// theme toggle stuff!
const prefersLight = document.defaultView?.matchMedia?.('(prefers-color-scheme: light)').matches === true,
saved = localStorage.getItem('theme'),
initial = saved ?? (prefersLight ? 'light' : 'dark');
const applyTheme = (mode) => {
const b = r.body;
const b = document.body;
b.classList.remove('theme-dark', 'theme-light');
b.classList.add(mode === 'dark' ? 'theme-dark' : 'theme-light');
const icon = r.querySelector('#themeToggleIcon'),
label = r.querySelector('#themeToggleLabel');
const icon = document.querySelector('#themeToggleIcon'),
label = document.querySelector('#themeToggleLabel');
if (icon && label) {
const dark = mode === 'dark';
icon.textContent = dark ? '🌙' : '☀️';
label.textContent = dark ? 'Dark' : 'Light';
const isDark = mode === 'dark';
icon.textContent = isDark ? '🌙' : '☀️';
label.textContent = isDark ? 'Dark' : 'Light';
}
const btn = r.querySelector('#themeToggle');
if (btn) btn.setAttribute('aria-pressed', String(mode === 'dark'));
document.querySelector('#themeToggle')?.setAttribute('aria-pressed', String(mode === 'dark'));
};
applyTheme(initial);
r.querySelector('#themeToggle')?.addEventListener('click', () => {
const isDark = r.body.classList.contains('theme-dark'),
next = isDark ? 'light' : 'dark';
document.querySelector('#themeToggle')?.addEventListener('click', () => {
const next = document.body.classList.contains('theme-dark') ? 'light' : 'dark';
applyTheme(next);
try { localStorage.setItem('theme', next); } catch (_) { /* ignore */ }
});
if (window.matchMedia) {
const mq = window.matchMedia("(prefers-color-scheme: dark)");
mq.addEventListener?.("change", (e) => {
+23 -4
View File
@@ -37,14 +37,33 @@
}
}
body.theme-light {
color-scheme: light;
}
body.theme-dark {
color-scheme: dark;
--bg: #0b1224;
--bg-2: #0e1730;
--surface: #0f1c3a;
--card: #0f1b33;
--text: #e7eef9;
--muted: #9fb2ce;
--border: rgba(255, 255, 255, 0.1);
--accent: #7aa2ff;
--accent-600: #4f7dff;
}
body.theme-light {
color-scheme: light;
--bg: #f6f8fc;
--bg-2: #eef2fb;
--surface: #ffffff;
--card: #ffffff;
--text: #0f172a;
--muted: #6b7280;
--border: #e5e9f2;
--accent: #2563eb;
--accent-600: #1e40af;
}
* {
box-sizing: border-box;
}