Implement settings reset

This commit is contained in:
toasted-nutbread 2019-12-14 23:06:44 -05:00
parent f17b55239e
commit e2a4a46e60
3 changed files with 57 additions and 0 deletions

View File

@ -488,3 +488,7 @@ function optionsSave(options) {
}); });
}); });
} }
function optionsGetDefault() {
return optionsUpdateVersion({}, {});
}

View File

@ -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 // Setup
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
document.querySelector('#settings-export').addEventListener('click', _onSettingsExportClick, false); document.querySelector('#settings-export').addEventListener('click', _onSettingsExportClick, false);
document.querySelector('#settings-import').addEventListener('click', _onSettingsImportClick, false); document.querySelector('#settings-import').addEventListener('click', _onSettingsImportClick, false);
document.querySelector('#settings-import-file').addEventListener('change', _onSettingsImportFileChange, 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); }, false);

View File

@ -867,6 +867,7 @@
<div> <div>
<button class="btn btn-default" id="settings-export">Export Settings</button> <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-default" id="settings-import">Import Settings</button>
<button class="btn btn-danger" id="settings-reset">Reset Default Settings</button>
</div> </div>
<div hidden><input type="file" id="settings-import-file" accept=".json,application/json"></div> <div hidden><input type="file" id="settings-import-file" accept=".json,application/json"></div>
@ -916,6 +917,36 @@
</div> </div>
</div> </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">&times;</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>
<div> <div>