Change: drop prefChanged, use prefs service

This commit is contained in:
eight 2018-10-04 18:05:41 +08:00
parent 10f9449144
commit 8a6e8ac03a
4 changed files with 15 additions and 27 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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/*"],

View File

@ -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}));
}