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: Merged setBadgeNumber and setBadgeBackgroundColor Created Dec. 13, 2013, 10:36 a.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
« no previous file with comments | « lib/prefs.js ('k') | metadata.chrome » ('j') | skin/popup.css » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,56 @@
else
frameData.blocked = 1;
}
+
+ // Update number in icon
+ if (Prefs.show_statsinicon)
+ {
+ tab.browserAction.setBadge({
+ color: badgeColor,
+ number: frameData.blocked
+ });
+ }
}
});
+
+/**
+ * Execute function for each tab in any window
+ * @param {Function} func function to be executed
Felix Dahlke 2013/12/13 13:57:20 s/ / / s'il vous plaît.
+ */
+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;
+
+ forEachTab(function(tab)
+ {
+ let badge = null;
+ if (Prefs.show_statsinicon)
+ {
+ let frameData = getFrameData(tab, 0);
+ if (frameData && "blocked" in frameData)
+ {
+ badge = {
+ color: badgeColor,
+ number: frameData.blocked
+ };
+ }
+ }
+ tab.browserAction.setBadge(badge);
+ });
+});
« no previous file with comments | « lib/prefs.js ('k') | metadata.chrome » ('j') | skin/popup.css » ('J')

Powered by Google App Engine
This is Rietveld