Apply enable/disable state of style to popup itself

This commit is contained in:
tophf 2017-03-14 15:18:58 +03:00
parent 94836b92d7
commit 6b49afaa48
2 changed files with 8 additions and 2 deletions

View File

@ -22,7 +22,9 @@ function requestStyles() {
chrome.runtime.sendMessage(request, applyStyles); chrome.runtime.sendMessage(request, applyStyles);
} }
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { chrome.runtime.onMessage.addListener(applyOnMessage);
function applyOnMessage(request, sender, sendResponse) {
// Also handle special request just for the pop-up // Also handle special request just for the pop-up
switch (request.method == "updatePopup" ? request.reason : request.method) { switch (request.method == "updatePopup" ? request.reason : request.method) {
case "styleDeleted": case "styleDeleted":
@ -51,7 +53,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
disableAll(request.disableAll); disableAll(request.disableAll);
break; break;
} }
}); }
function disableAll(disable) { function disableAll(disable) {
if (!disable === !g_disableAll) { if (!disable === !g_disableAll) {

View File

@ -10,6 +10,10 @@ function notifyAllTabs(request) {
// notify all open popups // notify all open popups
var reqPopup = shallowMerge({}, request, {method: "updatePopup", reason: request.method}); var reqPopup = shallowMerge({}, request, {method: "updatePopup", reason: request.method});
chrome.runtime.sendMessage(reqPopup); chrome.runtime.sendMessage(reqPopup);
// notify self: the message no longer is sent to the origin in new Chrome
if (typeof applyOnMessage !== 'undefined') {
applyOnMessage(reqPopup);
}
} }
function updateIcon(tab, styles) { function updateIcon(tab, styles) {