From 6b49afaa484406cc7ff1fe13d7c54b4e332e0098 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 14 Mar 2017 15:18:58 +0300 Subject: [PATCH] Apply enable/disable state of style to popup itself --- apply.js | 6 ++++-- messaging.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apply.js b/apply.js index 319211a4..eae0a738 100644 --- a/apply.js +++ b/apply.js @@ -22,7 +22,9 @@ function requestStyles() { 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 switch (request.method == "updatePopup" ? request.reason : request.method) { case "styleDeleted": @@ -51,7 +53,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { disableAll(request.disableAll); break; } -}); +} function disableAll(disable) { if (!disable === !g_disableAll) { diff --git a/messaging.js b/messaging.js index 6e378546..1f818ab3 100644 --- a/messaging.js +++ b/messaging.js @@ -10,6 +10,10 @@ function notifyAllTabs(request) { // notify all open popups var reqPopup = shallowMerge({}, request, {method: "updatePopup", reason: request.method}); 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) {