Skip to content

Commit

Permalink
Update global.js
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-sorrentino committed Nov 15, 2024
1 parent da3ca00 commit f271ac6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions hushline/static/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,29 @@ document.addEventListener("DOMContentLoaded", function () {
}

function updateThemeColor() {
const themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
const themeColorMetaTag = document.querySelector(
'meta[name="theme-color"]',
);

// Retrieve hex values of CSS variables
const lightModeColor = getHexColorFromCSSVariable("--theme-color-light");
const darkModeColor = getHexColorFromCSSVariable("--theme-color-dark");

// Detect if user prefers dark mode
const isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
const isDarkMode = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;

// Set the meta tag with the appropriate color
themeColorMetaTag.setAttribute("content", isDarkMode ? darkModeColor : lightModeColor);
themeColorMetaTag.setAttribute(
"content",
isDarkMode ? darkModeColor : lightModeColor,
);
}

// Initialize and add event listener for theme changes
updateThemeColor();
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", updateThemeColor);
});
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", updateThemeColor);
});

0 comments on commit f271ac6

Please sign in to comment.