| LEFT | RIGHT |
| 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"; |
| 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 Loading... |
| 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.setBadgeText(frameData.blocked.toString()); | 72 color: badgeColor, |
| 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 |
| 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) |
| 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) |
| 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.setBadgeText(frameData.blocked.toString()); | 110 { |
| 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.setBadgeText(""); | 118 }); |
| 118 }); | |
| 119 } | |
| 120 }); | 119 }); |
| LEFT | RIGHT |