Add settings configuration, not using it yet

This commit is contained in:
idk
2019-02-07 17:09:31 -05:00
parent c55c810928
commit 9583f680a0
7 changed files with 208 additions and 51 deletions

60
options/options.js Normal file
View File

@@ -0,0 +1,60 @@
/*
Store the currently selected settings using browser.storage.local.
*/
function storeSettings() {
function getSince() {
const proxy_scheme = document.querySelector("#proxy_scheme");
return proxy_scheme.value;
}
function getTypes() {
let proxy_value = [];
const textboxes = document.querySelectorAll(".proxy-options [type=text]");
for (let item of textboxes) {
if (item.checked) {
proxy_value.push(item.getAttribute("value"));
}
}
return proxy_value;
}
const proxy_scheme = getSince();
const proxy_value = getTypes();
browser.storage.local.set({
proxy_scheme,
proxy_value
});
}
/*
Update the options UI with the settings values retrieved from storage,
or the default settings if the stored settings are empty.
*/
function updateUI(restoredSettings) {
const selectList = document.querySelector("#proxy_scheme");
selectList.value = restoredSettings.proxy_scheme;
const textboxes = document.querySelectorAll(".proxy-options [type=text]");
for (let item of textboxes) {
if (restoredSettings.proxy_value.indexOf(item.getAttribute("value")) != -1) {
item.value = restoredSettings.proxy_value.indexOf(item.getAttribute("value"));
}
}
}
function onError(e) {
console.error(e);
}
/*
On opening the options page, fetch stored settings and update the UI with them.
*/
const gettingStoredSettings = browser.storage.local.get();
gettingStoredSettings.then(updateUI, onError);
/*
On clicking the save button, save the currently selected settings.
*/
const saveButton = document.querySelector("#save-button");
saveButton.addEventListener("click", storeSettings);