diff --git a/content/apply.js b/content/apply.js index d18b0a22..9f5c66dc 100644 --- a/content/apply.js +++ b/content/apply.js @@ -34,6 +34,9 @@ window.addEventListener(chrome.runtime.id, orphanCheck, true); } + prefs.subscribe(['disableAll'], (key, value) => doDisableAll(value)); + prefs.subscribe(['exposeIframes'], (key, value) => doExposeIframes(value)); + function requestStyles(options, callback = applyStyles) { if (!chrome.app && document instanceof XMLDocument) { chrome.runtime.sendMessage({method: 'styleViaAPI', action: 'styleApply'}); @@ -140,15 +143,6 @@ replaceAll(request.styles); break; - case 'prefChanged': - if ('disableAll' in request.prefs) { - doDisableAll(request.prefs.disableAll); - } - if ('exposeIframes' in request.prefs) { - doExposeIframes(request.prefs.exposeIframes); - } - break; - case 'ping': sendResponse(true); break; diff --git a/edit/edit.js b/edit/edit.js index 8e62f9c6..90668561 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -55,6 +55,9 @@ Promise.all([ } }); +prefs.subscribe(['editor.smartIndent'], (key, value) => + CodeMirror.setOption('smartIndent', value)); + function preinit() { // make querySelectorAll enumeration code readable ['forEach', 'some', 'indexOf', 'map'].forEach(method => { @@ -183,11 +186,6 @@ function onRuntimeMessage(request) { break; } break; - case 'prefChanged': - if ('editor.smartIndent' in request.prefs) { - CodeMirror.setOption('smartIndent', request.prefs['editor.smartIndent']); - } - break; case 'editDeleteText': document.execCommand('delete'); break; diff --git a/manifest.json b/manifest.json index 055e4533..46e29f54 100644 --- a/manifest.json +++ b/manifest.json @@ -58,7 +58,7 @@ "run_at": "document_start", "all_frames": true, "match_about_blank": true, - "js": ["content/apply.js"] + "js": ["js/prefs.js", "content/apply.js"] }, { "matches": ["http://userstyles.org/*", "https://userstyles.org/*"], diff --git a/popup/popup.js b/popup/popup.js index bea9498d..f7909e46 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -28,6 +28,14 @@ getActiveTab().then(tab => chrome.runtime.onMessage.addListener(onRuntimeMessage); +prefs.subscribe(['popup.stylesFirst'], (key, stylesFirst) => { + const actions = $('body > .actions'); + const before = stylesFirst ? actions : actions.nextSibling; + document.body.insertBefore(installed, before); +}); +prefs.subscribe(['popupWidth'], (key, value) => setPopupWidth(value)); +prefs.subscribe(['popup.borders'], (key, value) => toggleSideBorders(value)); + function onRuntimeMessage(msg) { switch (msg.method) { case 'styleAdded': @@ -38,18 +46,6 @@ function onRuntimeMessage(msg) { case 'styleDeleted': handleDelete(msg.id); break; - case 'prefChanged': - if ('popup.stylesFirst' in msg.prefs) { - const stylesFirst = msg.prefs['popup.stylesFirst']; - 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); - } else if ('popup.borders' in msg.prefs) { - toggleSideBorders(msg.prefs['popup.borders']); - } - break; } dispatchEvent(new CustomEvent(msg.method, {detail: msg})); }