Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/stats.js

Issue 29785558: Issue 6679 - Don't show block stats in icon if disabled (Closed)
Patch Set: Split logic out into separate function Created May 18, 2018, 12:24 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
});
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld