stylus/messaging.js

23 lines
697 B
JavaScript
Raw Normal View History

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) {
chrome.tabs.sendMessage(tab.id, request);
2012-04-16 01:56:12 +00:00
updateBadgeText(tab);
});
});
});
}
function updateBadgeText(tab) {
chrome.extension.sendMessage({method: "getStyles", matchUrl: tab.url, enabled: true}, function(styles) {
var t = getBadgeText(styles);
console.log("Tab " + tab.id + " (" + tab.url + ") badge text set to '" + t + "'.");
chrome.browserAction.setBadgeText({text: t, tabId: tab.id});
2012-04-16 01:56:12 +00:00
});
}
function getBadgeText(styles) {
return styles.length == 0 ? "" : ("" + styles.length);
2012-04-16 01:56:12 +00:00
}