PrivateKeyboardAddon/settings/options.js

58 lines
2.0 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
})
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
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-08-08 19:49:22 +00:00
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);