Prettified Code!

This commit is contained in:
DJ2LS 2023-03-16 07:41:41 +00:00 committed by GitHub Action
parent c280ab0a54
commit 91bebcd6a8
2 changed files with 56 additions and 51 deletions

View file

@ -162,32 +162,32 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("bootstrap_theme").href = escape(theme_path); document.getElementById("bootstrap_theme").href = escape(theme_path);
document.querySelector("html").setAttribute("data-bs-theme", "dark"); document.querySelector("html").setAttribute("data-bs-theme", "dark");
} else if (config.theme == "default_auto") { } else if (config.theme == "default_auto") {
var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; 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 // https://stackoverflow.com/a/57795495
// check if dark mode or light mode used in OS // check if dark mode or light mode used in OS
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { if (
// dark mode window.matchMedia &&
document.documentElement.setAttribute("data-bs-theme", "dark"); window.matchMedia("(prefers-color-scheme: dark)").matches
} else { ) {
document.documentElement.setAttribute("data-bs-theme", "light"); // dark mode
} document.documentElement.setAttribute("data-bs-theme", "dark");
} else {
document.documentElement.setAttribute("data-bs-theme", "light");
}
// also register event listener for automatic change // also register event listener for automatic change
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (event) => {
let newColorScheme = event.matches ? "dark" : "light"; let newColorScheme = event.matches ? "dark" : "light";
if(newColorScheme == "dark"){ if (newColorScheme == "dark") {
document.documentElement.setAttribute("data-bs-theme", "dark"); document.documentElement.setAttribute("data-bs-theme", "dark");
} else { } else {
document.documentElement.setAttribute("data-bs-theme", "light"); document.documentElement.setAttribute("data-bs-theme", "light");
} }
});
});
} else { } else {
var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; 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);

View file

@ -367,24 +367,27 @@ window.addEventListener("DOMContentLoaded", () => {
// https://stackoverflow.com/a/57795495 // https://stackoverflow.com/a/57795495
// check if dark mode or light mode used in OS // check if dark mode or light mode used in OS
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { if (
// dark mode window.matchMedia &&
document.documentElement.setAttribute("data-bs-theme", "dark"); window.matchMedia("(prefers-color-scheme: dark)").matches
) {
// dark mode
document.documentElement.setAttribute("data-bs-theme", "dark");
} else { } else {
document.documentElement.setAttribute("data-bs-theme", "light"); document.documentElement.setAttribute("data-bs-theme", "light");
} }
// also register event listener for automatic change // also register event listener for automatic change
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { window
let newColorScheme = event.matches ? "dark" : "light"; .matchMedia("(prefers-color-scheme: dark)")
if(newColorScheme == "dark"){ .addEventListener("change", (event) => {
document.documentElement.setAttribute("data-bs-theme", "dark"); let newColorScheme = event.matches ? "dark" : "light";
} else { if (newColorScheme == "dark") {
document.documentElement.setAttribute("data-bs-theme", "light"); document.documentElement.setAttribute("data-bs-theme", "dark");
} } else {
}); document.documentElement.setAttribute("data-bs-theme", "light");
}
});
} else { } else {
var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css";
document.getElementById("theme_selector").value = "default_light"; document.getElementById("theme_selector").value = "default_light";
@ -1235,27 +1238,29 @@ window.addEventListener("DOMContentLoaded", () => {
document.querySelector("html").setAttribute("data-bs-theme", "dark"); document.querySelector("html").setAttribute("data-bs-theme", "dark");
} else if (theme == "default_auto") { } else if (theme == "default_auto") {
var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css";
// https://stackoverflow.com/a/57795495 // https://stackoverflow.com/a/57795495
// check if dark mode or light mode used in OS // check if dark mode or light mode used in OS
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
// dark mode // 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"); document.documentElement.setAttribute("data-bs-theme", "dark");
} else { } 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");
}
}); });
} else { } else {
var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css"; var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css";