From 1dd14b2bccc12593514b4de943d9a81bc7b941a6 Mon Sep 17 00:00:00 2001 From: Utkarsh Singh Date: Sun, 17 May 2026 11:45:40 +0530 Subject: [PATCH 1/3] feat: add dark/light mode toggle with localStorage persistence --- static/script.js | 20 ++++++++++++++++++++ static/style.css | 30 ++++++++++++++++++++++++++++++ templates/index.html | 5 +++++ 3 files changed, 55 insertions(+) diff --git a/static/script.js b/static/script.js index 58b5d60b..0ce6a4a4 100644 --- a/static/script.js +++ b/static/script.js @@ -687,5 +687,25 @@ if (isDetailPage) { try { document.execCommand("copy"); showCopySuccess(); } catch (e) { /* silent fail */ } document.body.removeChild(ta); } + // ===================================================== +// Dark / Light Mode Toggle + +var themeToggle = document.getElementById('theme-toggle'); +var themeIcon = document.getElementById('theme-icon'); + +if (themeToggle) { + + if (localStorage.getItem('theme') === 'dark') { + document.body.classList.add('dark-mode'); + themeIcon.textContent = '☀️'; + } + + themeToggle.addEventListener('click', function () { + document.body.classList.toggle('dark-mode'); + var isDark = document.body.classList.contains('dark-mode'); + themeIcon.textContent = isDark ? '☀️' : '🌙'; + localStorage.setItem('theme', isDark ? 'dark' : 'light'); + }); +} } // end isDetailPage diff --git a/static/style.css b/static/style.css index 837c450d..207cfbd8 100644 --- a/static/style.css +++ b/static/style.css @@ -6,6 +6,33 @@ ============================================================= */ /* ---- Variables -------------------------------------------- */ +/* ── Theme Variables ── */ + + +body.dark-mode { + --bg-color: #0f0f1a; + --text-color: #ffffff; + --card-bg: #1e1e2e; +} + + + +/* Toggle Button */ +.theme-toggle { + background: none; + border: 2px solid var(--text-color); + border-radius: 50%; + width: 38px; + height: 38px; + cursor: pointer; + font-size: 18px; + margin-left: 10px; + transition: 0.3s; +} + +.theme-toggle:hover { + transform: scale(1.1); +} :root { /* Core palette */ --indigo-900: #0f1560; @@ -84,6 +111,9 @@ body { background: var(--white); line-height: 1.65; -webkit-font-smoothing: antialiased; + + background-color: var(--bg-color); + transition: background-color 0.3s, color 0.3s; } img { display: block; max-width: 100%; } a { color: var(--indigo-500); text-decoration: none; } diff --git a/templates/index.html b/templates/index.html index 0e8b0d20..377d5dde 100644 --- a/templates/index.html +++ b/templates/index.html @@ -16,11 +16,16 @@