[mv3] Add ability to reset to default settings

This commit is contained in:
Raymond Hill 2025-12-25 16:32:38 -05:00
parent 37d995eeac
commit 6063d4f0ad
No known key found for this signature in database
GPG key ID: F5630CAE62A14316
3 changed files with 21 additions and 1 deletions

View file

@ -383,6 +383,14 @@
"message": "Restore…",
"description": "Text for buttons used to restore content"
},
"resetToDefaultButton": {
"message": "Reset to default settings…",
"description": "Text for buttons used to reset configurations to default"
},
"resetToDefaultConfirm": {
"message": "All your custom settings will be removed. Do you really want to reset to default settings?",
"description": "Message asking user to confirm reset to default settings"
},
"dnrRulesWarning": {
"message": "Do not add content from untrusted sources",
"description": "Short description of the DNR rules editor pane"

View file

@ -103,6 +103,7 @@
<p>
<button class="iconified dontshrink" type="button"><span class="fa-icon">download-alt</span><span data-i18n="backupButton">_</span><span class="hover"></span></button>
<button class="iconified dontshrink" type="button"><span class="fa-icon">upload-alt</span><span data-i18n="restoreButton">_</span><span class="hover"></span></button><input type="file" accept="application/json">
<button class="iconified dontshrink" type="button"><span class="fa-icon">undo</span><span data-i18n="resetToDefaultButton">_</span><span class="hover"></span></button><input type="file" accept="application/json">
</p>
</div>
</section>

View file

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock
*/
import { browser, sendMessage } from './ext.js';
import { browser, i18n, sendMessage } from './ext.js';
import { dom, qs$ } from './dom.js';
import { hashFromIterable } from './dashboard.js';
import { renderFilterLists } from './filter-lists.js';
@ -173,6 +173,13 @@ async function restoreSettings() {
input.click();
}
async function resetSettings() {
const response = self.confirm(i18n.getMessage('resetToDefaultConfirm'));
if ( response !== true ) { return; }
const api = await import('./backup-restore.js');
await api.restoreFromObject({});
}
/******************************************************************************/
dom.on('#autoReload input[type="checkbox"]', 'change', ev => {
@ -210,6 +217,10 @@ dom.on('section[data-pane="settings"] [data-i18n="restoreButton"]', 'click', ( )
restoreSettings();
});
dom.on('section[data-pane="settings"] [data-i18n="resetToDefaultButton"]', 'click', ( ) => {
resetSettings();
});
/******************************************************************************/
function listen() {