-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptions.js
31 lines (24 loc) · 1.11 KB
/
options.js
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
27
28
29
30
31
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const $ = document.getElementById.bind(document);
const logError = console.exception.bind(console);
const saveOptions = () => {
const domains = $("domains").value.split(/\s*,\s*/).filter(v => !!v);
$("domains").value = domains.join(", ");
const mode = $("mode").value;
browser.storage.local.set({ domains, mode }).then(() => {
console.info("Settings saved", { domains, mode });
$("status").textContent = "Settings saved!";
setTimeout(() => { $("status").textContent = ""; }, 750);
}).catch(logError);
};
const restoreOptions = () => {
browser.storage.local.get({ domains: [], mode: "whitelist" }).then(({ domains, mode }) => {
$("domains").value = domains.filter(v => !!v).join(", ");
$("mode").value = mode;
}).catch(logError);
};
document.addEventListener("DOMContentLoaded", restoreOptions);
$("save").addEventListener("click", saveOptions);