add reset settings option

This commit is contained in:
Argn0
2022-05-24 10:04:56 +02:00
parent 393861dcd3
commit 3007cddce9
4 changed files with 39 additions and 6 deletions

View File

@@ -947,5 +947,14 @@
}, },
"openOptionsPage": { "openOptionsPage": {
"message": "Open options page" "message": "Open options page"
},
"resetToDefault": {
"message": "Reset to default"
},
"confirmResetToDefault": {
"message": "Are you sure you want to reset all settings to their default values? This cannot be undone."
},
"whatResetToDefault": {
"message": "This resets all settings to their default values."
} }
} }

View File

@@ -368,6 +368,14 @@
</div> </div>
</div> </div>
<div data-type="button-press" data-sync="resetToDefault" data-confirm-message="confirmResetToDefault">
<div class="option-button trigger-button">
__MSG_resetToDefault__
</div>
<div class="small-description">__MSG_whatResetToDefault__</div>
</div>
</div> </div>
<div id="advanced" class="option-group hidden"> <div id="advanced" class="option-group hidden">

View File

@@ -113,6 +113,7 @@ export interface SBObject {
local: SBStorage; local: SBStorage;
forceSyncUpdate(prop: string): void; forceSyncUpdate(prop: string): void;
forceLocalUpdate(prop: string): void; forceLocalUpdate(prop: string): void;
resetToDefault(): void;
} }
const Config: SBObject = { const Config: SBObject = {
@@ -289,7 +290,8 @@ const Config: SBObject = {
config: null, config: null,
local: null, local: null,
forceSyncUpdate, forceSyncUpdate,
forceLocalUpdate forceLocalUpdate,
resetToDefault
}; };
// Function setup // Function setup
@@ -522,6 +524,10 @@ function addDefaults() {
} }
} }
function resetToDefault() {
chrome.storage.sync.set(Config.syncDefaults);
}
// Sync config // Sync config
setupConfig(); setupConfig();

View File

@@ -232,12 +232,22 @@ async function init() {
} }
case "button-press": { case "button-press": {
const actionButton = optionsElements[i].querySelector(".trigger-button"); const actionButton = optionsElements[i].querySelector(".trigger-button");
const confirmMessage = optionsElements[i].getAttribute("data-confirm-message");
switch(optionsElements[i].getAttribute("data-sync")) { actionButton.addEventListener("click", () => {
case "copyDebugInformation": if (confirmMessage !== null && !confirm(chrome.i18n.getMessage(confirmMessage))) {
actionButton.addEventListener("click", copyDebugOutputToClipboard); return;
break; }
} switch (optionsElements[i].getAttribute("data-sync")) {
case "copyDebugInformation":
copyDebugOutputToClipboard();
break;
case "resetToDefault":
Config.resetToDefault();
window.location.reload();
break;
}
});
break; break;
} }