mirror of
https://github.com/davegallant/davegallant.github.io.git
synced 2025-08-06 08:43:40 +00:00
Force dark theme
This commit is contained in:
@@ -28,32 +28,13 @@ function setCommentsTheme(theme) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setTheme(theme) {
|
function setTheme(theme) {
|
||||||
if (theme == "auto") {
|
|
||||||
theme = window.matchMedia("(prefers-color-scheme: light)").matches
|
|
||||||
? "light"
|
|
||||||
: "dark";
|
|
||||||
}
|
|
||||||
document.documentElement.setAttribute("data-theme", theme);
|
document.documentElement.setAttribute("data-theme", theme);
|
||||||
setPrismTheme(theme);
|
setPrismTheme(theme);
|
||||||
setCommentsTheme(theme);
|
setCommentsTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTheme(e) {
|
|
||||||
const theme = e.currentTarget.classList.contains("light--hidden")
|
|
||||||
? "light"
|
|
||||||
: "dark";
|
|
||||||
setTheme(theme);
|
|
||||||
saveTheme(theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initial load
|
setTheme("dark");
|
||||||
setTheme(getTheme());
|
|
||||||
|
|
||||||
window
|
|
||||||
.matchMedia("(prefers-color-scheme: dark)")
|
|
||||||
.addEventListener("change", (event) => {
|
|
||||||
setTheme(getTheme());
|
|
||||||
});
|
|
||||||
|
|
||||||
// This script is inlined in the <head> of the document, so we have to wait
|
// This script is inlined in the <head> of the document, so we have to wait
|
||||||
// for the DOM content before can add event listeners to the toggle buttons
|
// for the DOM content before can add event listeners to the toggle buttons
|
||||||
|
Reference in New Issue
Block a user