Skip to content

Commit bc9451b

Browse files
Merge pull request #798: Fix dark mode inconsistencies on chat and vault pages
2 parents 0ae2cc9 + 666dfca commit bc9451b

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎frontend/pages/chat.html‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@
1010
document.documentElement.setAttribute('data-theme', 'night');
1111
}
1212
})();
13+
14+
document.addEventListener('DOMContentLoaded', function () {
15+
const btn = document.getElementById('themeToggle');
16+
if (!btn) return;
17+
18+
const icon = btn.querySelector('i');
19+
const STORAGE_KEY = 'bibliodrift_theme';
20+
21+
function applyTheme(theme) {
22+
if (theme === 'night') {
23+
document.documentElement.setAttribute('data-theme', 'night');
24+
if (icon) icon.className = 'fa-solid fa-sun';
25+
} else {
26+
document.documentElement.removeAttribute('data-theme');
27+
if (icon) icon.className = 'fa-solid fa-moon';
28+
}
29+
30+
localStorage.setItem(STORAGE_KEY, theme);
31+
if (typeof restoreTheme === 'function') restoreTheme();
32+
}
33+
34+
const savedTheme = localStorage.getItem(STORAGE_KEY) || 'light';
35+
applyTheme(savedTheme);
36+
37+
btn.addEventListener('click', function () {
38+
const current = document.documentElement.getAttribute('data-theme') === 'night' ? 'night' : 'light';
39+
const next = current === 'night' ? 'light' : 'night';
40+
applyTheme(next);
41+
});
42+
});
1343
</script>
1444
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1545
<title>Chat with Elara | BiblioDrift</title>

‎frontend/pages/vault.html‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
<script>
2020
(function () {
21-
const theme = localStorage.getItem('bibliodrift_theme') || 'dark';
22-
document.documentElement.setAttribute('data-theme', theme);
21+
const theme = localStorage.getItem('bibliodrift_theme');
22+
if (theme === 'night') {
23+
document.documentElement.setAttribute('data-theme', 'night');
24+
}
2325
})();
2426
</script>
2527

@@ -699,7 +701,7 @@ <h3 style="color: var(--text-main) !important;">Ambient Sanctuary</h3>
699701

700702
function updateThemeToggleButton(currentTheme) {
701703
const icon = themeToggle.querySelector("i");
702-
if (currentTheme === "night" || currentTheme === "dark") {
704+
if (currentTheme === "night") {
703705
icon.className = "fa-solid fa-sun";
704706
themeToggle.setAttribute("title", "Switch to Light Mode");
705707
} else {
@@ -712,9 +714,13 @@ <h3 style="color: var(--text-main) !important;">Ambient Sanctuary</h3>
712714

713715
themeToggle.addEventListener("click", () => {
714716
const activeTheme = document.documentElement.getAttribute('data-theme');
715-
const nextTheme = (activeTheme === "dark" || activeTheme === "night") ? "light" : "dark";
717+
const nextTheme = (activeTheme === "night") ? "light" : "night";
716718

717-
document.documentElement.setAttribute('data-theme', nextTheme);
719+
if (nextTheme === "night") {
720+
document.documentElement.setAttribute('data-theme', 'night');
721+
} else {
722+
document.documentElement.removeAttribute('data-theme');
723+
}
718724
localStorage.setItem('bibliodrift_theme', nextTheme);
719725
if (typeof restoreTheme === 'function') restoreTheme();
720726
updateThemeToggleButton(nextTheme);

0 commit comments

Comments
 (0)