From d4382d3f085c10d2517543e1ba9449f52326c562 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 7 Apr 2015 20:07:45 +0300 Subject: [PATCH 1/2] Apply global changes to popups --- apply.js | 3 ++- background.js | 1 - edit.js | 1 - messaging.js | 7 +++++++ popup.js | 1 - storage.js | 2 -- 6 files changed, 9 insertions(+), 6 deletions(-) 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..0a36e541 100644 --- a/popup.js +++ b/popup.js @@ -221,5 +221,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}); }); From 5b0d8fbba0fe3b378d3d07bba07f3cfa60608137 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 7 Apr 2015 20:14:14 +0300 Subject: [PATCH 2/2] Show a newly installed style in popups --- popup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/popup.js b/popup.js index 0a36e541..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)); } }