diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 46eb7ae4..e13a9670 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -550,11 +550,8 @@ "optionsActions": { "message": "Actions" }, - "optionsSave": { - "message": "Save" - }, - "optionsSaved": { - "message": "Options saved." + "optionsReset": { + "message": "Reset" }, "optionsOpenManager": { "message": "Open styles manager" diff --git a/options/index.css b/options/index.css index 678b6bc9..ffbb0fc8 100644 --- a/options/index.css +++ b/options/index.css @@ -53,24 +53,11 @@ input[type=number] { margin-top: -2em; } -#save { +#reset { text-align: right; position: relative; } -#save-status { - margin-top: .5ex; - position: absolute; - right: 0; - visibility: hidden; -} - -#save-status.fadeinout { - visibility: visible; - animation: fadeinout 1s ease-in-out; - animation-fill-mode: both; -} - #notes { background-color: #f4f4f4; margin-top: .75rem; diff --git a/options/index.html b/options/index.html index 31ec2ab0..7b92a0d6 100644 --- a/options/index.html +++ b/options/index.html @@ -49,9 +49,8 @@ -
- -
+
+
diff --git a/options/index.js b/options/index.js index ef581b09..22147898 100644 --- a/options/index.js +++ b/options/index.js @@ -2,31 +2,15 @@ 'use strict'; -function restore() { - setupLivePrefs([ - 'show-badge', - 'popup.stylesFirst' - ]); - //$('#show-badge').value = bg.prefs.get('show-badge'); - $('#badgeDisabled').value = prefs.get('badgeDisabled'); - $('#badgeNormal').value = prefs.get('badgeNormal'); - $('#popupWidth').value = prefs.get('popupWidth'); - $('#updateInterval').value = prefs.get('updateInterval'); - enforceValueRange('popupWidth'); -} - - -function save() { - prefs.set('badgeDisabled', $('#badgeDisabled').value); - prefs.set('badgeNormal', $('#badgeNormal').value); - prefs.set('popupWidth', enforceValueRange('popupWidth')); - prefs.set( - 'updateInterval', - Math.max(0, Number($('#updateInterval').value)) - ); - animateElement($('#save-status'), {className: 'fadeinout'}); -} - +setupLivePrefs([ + 'show-badge', + 'popup.stylesFirst', + 'badgeNormal', + 'badgeDisabled', + 'popupWidth', + 'updateInterval', +]); +enforceValueRange('popupWidth'); function enforceValueRange(id) { const element = document.getElementById(id); @@ -41,10 +25,6 @@ function enforceValueRange(id) { return value | 0; } - -restore(); -$('#save').onclick = save; - // overwrite the default URL if browser is Opera $('[data-cmd="open-keyboard"]').href = configureCommands.url; @@ -104,5 +84,10 @@ document.onclick = e => { configureCommands.open(); break; + case 'reset': + $$('input') + .filter(input => input.id in prefs.readOnlyValues) + .forEach(input => prefs.reset(input.id)); + break; } }; diff --git a/popup.js b/popup.js index b4b74a9e..e887bebd 100644 --- a/popup.js +++ b/popup.js @@ -33,18 +33,24 @@ chrome.runtime.onMessage.addListener(msg => { const actions = $('body > .actions'); const before = stylesFirst ? actions : actions.nextSibling; document.body.insertBefore(installed, before); + } else if ('popupWidth' in msg.prefs) { + setPopupWidth(msg.prefs.popupWidth); } break; } }); +function setPopupWidth(width = prefs.get('popupWidth')) { + document.body.style.width = + Math.max(200, Math.min(800, width)) + 'px'; +} + + function initPopup(url) { installed = $('#installed'); - // popup width - document.body.style.width = - Math.max(200, Math.min(800, prefs.get('popupWidth'))) + 'px'; + setPopupWidth(); // force Chrome to resize the popup document.body.style.height = '10px'; diff --git a/storage.js b/storage.js index fa8f303a..dbb435bc 100644 --- a/storage.js +++ b/storage.js @@ -652,6 +652,8 @@ prefs = prefs || new function Prefs() { remove: key => this.set(key, undefined), + reset: key => this.set(key, deepCopy(defaults[key])), + broadcast(key, value, {noSync} = {}) { broadcastPrefs[key] = value; debounce(doBroadcast);