light theme! crt now disabled by default
This commit is contained in:
parent
cdcc7466e5
commit
c6afc274c2
9 changed files with 355 additions and 315 deletions
|
@ -1,42 +1,33 @@
|
|||
function toggle_config_setting(config, name) {
|
||||
if (config[name]) {
|
||||
delete config[name];
|
||||
update_config(config);
|
||||
return true;
|
||||
}
|
||||
config[name] = true;
|
||||
update_config(config);
|
||||
return true;
|
||||
}
|
||||
const DEFAULT_CONFIG = {
|
||||
crt: false
|
||||
};
|
||||
const config = (() => {
|
||||
let saved = localStorage.getItem("config");
|
||||
if (saved) {
|
||||
const config = JSON.parse(saved);
|
||||
setCRT(config.crt || DEFAULT_CONFIG.crt);
|
||||
return config;
|
||||
}
|
||||
|
||||
function set_config_setting(config, name, value) {
|
||||
config[name] = value;
|
||||
update_config(config);
|
||||
return true;
|
||||
}
|
||||
localStorage.setItem("config", JSON.stringify(DEFAULT_CONFIG));
|
||||
return DEFAULT_CONFIG;
|
||||
})();
|
||||
|
||||
function clear_config_setting(config, name) {
|
||||
if (!config[name]) return false;
|
||||
delete config[name];
|
||||
update_config(config);
|
||||
return true;
|
||||
}
|
||||
|
||||
function update_config(config) {
|
||||
localStorage.setItem("config", JSON.stringify(config));
|
||||
}
|
||||
|
||||
const config = JSON.parse(localStorage.getItem("config")) || {};
|
||||
if (config) {
|
||||
if (config.disable_crt) {
|
||||
document.querySelector('div#overlay').setAttribute("hidden", true);
|
||||
document.body.style.textShadow = "none";
|
||||
document.getElementById('toggle-crt').classList.add("disabled");
|
||||
}
|
||||
function saveConfig() {
|
||||
localStorage.setItem("config", JSON.stringify(config));
|
||||
}
|
||||
|
||||
document.getElementById("toggle-crt").addEventListener("click", () => {
|
||||
toggle_config_setting(config, "disable_crt");
|
||||
document.querySelector('div#overlay').toggleAttribute("hidden");
|
||||
document.getElementById('toggle-crt').className = config.disable_crt ? "disabled" : "";
|
||||
config.crt = !config.crt;
|
||||
setCRT(config.crt);
|
||||
saveConfig();
|
||||
});
|
||||
|
||||
function setCRT(/** @type boolean */ enabled) {
|
||||
if (enabled) {
|
||||
document.body.classList.add("crt");
|
||||
} else {
|
||||
document.body.classList.remove("crt");
|
||||
}
|
||||
document.getElementById('toggle-crt').className = enabled ? "" : "disabled";
|
||||
}
|
||||
|
|
16
public/script/index.js
Normal file
16
public/script/index.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
const hexPrimary = document.getElementById("hex-primary");
|
||||
const hexSecondary = document.getElementById("hex-secondary");
|
||||
const hexTertiary = document.getElementById("hex-tertiary");
|
||||
|
||||
function updateHexColours() {
|
||||
const style = getComputedStyle(document.body);
|
||||
hexPrimary.textContent = style.getPropertyValue('--primary');
|
||||
hexSecondary.textContent = style.getPropertyValue('--secondary');
|
||||
hexTertiary.textContent = style.getPropertyValue('--tertiary');
|
||||
}
|
||||
|
||||
updateHexColours();
|
||||
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
|
||||
updateHexColours();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue