-
Notifications
You must be signed in to change notification settings - Fork 5
/
options.js
37 lines (32 loc) · 1.56 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
32
33
34
35
36
37
function saveOptions(e) {
e.preventDefault();
var server = document.querySelector("#server").value;
var port = document.querySelector("#port").value;
var username = document.querySelector("#username").value;
var password = document.querySelector("#password").value;
var context = document.querySelector("#context").value;
var protocol = document.querySelector("#protocol").value;
var channel = document.querySelector("#channel").value;
browser.storage.local.set({
asterisk: {server: server, port: port, username:username, password:password, context:context,protocol:protocol,channel:channel}
});
}
function restoreOptions() {
function setCurrentChoice(result) {
//console.log(result);
document.querySelector("#server").value = result.asterisk.server || "localhost";
document.querySelector("#port").value = result.asterisk.port || "8088";
document.querySelector("#username").value = result.asterisk.username || "admin";
document.querySelector("#password").value = result.asterisk.password || "";
document.querySelector("#context").value = result.asterisk.context || "default";
document.querySelector("#protocol").value = result.asterisk.protocol || "";
document.querySelector("#channel").value = result.asterisk.channel || "";
}
function onError(error) {
//console.log(`Error: ${error}`);
}
var getting = browser.storage.local.get("asterisk");
getting.then(setCurrentChoice, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);