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

Delta Between Two Patch Sets: lib/stats.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Left Patch Set: Applied Sebastian's suggestions and updated strings Created Nov. 26, 2013, 4:18 p.m.
Right Patch Set: Merged setBadgeNumber and setBadgeBackgroundColor Created Dec. 13, 2013, 10:36 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/prefs.js ('k') | metadata.chrome » ('j') | skin/popup.css » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Provides usage stats 19 * @fileOverview Provides usage stats
20 */ 20 */
21 21
22 let {Prefs} = require("prefs"); 22 let {Prefs} = require("prefs");
23 let {BlockingFilter} = require("filterClasses"); 23 let {BlockingFilter} = require("filterClasses");
24 let {FilterNotifier} = require("filterNotifier"); 24 let {FilterNotifier} = require("filterNotifier");
25 25
26 let badgeColor = [100, 100, 100, 255]; 26 let badgeColor = "#646464";
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.
27 27
28 /** 28 /**
29 * Get statistics for specified tab 29 * Get statistics for specified tab
30 * @param {String} key field key 30 * @param {String} key field key
31 * @param {Number} tabId tab ID (leave undefined for total stats) 31 * @param {Number} tabId tab ID (leave undefined for total stats)
32 * @return {Number} field value 32 * @return {Number} field value
33 */ 33 */
34 let getStats = exports.getStats = function getStats(key, tab) 34 let getStats = exports.getStats = function getStats(key, tab)
35 { 35 {
36 if (!tab) 36 if (!tab)
(...skipping 22 matching lines...) Expand all
59 let frameData = getFrameData(tab, 0); 59 let frameData = getFrameData(tab, 0);
60 if (frameData) 60 if (frameData)
61 { 61 {
62 if ("blocked" in frameData) 62 if ("blocked" in frameData)
63 frameData.blocked++; 63 frameData.blocked++;
64 else 64 else
65 frameData.blocked = 1; 65 frameData.blocked = 1;
66 } 66 }
67 67
68 // Update number in icon 68 // Update number in icon
69 if (Prefs.show_iconnumber) 69 if (Prefs.show_statsinicon)
70 { 70 {
71 tab.browserAction.setBadgeBackgroundColor(badgeColor); 71 tab.browserAction.setBadge({
72 tab.browserAction.setBadgeNumber(frameData.blocked); 72 color: badgeColor,
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.
73 number: frameData.blocked
74 });
73 } 75 }
74 } 76 }
75 }); 77 });
76 78
77 /** 79 /**
78 * Execute function for each tab in any window 80 * Execute function for each tab in any window
79 * @param {Function} func function to be executed 81 * @param {Function} func function to be executed
Felix Dahlke 2013/12/13 13:57:20 s/ / / s'il vous plaît.
80 */ 82 */
81 function forEachTab(func) 83 function forEachTab(func)
82 { 84 {
83 ext.windows.getAll(function(windows) 85 ext.windows.getAll(function(windows)
84 { 86 {
85 for (let i = 0; i < windows.length; i++) 87 for each (let window in windows)
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.
86 { 88 {
87 windows[i].getAllTabs(function(tabs) 89 window.getAllTabs(function(tabs)
88 { 90 {
89 for (let i = 0; i < tabs.length; i++) 91 for (let i = 0; i < tabs.length; i++)
90 func(tabs[i]); 92 func(tabs[i]);
91 }); 93 });
92 } 94 }
93 }); 95 });
94 } 96 }
95 97
96 Prefs.addListener(function(name) 98 Prefs.addListener(function(name)
97 { 99 {
98 if (name != "show_iconnumber") 100 if (name != "show_statsinicon")
99 return; 101 return;
100 102
101 if (Prefs.show_iconnumber) 103 forEachTab(function(tab)
102 { 104 {
103 // Add number to icon 105 let badge = null;
104 forEachTab(function(tab) { 106 if (Prefs.show_statsinicon)
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.
105 tab.browserAction.setBadgeBackgroundColor(badgeColor); 107 {
106
107 let frameData = getFrameData(tab, 0); 108 let frameData = getFrameData(tab, 0);
108 if (frameData && "blocked" in frameData) 109 if (frameData && "blocked" in frameData)
109 tab.browserAction.setBadgeNumber(frameData.blocked); 110 {
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.
110 }); 111 badge = {
111 } 112 color: badgeColor,
112 else 113 number: frameData.blocked
113 { 114 };
114 // Remove number from icon 115 }
115 forEachTab(function(tab) 116 }
116 { 117 tab.browserAction.setBadge(badge);
117 tab.browserAction.setBadgeNumber(null); 118 });
118 });
119 }
120 }); 119 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld