2012-04-16 01:56:12 +00:00
|
|
|
function notifyAllTabs(request) {
|
|
|
|
chrome.windows.getAll({populate: true}, function(windows) {
|
|
|
|
windows.forEach(function(win) {
|
|
|
|
win.tabs.forEach(function(tab) {
|
2012-08-20 01:14:33 +00:00
|
|
|
chrome.tabs.sendMessage(tab.id, request);
|
2012-04-16 01:56:12 +00:00
|
|
|
updateBadgeText(tab);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateBadgeText(tab) {
|
2015-03-03 23:04:27 +00:00
|
|
|
if (prefs.getPref("show-badge")) {
|
2014-02-08 03:49:08 +00:00
|
|
|
function stylesReceived(styles) {
|
2014-02-08 02:04:06 +00:00
|
|
|
var t = getBadgeText(styles);
|
|
|
|
console.log("Tab " + tab.id + " (" + tab.url + ") badge text set to '" + t + "'.");
|
|
|
|
chrome.browserAction.setBadgeText({text: t, tabId: tab.id});
|
2014-02-08 03:49:08 +00:00
|
|
|
}
|
|
|
|
// if we have access to this, call directly. a page sending a message to itself doesn't seem to work right.
|
|
|
|
if (typeof getStyles != "undefined") {
|
|
|
|
getStyles({matchUrl: tab.url, enabled: true}, stylesReceived);
|
|
|
|
} else {
|
|
|
|
chrome.extension.sendMessage({method: "getStyles", matchUrl: tab.url, enabled: true}, stylesReceived);
|
|
|
|
}
|
2014-02-08 02:04:06 +00:00
|
|
|
} else {
|
|
|
|
chrome.browserAction.setBadgeText({text: "", tabId: tab.id});
|
|
|
|
}
|
2012-04-16 01:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBadgeText(styles) {
|
2012-08-20 01:14:33 +00:00
|
|
|
return styles.length == 0 ? "" : ("" + styles.length);
|
2012-04-16 01:56:12 +00:00
|
|
|
}
|