Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/stats.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Patch Set: Applied Sebastian's suggestions and updated strings Created Nov. 26, 2013, 4:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 = [100, 100, 100, 255];
Wladimir Palant 2013/12/03 12:55:43 I'd prefer "#606060" here - it's more compact and
Thomas Greiner 2013/12/04 10:44:50 Done.
+
/**
* 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,57 @@
else
frameData.blocked = 1;
}
+
+ // Update number in icon
+ if (Prefs.show_iconnumber)
+ {
+ tab.browserAction.setBadgeBackgroundColor(badgeColor);
+ tab.browserAction.setBadgeNumber(frameData.blocked);
Wladimir Palant 2013/12/03 12:55:43 Will this count be automatically removed if the ta
Thomas Greiner 2013/12/04 10:44:50 Yes, it gets reset implicitly.
+ }
}
});
+
+/**
+ * Execute function for each tab in any window
+ * @param {Function} func function to be executed
+ */
+function forEachTab(func)
+{
+ ext.windows.getAll(function(windows)
+ {
+ for (let i = 0; i < windows.length; i++)
Wladimir Palant 2013/12/03 12:55:43 |for each (let window in windows)| should be a bet
Thomas Greiner 2013/12/04 10:44:50 Done.
+ {
+ windows[i].getAllTabs(function(tabs)
+ {
+ for (let i = 0; i < tabs.length; i++)
+ func(tabs[i]);
+ });
+ }
+ });
+}
+
+Prefs.addListener(function(name)
+{
+ if (name != "show_iconnumber")
+ return;
+
+ if (Prefs.show_iconnumber)
+ {
+ // Add number to icon
+ forEachTab(function(tab) {
Felix Dahlke 2013/12/02 15:45:58 Opening brace should go on the next line.
Thomas Greiner 2013/12/03 12:06:05 Done.
+ tab.browserAction.setBadgeBackgroundColor(badgeColor);
+
+ let frameData = getFrameData(tab, 0);
+ if (frameData && "blocked" in frameData)
+ tab.browserAction.setBadgeNumber(frameData.blocked);
Felix Dahlke 2013/12/02 15:45:58 Shouldn't we set the badge number to null explicit
Thomas Greiner 2013/12/03 12:06:05 The value is already null when we get here (either
Felix Dahlke 2013/12/04 12:30:06 True, fine like this then.
Thomas Greiner 2013/12/10 10:09:29 Done.
+ });
+ }
+ else
+ {
+ // Remove number from icon
+ forEachTab(function(tab)
+ {
+ tab.browserAction.setBadgeNumber(null);
+ });
+ }
+});

Powered by Google App Engine
This is Rietveld