OLD | NEW |
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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 * Gets the number of requests blocked on the given page. | 28 * Gets the number of requests blocked on the given page. |
29 * | 29 * |
30 * @param {Page} page | 30 * @param {Page} page |
31 * @return {Number} | 31 * @return {Number} |
32 */ | 32 */ |
33 exports.getBlockedPerPage = function(page) | 33 exports.getBlockedPerPage = function(page) |
34 { | 34 { |
35 return blockedPerPage.get(page) || 0; | 35 return blockedPerPage.get(page) || 0; |
36 }; | 36 }; |
37 | 37 |
38 FilterNotifier.addListener(function(action, item, newValue, oldValue, page) | 38 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) => |
39 { | 39 { |
40 if (action != "filter.hitCount" || !page) | 40 if (!(filter instanceof BlockingFilter) || !page) |
41 return; | |
42 | |
43 if (!(item instanceof BlockingFilter)) | |
44 return; | 41 return; |
45 | 42 |
46 Prefs.blocked_total++; | 43 Prefs.blocked_total++; |
47 | 44 |
48 let blocked = blockedPerPage.get(page) || 0; | 45 let blocked = blockedPerPage.get(page) || 0; |
49 blockedPerPage.set(page, ++blocked); | 46 blockedPerPage.set(page, ++blocked); |
50 | 47 |
51 // Update number in icon | 48 // Update number in icon |
52 if (Prefs.show_statsinicon) | 49 if (Prefs.show_statsinicon) |
53 { | 50 { |
54 page.browserAction.setBadge({ | 51 page.browserAction.setBadge({ |
55 color: badgeColor, | 52 color: badgeColor, |
56 number: blocked | 53 number: blocked |
57 }); | 54 }); |
58 } | 55 } |
59 }); | 56 }); |
60 | 57 |
61 Prefs.on("show_statsinicon", function() | 58 Prefs.on("show_statsinicon", () => |
62 { | 59 { |
63 ext.pages.query({}, function(pages) | 60 ext.pages.query({}, function(pages) |
64 { | 61 { |
65 for (var i = 0; i < pages.length; i++) | 62 for (var i = 0; i < pages.length; i++) |
66 { | 63 { |
67 let page = pages[i]; | 64 let page = pages[i]; |
68 let badge = null; | 65 let badge = null; |
69 | 66 |
70 if (Prefs.show_statsinicon) | 67 if (Prefs.show_statsinicon) |
71 { | 68 { |
72 let blocked = blockedPerPage.get(page); | 69 let blocked = blockedPerPage.get(page); |
73 if (blocked) | 70 if (blocked) |
74 { | 71 { |
75 badge = { | 72 badge = { |
76 color: badgeColor, | 73 color: badgeColor, |
77 number: blocked | 74 number: blocked |
78 }; | 75 }; |
79 } | 76 } |
80 } | 77 } |
81 | 78 |
82 page.browserAction.setBadge(badge); | 79 page.browserAction.setBadge(badge); |
83 } | 80 } |
84 }); | 81 }); |
85 }); | 82 }); |
OLD | NEW |