🚸 Set theme-color using theme colour scheme

This commit is contained in:
James Panther
2022-11-22 09:55:20 +11:00
parent 4679ce485c
commit 447ce2f52a
2 changed files with 10 additions and 4 deletions
+9 -3
View File
@@ -1,11 +1,17 @@
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
const userPreference = localStorage.getItem("appearance");
function getCSSValue(varName) {
var cssValue = window.getComputedStyle(document.documentElement).getPropertyValue(varName);
return "rgb(" + cssValue.replace(/\s+/g, "") + ")";
}
function setThemeColor() {
const metaThemeColor = document.querySelector("meta[name=theme-color]");
var metaThemeColor = document.querySelector("meta[name=theme-color]");
document.documentElement.classList.contains("dark")
? metaThemeColor.setAttribute("content", "#27272a")
: metaThemeColor.setAttribute("content", "#ffffff");
? metaThemeColor.setAttribute("content", getCSSValue("--color-neutral-800"))
: metaThemeColor.setAttribute("content", getCSSValue("--color-neutral"));
return true;
}
if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {