summaryrefslogtreecommitdiff
path: root/src/common/config.ts
blob: 01382578ea7aab7e5453e43e46d794120813952a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export async function setConfig(key: ConfigKey, value: any) {
    try {
        await browser.storage.sync.set({ [key.toString()]: value });
    } catch (e) {
        console.error("Failed to persist config option to storage", e);
    }
}

export async function getConfig(key: ConfigKey) {
    return (await browser.storage.sync.get({ [key.toString()]: undefined }))[key.toString()]
        || key.defaultValue;
}

export class ConfigKey {
    static readonly ALLOW_UNSIGNED_DOMAINS = new ConfigKey('config.allow_unsigned_script_no_owner', 'yes', { yes: "Yes", no: "No", ask: "Ask" });
    static readonly ALLOW_MIXED_SCRIPTS    = new ConfigKey('config.allow_mixed_unsigned_scripts', 'ask', { yes: "Yes", no: "No", ask: "Ask" });
    static readonly TRUSTED_FIRST_LOAD     = new ConfigKey('config.trust_all_on_first_load', 'yes', { yes: "Yes", no: "No" });

    // private to disallow creating other instances of this type
    private constructor(private key: string, public readonly defaultValue: string, public readonly options: {[key: string]: string}) {
    }

    toString() {
        return this.key;
    }
}