Index: lib/stats.js |
=================================================================== |
--- a/lib/stats.js |
+++ b/lib/stats.js |
@@ -24,26 +24,26 @@ |
let {FilterNotifier} = require("filterNotifier"); |
let badgeColor = "#646464"; |
-let statsPerTab = new TabMap(true); |
+let statsPerPage = new ext.PageMap(); |
/** |
- * Get statistics for specified tab |
+ * Get statistics for specified page |
* @param {String} key field key |
- * @param {Number} tabId tab ID (leave undefined for total stats) |
+ * @param {Page} page field page |
* @return {Number} field value |
*/ |
-let getStats = exports.getStats = function getStats(key, tab) |
+let getStats = exports.getStats = function getStats(key, page) |
{ |
- if (!tab) |
+ if (!page) |
return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0); |
- let tabStats = statsPerTab.get(tab); |
- return tabStats ? tabStats.blocked : 0; |
+ let pageStats = statsPerPage.get(page); |
+ return pageStats ? pageStats.blocked : 0; |
}; |
-FilterNotifier.addListener(function(action, item, newValue, oldValue, tab) |
+FilterNotifier.addListener(function(action, item, newValue, oldValue, page) |
{ |
- if (action != "filter.hitCount" || !tab) |
+ if (action != "filter.hitCount" || !page) |
return; |
let blocked = item instanceof BlockingFilter; |
@@ -57,66 +57,47 @@ |
Prefs.stats_total.blocked = 1; |
Prefs.stats_total = Prefs.stats_total; |
- let tabStats = statsPerTab.get(tab); |
- if (!tabStats) |
+ let pageStats = statsPerPage.get(page); |
+ if (!pageStats) |
{ |
- tabStats = {}; |
- statsPerTab.set(tab, tabStats); |
+ pageStats = {}; |
+ statsPerPage.set(page, pageStats); |
} |
- if ("blocked" in tabStats) |
- tabStats.blocked++; |
+ if ("blocked" in pageStats) |
+ pageStats.blocked++; |
else |
- tabStats.blocked = 1; |
+ pageStats.blocked = 1; |
// Update number in icon |
if (Prefs.show_statsinicon) |
{ |
- tab.browserAction.setBadge({ |
+ page.browserAction.setBadge({ |
color: badgeColor, |
- number: tabStats.blocked |
+ number: pageStats.blocked |
}); |
} |
} |
}); |
-/** |
- * Execute function for each tab in any window |
- * @param {Function} func function to be executed |
- */ |
-function forEachTab(func) |
-{ |
- ext.windows.getAll(function(windows) |
- { |
- for each (let window in windows) |
- { |
- window.getAllTabs(function(tabs) |
- { |
- for (let i = 0; i < tabs.length; i++) |
- func(tabs[i]); |
- }); |
- } |
- }); |
-} |
- |
Prefs.addListener(function(name) |
{ |
if (name != "show_statsinicon") |
return; |
- forEachTab(function(tab) |
+ ext.pages.query({}, function(page) |
{ |
let badge = null; |
if (Prefs.show_statsinicon) |
{ |
- let tabStats = statsPerTab.get(tab); |
- if (tabStats && "blocked" in tabStats) |
+ let pageStats = statsPerPage.get(page); |
+ if (pageStats && "blocked" in pageStats) |
{ |
badge = { |
color: badgeColor, |
- number: tabStats.blocked |
+ number: pageStats.blocked |
}; |
} |
} |
- tab.browserAction.setBadge(badge); |
+ page.browserAction.setBadge(badge); |
}); |
}); |