summaryrefslogtreecommitdiff
path: root/src/common/config.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/config.ts')
-rw-r--r--src/common/config.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/config.ts b/src/common/config.ts
new file mode 100644
index 0000000..0138257
--- /dev/null
+++ b/src/common/config.ts
@@ -0,0 +1,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;
+ }
+} \ No newline at end of file