Index: lib/stats.js |
=================================================================== |
--- a/lib/stats.js |
+++ b/lib/stats.js |
@@ -23,6 +23,8 @@ |
let {BlockingFilter} = require("filterClasses"); |
let {FilterNotifier} = require("filterNotifier"); |
+let badgeColor = "#646464"; |
+ |
/** |
* Get statistics for specified tab |
* @param {String} key field key |
@@ -43,7 +45,7 @@ |
if (action != "filter.hitCount") |
return; |
- var blocked = item instanceof BlockingFilter; |
+ let blocked = item instanceof BlockingFilter; |
// Increment counts |
if (blocked) |
@@ -62,5 +64,58 @@ |
else |
frameData.blocked = 1; |
} |
+ |
+ // Update number in icon |
+ if (Prefs.show_statsinicon) |
+ { |
+ tab.browserAction.setBadgeBackgroundColor(badgeColor); |
+ tab.browserAction.setBadgeNumber(frameData.blocked); |
+ } |
} |
}); |
+ |
+/** |
+ * Execute function for each tab in any window |
+ * @param {Function} func function to be executed |
+ */ |
+function forEachTab(func) |
+{ |
+ ext.windows.getAll(function(windows) |
+ { |
+ for each (let window in windows) |
+ { |
+ window.getAllTabs(function(tabs) |
+ { |
+ for (let i = 0; i < tabs.length; i++) |
+ func(tabs[i]); |
+ }); |
+ } |
+ }); |
+} |
+ |
+Prefs.addListener(function(name) |
+{ |
+ if (name != "show_statsinicon") |
+ return; |
+ |
+ if (Prefs.show_statsinicon) |
+ { |
+ // Add number to icon |
+ forEachTab(function(tab) |
+ { |
+ tab.browserAction.setBadgeBackgroundColor(badgeColor); |
+ |
+ let frameData = getFrameData(tab, 0); |
+ if (frameData && "blocked" in frameData) |
+ tab.browserAction.setBadgeNumber(frameData.blocked); |
+ }); |
+ } |
+ else |
+ { |
+ // Remove number from icon |
+ forEachTab(function(tab) |
+ { |
+ tab.browserAction.setBadgeNumber(null); |
+ }); |
+ } |
+}); |