feat: add customizable accent color
This commit is contained in:
@@ -24,6 +24,20 @@
|
||||
var root = document.documentElement;
|
||||
root.classList.toggle("dark", dark);
|
||||
root.style.colorScheme = dark ? "dark" : "light";
|
||||
|
||||
var accent = localStorage.getItem("accent");
|
||||
if (accent && /^#[0-9a-fA-F]{6}$/.test(accent)) {
|
||||
var hex = accent.slice(1);
|
||||
var r = parseInt(hex.slice(0, 2), 16) / 255;
|
||||
var g = parseInt(hex.slice(2, 4), 16) / 255;
|
||||
var b = parseInt(hex.slice(4, 6), 16) / 255;
|
||||
var lin = function (c) {
|
||||
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
||||
};
|
||||
var lum = 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
||||
root.style.setProperty("--c-accent", accent);
|
||||
root.style.setProperty("--c-accent-contrast", lum > 0.45 ? "#0b1220" : "#ffffff");
|
||||
}
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user