diff --git a/apply.js b/apply.js index 3e34dba9..64fe523e 100644 --- a/apply.js +++ b/apply.js @@ -6,7 +6,8 @@ if (location.href.indexOf(chrome.extension.getURL("")) == 0) { } chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { - switch (request.method) { + // Also handle special request just for the pop-up + switch (request.method == "updatePopup" ? request.reason : request.method) { case "styleDeleted": removeStyle(request.id, document); break; diff --git a/background.js b/background.js index 1284d5a5..95b97b82 100644 --- a/background.js +++ b/background.js @@ -82,7 +82,6 @@ function disableAllStylesToggle(newState) { } prefs.setPref("disableAll", newState); notifyAllTabs({method: "styleDisableAll", disableAll: newState}); - chrome.extension.sendMessage({method: "updatePopup", reason: "styleDisableAll", disableAll: newState}); } function getStyles(options, callback) { diff --git a/edit.js b/edit.js index 690f937f..e0e6f44a 100644 --- a/edit.js +++ b/edit.js @@ -694,7 +694,6 @@ function saveComplete(style) { } else { updateTitle(); } - chrome.extension.sendMessage({method: "updatePopup", reason: "styleUpdated", style: style}); } function showMozillaFormat() { diff --git a/messaging.js b/messaging.js index 6674bd72..6921f1f0 100644 --- a/messaging.js +++ b/messaging.js @@ -7,6 +7,13 @@ function notifyAllTabs(request) { }); }); }); + // notify all open popups + // use a shallow copy since the original `request` is still being processed + var reqPopup = {}; + for (var k in request) reqPopup[k] = request[k]; + reqPopup.reason = request.method; + reqPopup.method = "updatePopup"; + chrome.extension.sendMessage(reqPopup); } function updateBadgeText(tab) { diff --git a/popup.js b/popup.js index 72bcd745..de1f8e62 100644 --- a/popup.js +++ b/popup.js @@ -177,6 +177,10 @@ function handleUpdate(style) { var styleElement = installed.querySelector("[style-id='" + style.id + "']"); if (styleElement) { installed.replaceChild(createStyleElement(style), styleElement); + } else if (chrome.extension.getBackgroundPage().getApplicableSections(style, location.href).length) { + // a new style for the current url is installed + document.getElementById("unavailable").style.display = "none"; + installed.appendChild(createStyleElement(style)); } } @@ -221,5 +225,4 @@ loadPrefs({"disableAll": false}); handleDisableAll(prefs.getPref("disableAll")); document.getElementById("disableAll").addEventListener("change", function(event) { notifyAllTabs({method: "styleDisableAll", disableAll: event.target.checked}); - chrome.extension.sendMessage({method: "updatePopup", reason: "styleDisableAll", disableAll: event.target.checked}); }); diff --git a/storage.js b/storage.js index 85a968bd..a60254d6 100644 --- a/storage.js +++ b/storage.js @@ -81,7 +81,6 @@ function enableStyle(id, enabled) { chrome.extension.sendMessage({method: "getStyles", id: id}, function(styles) { handleUpdate(styles[0]); notifyAllTabs({method: "styleUpdated", style: styles[0]}); - chrome.extension.sendMessage({method: "updatePopup", reason: "styleUpdated", style: styles[0]}); }); }); }); @@ -95,7 +94,6 @@ function deleteStyle(id) { t.executeSql("DELETE FROM styles WHERE id = ?;", [id]); }, reportError, function() { chrome.extension.sendMessage({method: "styleChanged"}); - chrome.extension.sendMessage({method: "updatePopup", reason: "styleDeleted", id: id}); handleDelete(id); notifyAllTabs({method: "styleDeleted", id: id}); });