diff --git a/gui/preload-chat.js b/gui/preload-chat.js index a2a10c06..4e662991 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -162,32 +162,32 @@ window.addEventListener("DOMContentLoaded", () => { document.getElementById("bootstrap_theme").href = escape(theme_path); document.querySelector("html").setAttribute("data-bs-theme", "dark"); } else if (config.theme == "default_auto") { - var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; - document.getElementById("bootstrap_theme").href = escape(theme_path); + document.getElementById("bootstrap_theme").href = escape(theme_path); - // https://stackoverflow.com/a/57795495 - // check if dark mode or light mode used in OS - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { - // dark mode - document.documentElement.setAttribute("data-bs-theme", "dark"); - } else { - document.documentElement.setAttribute("data-bs-theme", "light"); - } + // https://stackoverflow.com/a/57795495 + // check if dark mode or light mode used in OS + if ( + window.matchMedia && + window.matchMedia("(prefers-color-scheme: dark)").matches + ) { + // dark mode + document.documentElement.setAttribute("data-bs-theme", "dark"); + } else { + document.documentElement.setAttribute("data-bs-theme", "light"); + } - // also register event listener for automatic change - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { + // also register event listener for automatic change + window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", (event) => { let newColorScheme = event.matches ? "dark" : "light"; - if(newColorScheme == "dark"){ - document.documentElement.setAttribute("data-bs-theme", "dark"); + if (newColorScheme == "dark") { + document.documentElement.setAttribute("data-bs-theme", "dark"); } else { - document.documentElement.setAttribute("data-bs-theme", "light"); + document.documentElement.setAttribute("data-bs-theme", "light"); } - - }); - - - + }); } else { var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; document.getElementById("bootstrap_theme").href = escape(theme_path); diff --git a/gui/preload-main.js b/gui/preload-main.js index 2091056f..eefdc198 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -367,24 +367,27 @@ window.addEventListener("DOMContentLoaded", () => { // https://stackoverflow.com/a/57795495 // check if dark mode or light mode used in OS - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { - // dark mode - document.documentElement.setAttribute("data-bs-theme", "dark"); + if ( + window.matchMedia && + window.matchMedia("(prefers-color-scheme: dark)").matches + ) { + // dark mode + document.documentElement.setAttribute("data-bs-theme", "dark"); } else { - document.documentElement.setAttribute("data-bs-theme", "light"); + document.documentElement.setAttribute("data-bs-theme", "light"); } // also register event listener for automatic change - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { - let newColorScheme = event.matches ? "dark" : "light"; - if(newColorScheme == "dark"){ - document.documentElement.setAttribute("data-bs-theme", "dark"); - } else { - document.documentElement.setAttribute("data-bs-theme", "light"); - } - }); - - + window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", (event) => { + let newColorScheme = event.matches ? "dark" : "light"; + if (newColorScheme == "dark") { + document.documentElement.setAttribute("data-bs-theme", "dark"); + } else { + document.documentElement.setAttribute("data-bs-theme", "light"); + } + }); } else { var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; document.getElementById("theme_selector").value = "default_light"; @@ -1235,27 +1238,29 @@ window.addEventListener("DOMContentLoaded", () => { document.querySelector("html").setAttribute("data-bs-theme", "dark"); } else if (theme == "default_auto") { var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; - // https://stackoverflow.com/a/57795495 - // check if dark mode or light mode used in OS - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + // https://stackoverflow.com/a/57795495 + // check if dark mode or light mode used in OS + if ( + window.matchMedia && + window.matchMedia("(prefers-color-scheme: dark)").matches + ) { // dark mode + document.documentElement.setAttribute("data-bs-theme", "dark"); + } else { + document.documentElement.setAttribute("data-bs-theme", "light"); + } + + // also register event listener for automatic change + window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", (event) => { + let newColorScheme = event.matches ? "dark" : "light"; + if (newColorScheme == "dark") { document.documentElement.setAttribute("data-bs-theme", "dark"); - } else { + } else { document.documentElement.setAttribute("data-bs-theme", "light"); - } - - // also register event listener for automatic change - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { - let newColorScheme = event.matches ? "dark" : "light"; - if(newColorScheme == "dark"){ - document.documentElement.setAttribute("data-bs-theme", "dark"); - } else { - document.documentElement.setAttribute("data-bs-theme", "light"); - } + } }); - - - } else { var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css";