add option reset button, default options

This commit is contained in:
Vipra 2023-07-04 22:41:24 +02:00
parent 0b8ed6c238
commit 14ae2a1bca
2 changed files with 27 additions and 6 deletions

View file

@ -44,6 +44,7 @@
<div class="footer"> <div class="footer">
<button type="submit">Save</button> <button type="submit">Save</button>
<button id="resetbutton" type="button">Reset Cache</button> <button id="resetbutton" type="button">Reset Cache</button>
<button id="defaultSettings" type="button">Default settings</button>
<a target="_blank" href="https://github.com/ItsVipra/ProToots" <a target="_blank" href="https://github.com/ItsVipra/ProToots"
>More info / help on Github</a >More info / help on Github</a
> >

View file

@ -14,12 +14,18 @@ function saveOptions(e) {
} }
function restoreOptions() { function restoreOptions() {
function setCurrentChoice(result) { async function setCurrentChoice(result) {
document.querySelector("#logging").checked = result.logging || false; console.log(result);
document.querySelector("#status").checked = result.statusVisibility || false; if (Object.keys(result).length == 0) {
document.querySelector("#notification").checked = result.notificationVisibility || false; console.log(result);
document.querySelector("#account").checked = result.accountVisibility || false; await defaultOptions();
document.querySelector("#conversation").checked = result.conversationVisibility || false; } else {
document.querySelector("#logging").checked = result.logging || false;
document.querySelector("#status").checked = result.statusVisibility || false;
document.querySelector("#notification").checked = result.notificationVisibility || false;
document.querySelector("#account").checked = result.accountVisibility || false;
document.querySelector("#conversation").checked = result.conversationVisibility || false;
}
} }
function onError(err) { function onError(err) {
@ -30,8 +36,22 @@ function restoreOptions() {
getting.then(setCurrentChoice, onError); getting.then(setCurrentChoice, onError);
} }
async function defaultOptions() {
await storage.sync.set({
logging: false,
statusVisibility: true,
notificationVisibility: true,
accountVisibility: true,
conversationVisibility: false,
});
restoreOptions();
}
document.addEventListener("DOMContentLoaded", restoreOptions); document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions); document.querySelector("form").addEventListener("submit", saveOptions);
document.querySelector("#resetbutton").addEventListener("click", async () => { document.querySelector("#resetbutton").addEventListener("click", async () => {
await storage.local.clear(); await storage.local.clear();
}); });
document.querySelector("#defaultSettings").addEventListener("click", async () => {
await defaultOptions();
});