Merge pull request #93 from tophf/apply-styles-to-popup

Apply styles to popup on change/disableAll
This commit is contained in:
Jason Barnabe 2015-04-07 12:16:23 -05:00
commit cd14e6d462
6 changed files with 13 additions and 6 deletions

View File

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

View File

@ -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) {

View File

@ -694,7 +694,6 @@ function saveComplete(style) {
} else {
updateTitle();
}
chrome.extension.sendMessage({method: "updatePopup", reason: "styleUpdated", style: style});
}
function showMozillaFormat() {

View File

@ -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) {

View File

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

View File

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