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

Side by Side Diff: lib/stats.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Fix scoping regression Created Jan. 16, 2017, 9:12 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module stats */ 18 /** @module stats */
19 19
20 "use strict";
21
20 let {Prefs} = require("prefs"); 22 let {Prefs} = require("prefs");
21 let {BlockingFilter} = require("filterClasses"); 23 let {BlockingFilter} = require("filterClasses");
22 let {FilterNotifier} = require("filterNotifier"); 24 let {FilterNotifier} = require("filterNotifier");
23 25
24 let badgeColor = "#646464"; 26 let badgeColor = "#646464";
25 let blockedPerPage = new ext.PageMap(); 27 let blockedPerPage = new ext.PageMap();
26 28
27 /** 29 /**
28 * Gets the number of requests blocked on the given page. 30 * Gets the number of requests blocked on the given page.
29 * 31 *
30 * @param {Page} page 32 * @param {Page} page
31 * @return {Number} 33 * @return {Number}
32 */ 34 */
33 exports.getBlockedPerPage = function(page) 35 exports.getBlockedPerPage = page => blockedPerPage.get(page) || 0;
34 {
35 return blockedPerPage.get(page) || 0;
36 };
37 36
38 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) => 37 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) =>
39 { 38 {
40 if (!(filter instanceof BlockingFilter) || !page) 39 if (!(filter instanceof BlockingFilter) || !page)
41 return; 40 return;
42 41
43 Prefs.blocked_total++; 42 Prefs.blocked_total++;
44 43
45 let blocked = blockedPerPage.get(page) || 0; 44 let blocked = blockedPerPage.get(page) || 0;
46 blockedPerPage.set(page, ++blocked); 45 blockedPerPage.set(page, ++blocked);
47 46
48 // Update number in icon 47 // Update number in icon
49 if (Prefs.show_statsinicon) 48 if (Prefs.show_statsinicon)
50 { 49 {
51 page.browserAction.setBadge({ 50 page.browserAction.setBadge({
52 color: badgeColor, 51 color: badgeColor,
53 number: blocked 52 number: blocked
54 }); 53 });
55 } 54 }
56 }); 55 });
57 56
58 Prefs.on("show_statsinicon", () => 57 Prefs.on("show_statsinicon", () =>
59 { 58 {
60 ext.pages.query({}, function(pages) 59 ext.pages.query({}, pages =>
61 { 60 {
62 for (var i = 0; i < pages.length; i++) 61 for (let page of pages)
63 { 62 {
64 let page = pages[i];
65 let badge = null; 63 let badge = null;
66 64
67 if (Prefs.show_statsinicon) 65 if (Prefs.show_statsinicon)
68 { 66 {
69 let blocked = blockedPerPage.get(page); 67 let blocked = blockedPerPage.get(page);
70 if (blocked) 68 if (blocked)
71 { 69 {
72 badge = { 70 badge = {
73 color: badgeColor, 71 color: badgeColor,
74 number: blocked 72 number: blocked
75 }; 73 };
76 } 74 }
77 } 75 }
78 76
79 page.browserAction.setBadge(badge); 77 page.browserAction.setBadge(badge);
80 } 78 }
81 }); 79 });
82 }); 80 });
OLDNEW
« lib/notificationHelper.js ('K') | « lib/requestBlocker.js ('k') | lib/subscriptionInit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld