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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 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')
OLDNEW
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 = "#646464";
27
26 /** 28 /**
27 * Get statistics for specified tab 29 * Get statistics for specified tab
28 * @param {String} key field key 30 * @param {String} key field key
29 * @param {Number} tabId tab ID (leave undefined for total stats) 31 * @param {Number} tabId tab ID (leave undefined for total stats)
30 * @return {Number} field value 32 * @return {Number} field value
31 */ 33 */
32 let getStats = exports.getStats = function getStats(key, tab) 34 let getStats = exports.getStats = function getStats(key, tab)
33 { 35 {
34 if (!tab) 36 if (!tab)
35 return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0); 37 return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0);
36 38
37 let frameData = getFrameData(tab, 0); 39 let frameData = getFrameData(tab, 0);
38 return (frameData && key in frameData ? frameData[key] : 0); 40 return (frameData && key in frameData ? frameData[key] : 0);
39 }; 41 };
40 42
41 FilterNotifier.addListener(function(action, item, newValue, oldValue, tab) 43 FilterNotifier.addListener(function(action, item, newValue, oldValue, tab)
42 { 44 {
43 if (action != "filter.hitCount") 45 if (action != "filter.hitCount")
44 return; 46 return;
45 47
46 var blocked = item instanceof BlockingFilter; 48 let blocked = item instanceof BlockingFilter;
47 49
48 // Increment counts 50 // Increment counts
49 if (blocked) 51 if (blocked)
50 { 52 {
51 if ("blocked" in Prefs.stats_total) 53 if ("blocked" in Prefs.stats_total)
52 Prefs.stats_total.blocked++; 54 Prefs.stats_total.blocked++;
53 else 55 else
54 Prefs.stats_total.blocked = 1; 56 Prefs.stats_total.blocked = 1;
55 Prefs.stats_total = Prefs.stats_total; 57 Prefs.stats_total = Prefs.stats_total;
56 58
57 let frameData = getFrameData(tab, 0); 59 let frameData = getFrameData(tab, 0);
58 if (frameData) 60 if (frameData)
59 { 61 {
60 if ("blocked" in frameData) 62 if ("blocked" in frameData)
61 frameData.blocked++; 63 frameData.blocked++;
62 else 64 else
63 frameData.blocked = 1; 65 frameData.blocked = 1;
64 } 66 }
67
68 // Update number in icon
69 if (Prefs.show_statsinicon)
70 {
71 tab.browserAction.setBadge({
72 color: badgeColor,
73 number: frameData.blocked
74 });
75 }
65 } 76 }
66 }); 77 });
78
79 /**
80 * Execute function for each tab in any window
81 * @param {Function} func function to be executed
Felix Dahlke 2013/12/13 13:57:20 s/ / / s'il vous plaît.
82 */
83 function forEachTab(func)
84 {
85 ext.windows.getAll(function(windows)
86 {
87 for each (let window in windows)
88 {
89 window.getAllTabs(function(tabs)
90 {
91 for (let i = 0; i < tabs.length; i++)
92 func(tabs[i]);
93 });
94 }
95 });
96 }
97
98 Prefs.addListener(function(name)
99 {
100 if (name != "show_statsinicon")
101 return;
102
103 forEachTab(function(tab)
104 {
105 let badge = null;
106 if (Prefs.show_statsinicon)
107 {
108 let frameData = getFrameData(tab, 0);
109 if (frameData && "blocked" in frameData)
110 {
111 badge = {
112 color: badgeColor,
113 number: frameData.blocked
114 };
115 }
116 }
117 tab.browserAction.setBadge(badge);
118 });
119 });
OLDNEW
« no previous file with comments | « lib/prefs.js ('k') | metadata.chrome » ('j') | skin/popup.css » ('J')

Powered by Google App Engine
This is Rietveld