| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 /* | 
|  | 2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
|  | 3  * Copyright (C) 2006-2013 Eyeo GmbH | 
|  | 4  * | 
|  | 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 | 
|  | 7  * published by the Free Software Foundation. | 
|  | 8  * | 
|  | 9  * Adblock Plus is distributed in the hope that it will be useful, | 
|  | 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 12  * GNU General Public License for more details. | 
|  | 13  * | 
|  | 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/>. | 
|  | 16  */ | 
|  | 17 | 
|  | 18 /** | 
|  | 19  * @fileOverview Provides usage stats | 
|  | 20  */ | 
|  | 21 | 
|  | 22 let {Prefs} = require("prefs"); | 
|  | 23 let {BlockingFilter} = require("filterClasses"); | 
|  | 24 let {FilterNotifier} = require("filterNotifier"); | 
|  | 25 | 
|  | 26 /** | 
|  | 27  * Get statistics for specified tab | 
|  | 28  * @param  {String} key   field key | 
|  | 29  * @param  {Number} tabId tab ID (leave undefined for total stats) | 
|  | 30  * @return {Number}       field value | 
|  | 31  */ | 
|  | 32 let getStats = exports.getStats = function getStats(key, tabId) | 
|  | 33 { | 
|  | 34   if (tabId) | 
|  | 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); | 
|  | 41 }; | 
|  | 42 | 
|  | 43 FilterNotifier.addListener(function(action, item, newValue, oldValue, tabId) | 
|  | 44 { | 
|  | 45   if (action != "filter.hitCount") | 
|  | 46     return; | 
|  | 47 | 
|  | 48   var blocked = item instanceof BlockingFilter; | 
|  | 49 | 
|  | 50   // Increment counts | 
|  | 51   if (blocked) | 
|  | 52   { | 
|  | 53     if ("blocked" in Prefs.stats_total) | 
|  | 54       Prefs.stats_total.blocked++; | 
|  | 55     else | 
|  | 56       Prefs.stats_total.blocked = 1; | 
|  | 57 | 
|  | 58     let frameData = getFrameData(tabId, 0); | 
|  | 59     if (frameData) | 
|  | 60     { | 
|  | 61       if ("blocked" in frameData) | 
|  | 62         frameData.blocked++; | 
|  | 63       else | 
|  | 64         frameData.blocked = 1; | 
|  | 65     } | 
|  | 66   } | 
|  | 67 }); | 
| OLD | NEW | 
|---|