diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-14 23:06:44 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-29 12:33:28 -0500 |
commit | e2a4a46e6006b9a85a3b6e5e26f55076afb16919 (patch) | |
tree | 18de87301b03c7d3164dcf7af820af64e19998d4 | |
parent | f17b55239e941394908fad4a6b1676a171342dac (diff) |
Implement settings reset
-rw-r--r-- | ext/bg/js/options.js | 4 | ||||
-rw-r--r-- | ext/bg/js/settings/backup.js | 22 | ||||
-rw-r--r-- | ext/bg/settings.html | 31 |
3 files changed, 57 insertions, 0 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 1650cea9..84e74bd8 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -488,3 +488,7 @@ function optionsSave(options) { }); }); } + +function optionsGetDefault() { + return optionsUpdateVersion({}, {}); +} diff --git a/ext/bg/js/settings/backup.js b/ext/bg/js/settings/backup.js index 1e099288..d278b718 100644 --- a/ext/bg/js/settings/backup.js +++ b/ext/bg/js/settings/backup.js @@ -339,10 +339,32 @@ function _onSettingsImportFileChange(e) { } +// Resetting + +function _onSettingsResetClick() { + $('#settings-reset-modal').modal('show'); +} + +async function _onSettingsResetConfirmClick() { + $('#settings-reset-modal').modal('hide'); + + // Get default options + const optionsFull = optionsGetDefault(); + + // Assign options + await _settingsImportSetOptionsFull(optionsFull); + + // Reload settings page + window.location.reload(); +} + + // Setup window.addEventListener('DOMContentLoaded', () => { document.querySelector('#settings-export').addEventListener('click', _onSettingsExportClick, false); document.querySelector('#settings-import').addEventListener('click', _onSettingsImportClick, false); document.querySelector('#settings-import-file').addEventListener('change', _onSettingsImportFileChange, false); + document.querySelector('#settings-reset').addEventListener('click', _onSettingsResetClick, false); + document.querySelector('#settings-reset-modal-confirm').addEventListener('click', _onSettingsResetConfirmClick, false); }, false); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 56b5610e..4c973674 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -867,6 +867,7 @@ <div> <button class="btn btn-default" id="settings-export">Export Settings</button> <button class="btn btn-default" id="settings-import">Import Settings</button> + <button class="btn btn-danger" id="settings-reset">Reset Default Settings</button> </div> <div hidden><input type="file" id="settings-import-file" accept=".json,application/json"></div> @@ -916,6 +917,36 @@ </div> </div> </div> + + <div class="modal fade" tabindex="-1" role="dialog" id="settings-reset-modal"> + <div class="modal-dialog modal-dialog-centered"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> + <h4 class="modal-title">Settings Reset</h4> + </div> + <div class="modal-body"> + <p class="text-danger"> + You are about to reset all Yomichan settings back to their default values. + This will delete all custom profiles you may have created. + <strong>This action cannot be undone.</strong> + </p> + <p> + Consider making a backup using the "Export Settings" button before resetting + if you want to be able to revert. + </p> + <p> + Dictionary data will not be deleted, but any installed dictionaries + will need to be re-enabled. + </p> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> + <button type="button" class="btn btn-danger" id="settings-reset-modal-confirm">Reset All Settings</button> + </div> + </div> + </div> + </div> </div> <div> |