Skip to content

Commit

Permalink
proper colormode get/set
Browse files Browse the repository at this point in the history
  • Loading branch information
mart2070 committed Aug 2, 2024
1 parent d3d192d commit 4599c37
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tdx-enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
if (!frame.querySelector("#customStyles")) {
let head = frame.querySelector("head")
let html = frame.querySelector("html")
//html.classList.add(getColorMode()) //FIX THIS!
html.classList.add(settings("get","colorMode"))
let s = document.createElement("style")
s.id = "customStyles"
s.innerText = customStyles
Expand Down Expand Up @@ -574,6 +574,11 @@
*/

function getColorMode() {
let mode = window.matchMedia('(prefers-color-scheme: dark)').matches ? "darkMode" : "lightMode"
return mode
}

function setColorMode(mode,store=true) {
if (!mode) {
mode = "auto"
Expand All @@ -582,7 +587,7 @@
colorScheme = mode
var storageMode = mode

let autoScheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? "darkMode" : "lightMode"
let autoScheme = getColorMode()
if (autoScheme == mode) {
storageMode = "auto"
}
Expand Down Expand Up @@ -823,6 +828,7 @@
console.error("Couldn't grab settings!",e)
//set defaults
data = {
colorMode: getColorMode(),
linkBehavior: "tabs"
}
}
Expand Down

0 comments on commit 4599c37

Please sign in to comment.