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;
    }

    localStorage.setItem("config", JSON.stringify(DEFAULT_CONFIG));
    return DEFAULT_CONFIG;
})();

function saveConfig() {
    localStorage.setItem("config", JSON.stringify(config));
}

document.getElementById("toggle-crt").addEventListener("click", () => {
    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";
}
