PrivateKeyboardAddon/settings/options.js

68 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-08-08 19:49:22 +00:00
/*
Private Keyboard
Copyright (C) 2021 Kevin Froman VoidNetwork LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
function saveOptions(e) {
2021-09-21 04:47:40 +00:00
e.preventDefault()
2021-08-08 19:49:22 +00:00
browser.storage.sync.set({
keyboardprivacywhitelist: document.querySelector("#whitelist").value
2021-09-21 04:47:40 +00:00
})
browser.storage.sync.set({
keyboardprivacylan: document.querySelector("#whitelistLAN").checked
})
2021-10-12 18:36:09 +00:00
browser.storage.sync.set({
keyboardprivacyprompt: document.querySelector("#usePrompt").checked
})
2021-09-21 04:47:40 +00:00
document.getElementById('saved').innerHTML = '<br><b>Saved</b>'
setTimeout(function(){
document.getElementById('saved').innerHTML = '<br>'
}, 3000)
2021-08-08 19:49:22 +00:00
}
function restoreOptions() {
2021-09-21 04:47:40 +00:00
function setCurrentWhitelist(result) {
2021-08-08 19:49:22 +00:00
if (result['keyboardprivacywhitelist']){
document.querySelector("#whitelist").value = result['keyboardprivacywhitelist']
}
}
2021-09-21 04:47:40 +00:00
function setCurrentLAN(result){
document.querySelector("#whitelistLAN").checked = result['keyboardprivacylan']
}
2021-08-08 19:49:22 +00:00
2021-10-12 18:36:09 +00:00
function setCurrentPrompt(result){
document.querySelector("#usePrompt").checked = result['keyboardprivacyprompt']
}
2021-08-08 19:49:22 +00:00
function onError(error) {
console.log(`Error: ${error}`);
}
let getting = browser.storage.sync.get("keyboardprivacywhitelist");
2021-09-21 04:47:40 +00:00
getting.then(setCurrentWhitelist, onError);
let gettingLAN = browser.storage.sync.get("keyboardprivacylan");
gettingLAN.then(setCurrentLAN, onError);
2021-10-12 18:36:09 +00:00
let gettingPrompt = browser.storage.sync.get("keyboardprivacyprompt");
gettingPrompt.then(setCurrentPrompt, onError);
2021-08-08 19:49:22 +00:00
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);