Skip to content

Commit 2c281e5

Browse files
Bikram GoleBikram Gole
authored andcommitted
Sync browser chrome with active theme
1 parent f2f38e0 commit 2c281e5

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ let commandPalette = document.getElementById("command-palette");
337337
let commandBackdrop = document.getElementById("command-backdrop");
338338
let commandInput = document.getElementById("command-input");
339339
let commandResults = document.getElementById("command-results");
340+
const themeColorMeta = document.querySelector('meta[name="theme-color"]');
341+
const colorSchemeMeta = document.querySelector('meta[name="color-scheme"]');
340342
const quizQuestion = document.getElementById("quiz-question");
341343
const quizProgress = document.getElementById("quiz-progress");
342344
const quizOptions = document.getElementById("quiz-options");
@@ -992,6 +994,16 @@ function applyTheme(theme, notify = false) {
992994
currentTheme = selected;
993995
document.documentElement.dataset.theme = selected;
994996
document.body.dataset.theme = selected;
997+
const isLightTheme = selected === "paper";
998+
const computed = getComputedStyle(document.documentElement);
999+
const bgColor = computed.getPropertyValue("--bg-0").trim();
1000+
if (themeColorMeta && bgColor) {
1001+
themeColorMeta.setAttribute("content", bgColor);
1002+
}
1003+
if (colorSchemeMeta) {
1004+
colorSchemeMeta.setAttribute("content", isLightTheme ? "light" : "dark");
1005+
}
1006+
document.documentElement.style.colorScheme = isLightTheme ? "light" : "dark";
9951007
if (headerThemeSelect) headerThemeSelect.value = selected;
9961008
if (heroName) {
9971009
if (selected === "blackflag" && heroName.textContent.trim().length > 0) {

0 commit comments

Comments
 (0)