diff options
Diffstat (limited to 'src/js/settings.js')
-rw-r--r-- | src/js/settings.js | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/js/settings.js b/src/js/settings.js index deb033f..fc0ea68 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -27,7 +27,7 @@ import { setAccentColor, setTheme } from './theme.js'; /******************************************************************************/ -const handleImportFilePicker = function() { +function handleImportFilePicker() { const file = this.files[0]; if ( file === undefined || file.name === '' ) { return; } @@ -88,22 +88,22 @@ const handleImportFilePicker = function() { }; fr.readAsText(file); -}; +} /******************************************************************************/ -const startImportFilePicker = function() { +function startImportFilePicker() { const input = qs$('#restoreFilePicker'); // Reset to empty string, this will ensure an change event is properly // triggered if the user pick a file, even if it is the same as the last // one picked. input.value = ''; input.click(); -}; +} /******************************************************************************/ -const exportToFile = async function() { +async function exportToFile() { const response = await vAPI.messaging.send('dashboard', { what: 'backupUserData', }); @@ -119,11 +119,11 @@ const exportToFile = async function() { 'filename': response.localData.lastBackupFile }); onLocalDataReceived(response.localData); -}; +} /******************************************************************************/ -const onLocalDataReceived = function(details) { +function onLocalDataReceived(details) { let v, unit; if ( typeof details.storageUsed === 'number' ) { v = details.storageUsed; @@ -187,32 +187,32 @@ const onLocalDataReceived = function(details) { dom.attr('[data-setting-name="hyperlinkAuditingDisabled"]', 'disabled', ''); dom.attr('[data-setting-name="webrtcIPAddressHidden"]', 'disabled', ''); } -}; +} /******************************************************************************/ -const resetUserData = function() { +function resetUserData() { const msg = i18n$('aboutResetDataConfirm'); const proceed = window.confirm(msg); if ( proceed !== true ) { return; } vAPI.messaging.send('dashboard', { what: 'resetUserData', }); -}; +} /******************************************************************************/ -const synchronizeDOM = function() { +function synchronizeDOM() { dom.cl.toggle( dom.body, 'advancedUser', qs$('[data-setting-name="advancedUserEnabled"]').checked === true ); -}; +} /******************************************************************************/ -const changeUserSettings = function(name, value) { +function changeUserSettings(name, value) { vAPI.messaging.send('dashboard', { what: 'userSettings', name, @@ -235,11 +235,11 @@ const changeUserSettings = function(name, value) { default: break; } -}; +} /******************************************************************************/ -const onValueChanged = function(ev) { +function onValueChanged(ev) { const input = ev.target; const name = dom.attr(input, 'data-setting-name'); let value = input.value; @@ -256,14 +256,20 @@ const onValueChanged = function(ev) { } changeUserSettings(name, value); -}; +} /******************************************************************************/ // TODO: use data-* to declare simple settings -const onUserSettingsReceived = function(details) { +function onUserSettingsReceived(details) { const checkboxes = qsa$('[data-setting-type="bool"]'); + const onchange = ev => { + const checkbox = ev.target; + const name = checkbox.dataset.settingName || ''; + changeUserSettings(name, checkbox.checked); + synchronizeDOM(); + }; for ( const checkbox of checkboxes ) { const name = dom.attr(checkbox, 'data-setting-name') || ''; if ( details[name] === undefined ) { @@ -272,10 +278,7 @@ const onUserSettingsReceived = function(details) { continue; } checkbox.checked = details[name] === true; - dom.on(checkbox, 'change', ( ) => { - changeUserSettings(name, checkbox.checked); - synchronizeDOM(); - }); + dom.on(checkbox, 'change', onchange); } if ( details.canLeakLocalIPAddresses === true ) { @@ -295,6 +298,14 @@ const onUserSettingsReceived = function(details) { dom.on('#restoreFilePicker', 'change', handleImportFilePicker); synchronizeDOM(); +} + +/******************************************************************************/ + +self.wikilink = 'https://github.com/gorhill/uBlock/wiki/Dashboard:-Settings'; + +self.hasUnsavedData = function() { + return false; }; /******************************************************************************/ |