2020-01-05 00:54:40 +01:00
|
|
|
function saveOptions(e) {
|
|
|
|
|
e.preventDefault();
|
2020-01-05 23:28:42 +01:00
|
|
|
|
|
|
|
|
console.debug("Save preferences");
|
2020-01-09 21:03:06 +01:00
|
|
|
|
2020-01-05 00:54:40 +01:00
|
|
|
browser.storage.sync.set({
|
2020-01-09 21:03:06 +01:00
|
|
|
optionsRadioTest: document.querySelector(
|
|
|
|
|
'input[name="options_test"]:checked'
|
|
|
|
|
).value,
|
2020-01-05 23:28:42 +01:00
|
|
|
optionsCheck1: document.querySelector('input[name="check1"]').checked,
|
|
|
|
|
optionsCheck2: document.querySelector('input[name="check2"]').checked,
|
|
|
|
|
optionsCheck3: document.querySelector('input[name="check3"]').checked
|
2020-01-05 00:54:40 +01:00
|
|
|
});
|
2020-01-11 17:17:01 +01:00
|
|
|
|
|
|
|
|
/*
|
2020-01-12 01:15:19 +01:00
|
|
|
* Save accounts and filters
|
2020-01-11 17:17:01 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-01-12 01:15:19 +01:00
|
|
|
console.debug("Store accounts and filters");
|
2020-01-11 17:17:01 +01:00
|
|
|
|
|
|
|
|
let treeBase = document.getElementById("accountsTree");
|
|
|
|
|
let inputs = treeBase.querySelectorAll("input");
|
|
|
|
|
let accounts = [];
|
2020-01-12 01:15:19 +01:00
|
|
|
let filters = [];
|
2020-01-11 17:17:01 +01:00
|
|
|
for (let i = 0; i < inputs.length; ++i) {
|
2020-01-11 23:21:00 +01:00
|
|
|
let account = JSON.parse(inputs[i].value);
|
2020-01-12 01:15:19 +01:00
|
|
|
let checked = inputs[i].checked;
|
|
|
|
|
accounts.push({ ...account, checked: checked });
|
|
|
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
|
let inboxMailFolder = account.folders.find(obj => obj.type === "inbox");
|
|
|
|
|
|
|
|
|
|
if (inboxMailFolder) {
|
|
|
|
|
console.debug("Filter Id: " + inboxMailFolder.accountId);
|
|
|
|
|
console.debug("Filter Path: " + inboxMailFolder.path);
|
|
|
|
|
|
|
|
|
|
filters.push({
|
|
|
|
|
unread: true,
|
|
|
|
|
folder: inboxMailFolder
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-11 17:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store accounts
|
|
|
|
|
browser.storage.sync.set({
|
|
|
|
|
accounts: accounts
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-12 01:15:19 +01:00
|
|
|
// Store query filters
|
|
|
|
|
browser.storage.sync.set({
|
|
|
|
|
filters: filters
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.debug("Store accounts and filters done");
|
2020-01-05 00:54:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function restoreOptions() {
|
2020-01-05 23:28:42 +01:00
|
|
|
console.debug("Restore preferences");
|
|
|
|
|
|
|
|
|
|
function setCurrentRadioChoice(result) {
|
|
|
|
|
let selector = result.optionsRadioTest || "Option1";
|
2020-01-09 21:03:06 +01:00
|
|
|
let radioButton = document.querySelector(`[value=${selector}]`);
|
2020-01-05 23:28:42 +01:00
|
|
|
radioButton.checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setCurrentCheckChoice(result) {
|
|
|
|
|
let checkbox1 = document.querySelector('[name="check1"]');
|
2020-01-09 21:03:06 +01:00
|
|
|
checkbox1.checked = result.optionsCheck1 || false;
|
2020-01-05 23:28:42 +01:00
|
|
|
let checkbox2 = document.querySelector('[name="check2"]');
|
2020-01-09 21:03:06 +01:00
|
|
|
checkbox2.checked = result.optionsCheck2 || false;
|
2020-01-05 23:28:42 +01:00
|
|
|
let checkbox3 = document.querySelector('[name="check3"]');
|
2020-01-09 21:03:06 +01:00
|
|
|
checkbox3.checked = result.optionsCheck3 || false;
|
2020-01-05 00:54:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onError(error) {
|
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 23:28:42 +01:00
|
|
|
var getting = browser.storage.sync.get("optionsRadioTest");
|
2020-01-09 21:03:06 +01:00
|
|
|
getting.then(setCurrentRadioChoice, onError);
|
|
|
|
|
|
|
|
|
|
var getting = browser.storage.sync.get([
|
|
|
|
|
"optionsCheck1",
|
|
|
|
|
"optionsCheck2",
|
|
|
|
|
"optionsCheck3"
|
|
|
|
|
]);
|
|
|
|
|
getting.then(setCurrentCheckChoice, onError);
|
2020-01-05 00:54:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", restoreOptions);
|
2020-01-09 21:03:06 +01:00
|
|
|
document
|
|
|
|
|
.querySelector('[name="saveform"]')
|
|
|
|
|
.addEventListener("submit", saveOptions);
|