Index: lib/stats.js |
diff --git a/lib/stats.js b/lib/stats.js |
index 149a7b7a1445103539edc967858622fb6dd62bee..2101b9d8909ebc9d0a8b7ac120723cf250a0bbba 100644 |
--- a/lib/stats.js |
+++ b/lib/stats.js |
@@ -36,6 +36,17 @@ let getBlockedPerPage = |
*/ |
exports.getBlockedPerPage = page => blockedPerPage.get(page) || 0; |
+function updateBadge(page, blockedCount) |
+{ |
+ if (Prefs.show_statsinicon) |
+ { |
+ page.browserAction.setBadge(blockedCount && { |
+ color: badgeColor, |
+ number: blockedCount |
+ }); |
+ } |
+} |
+ |
// Once nagivation for the tab has been committed to (e.g. it's no longer |
// being prerendered) we clear its badge, or if some requests were already |
// blocked beforehand we display those on the badge now. |
@@ -46,10 +57,7 @@ browser.webNavigation.onCommitted.addListener(details => |
let page = new ext.Page({id: details.tabId}); |
let blocked = blockedPerPage.get(page); |
- page.browserAction.setBadge(blocked && { |
- color: badgeColor, |
- number: blocked |
- }); |
+ updateBadge(page, blocked); |
} |
}); |
@@ -62,16 +70,9 @@ FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, tabIds) => |
{ |
let page = new ext.Page({id: tabId}); |
let blocked = blockedPerPage.get(page) || 0; |
- blockedPerPage.set(page, ++blocked); |
- // Update number in icon |
- if (Prefs.show_statsinicon) |
- { |
- page.browserAction.setBadge({ |
- color: badgeColor, |
- number: blocked |
- }); |
- } |
+ blockedPerPage.set(page, ++blocked); |
+ updateBadge(page, blocked); |
} |
Prefs.blocked_total++; |
@@ -84,21 +85,11 @@ Prefs.on("show_statsinicon", () => |
for (let tab of tabs) |
{ |
let page = new ext.Page(tab); |
- let badge = null; |
if (Prefs.show_statsinicon) |
- { |
- let blocked = blockedPerPage.get(page); |
- if (blocked) |
- { |
- badge = { |
- color: badgeColor, |
- number: blocked |
- }; |
- } |
- } |
- |
- page.browserAction.setBadge(badge); |
+ updateBadge(page, blockedPerPage.get(page)); |
+ else |
+ page.browserAction.setBadge(null); |
} |
}); |
}); |