| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 /** | 26 /** |
| 27 * Get statistics for specified tab | 27 * Get statistics for specified tab |
| 28 * @param {String} key field key | 28 * @param {String} key field key |
| 29 * @param {Number} tabId tab ID (leave undefined for total stats) | 29 * @param {Number} tabId tab ID (leave undefined for total stats) |
| 30 * @return {Number} field value | 30 * @return {Number} field value |
| 31 */ | 31 */ |
| 32 let getStats = exports.getStats = function getStats(key, tabId) | 32 let getStats = exports.getStats = function getStats(key, tab) |
| 33 { | 33 { |
| 34 if (tabId) | 34 if (!tab) |
| 35 { | |
| 36 let frameData = getFrameData(tabId, 0); | |
| 37 return (frameData && key in frameData ? frameData[key] : 0); | |
| 38 } | |
| 39 else | |
| 40 return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0); | 35 return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0); |
| 36 |
| 37 let frameData = getFrameData(tab, 0); |
| 38 return (frameData && key in frameData ? frameData[key] : 0); |
| 41 }; | 39 }; |
| 42 | 40 |
| 43 FilterNotifier.addListener(function(action, item, newValue, oldValue, tab) | 41 FilterNotifier.addListener(function(action, item, newValue, oldValue, tab) |
| 44 { | 42 { |
| 45 if (action != "filter.hitCount") | 43 if (action != "filter.hitCount") |
| 46 return; | 44 return; |
| 47 | 45 |
| 48 var blocked = item instanceof BlockingFilter; | 46 var blocked = item instanceof BlockingFilter; |
| 49 | 47 |
| 50 // Increment counts | 48 // Increment counts |
| 51 if (blocked) | 49 if (blocked) |
| 52 { | 50 { |
| 53 if ("blocked" in Prefs.stats_total) | 51 if ("blocked" in Prefs.stats_total) |
| 54 Prefs.stats_total.blocked++; | 52 Prefs.stats_total.blocked++; |
| 55 else | 53 else |
| 56 Prefs.stats_total.blocked = 1; | 54 Prefs.stats_total.blocked = 1; |
| 57 Prefs.stats_total = Prefs.stats_total; | 55 Prefs.stats_total = Prefs.stats_total; |
| 58 | 56 |
| 59 let frameData = getFrameData(tab, 0); | 57 let frameData = getFrameData(tab, 0); |
| 60 if (frameData) | 58 if (frameData) |
| 61 { | 59 { |
| 62 if ("blocked" in frameData) | 60 if ("blocked" in frameData) |
| 63 frameData.blocked++; | 61 frameData.blocked++; |
| 64 else | 62 else |
| 65 frameData.blocked = 1; | 63 frameData.blocked = 1; |
| 66 } | 64 } |
| 67 } | 65 } |
| 68 }); | 66 }); |
| LEFT | RIGHT |