Index: lib/stats.js |
=================================================================== |
--- a/lib/stats.js |
+++ b/lib/stats.js |
@@ -22,21 +22,17 @@ |
let {FilterNotifier} = require("filterNotifier"); |
let badgeColor = "#646464"; |
-let statsPerPage = new ext.PageMap(); |
+let blockedPerPage = new ext.PageMap(); |
/** |
- * Get statistics for specified page |
- * @param {String} key field key |
- * @param {Page} page field page |
- * @return {Number} field value |
+ * Gets the number of requests blocked on the given page. |
+ * |
+ * @param {Page} page |
+ * @return {Number} |
*/ |
-exports.getStats = function(key, page) |
+exports.getBlockedPerPage = function(page) |
{ |
- if (!page) |
- return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0); |
- |
- let pageStats = statsPerPage.get(page); |
- return pageStats ? pageStats.blocked : 0; |
+ return blockedPerPage.get(page) || 0; |
}; |
FilterNotifier.addListener(function(action, item, newValue, oldValue, page) |
@@ -44,36 +40,21 @@ |
if (action != "filter.hitCount" || !page) |
return; |
- let blocked = item instanceof BlockingFilter; |
+ if (!(item instanceof BlockingFilter)) |
+ return; |
- // Increment counts |
- if (blocked) |
+ Prefs.blocked_total++; |
+ |
+ let blocked = blockedPerPage.get(page) || 0; |
+ blockedPerPage.set(page, ++blocked); |
+ |
+ // Update number in icon |
+ if (Prefs.show_statsinicon) |
{ |
- if ("blocked" in Prefs.stats_total) |
- Prefs.stats_total.blocked++; |
- else |
- Prefs.stats_total.blocked = 1; |
- Prefs.stats_total = Prefs.stats_total; |
- |
- let pageStats = statsPerPage.get(page); |
- if (!pageStats) |
- { |
- pageStats = {}; |
- statsPerPage.set(page, pageStats); |
- } |
- if ("blocked" in pageStats) |
- pageStats.blocked++; |
- else |
- pageStats.blocked = 1; |
- |
- // Update number in icon |
- if (Prefs.show_statsinicon) |
- { |
- page.browserAction.setBadge({ |
- color: badgeColor, |
- number: pageStats.blocked |
- }); |
- } |
+ page.browserAction.setBadge({ |
+ color: badgeColor, |
+ number: blocked |
+ }); |
} |
}); |
@@ -91,12 +72,12 @@ |
if (Prefs.show_statsinicon) |
{ |
- let pageStats = statsPerPage.get(page); |
- if (pageStats && "blocked" in pageStats) |
+ let blocked = blockedPerPage.get(page); |
+ if (blocked) |
{ |
badge = { |
color: badgeColor, |
- number: pageStats.blocked |
+ number: blocked |
}; |
} |
} |