| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 let badgeColor = "#646464"; | 24 let badgeColor = "#646464"; |
| 25 let blockedPerPage = new ext.PageMap(); | 25 let blockedPerPage = new ext.PageMap(); |
| 26 | 26 |
| 27 /** | 27 /** |
| 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 = page => blockedPerPage.get(page) || 0; |
| 34 { | |
| 35 return blockedPerPage.get(page) || 0; | |
| 36 }; | |
| 37 | 34 |
| 38 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) => | 35 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) => |
| 39 { | 36 { |
| 40 if (!(filter instanceof BlockingFilter) || !page) | 37 if (!(filter instanceof BlockingFilter) || !page) |
| 41 return; | 38 return; |
| 42 | 39 |
| 43 Prefs.blocked_total++; | 40 Prefs.blocked_total++; |
| 44 | 41 |
| 45 let blocked = blockedPerPage.get(page) || 0; | 42 let blocked = blockedPerPage.get(page) || 0; |
| 46 blockedPerPage.set(page, ++blocked); | 43 blockedPerPage.set(page, ++blocked); |
| 47 | 44 |
| 48 // Update number in icon | 45 // Update number in icon |
| 49 if (Prefs.show_statsinicon) | 46 if (Prefs.show_statsinicon) |
| 50 { | 47 { |
| 51 page.browserAction.setBadge({ | 48 page.browserAction.setBadge({ |
| 52 color: badgeColor, | 49 color: badgeColor, |
| 53 number: blocked | 50 number: blocked |
| 54 }); | 51 }); |
| 55 } | 52 } |
| 56 }); | 53 }); |
| 57 | 54 |
| 58 Prefs.on("show_statsinicon", () => | 55 Prefs.on("show_statsinicon", () => |
| 59 { | 56 { |
| 60 ext.pages.query({}, function(pages) | 57 ext.pages.query({}, pages => |
| 61 { | 58 { |
| 62 for (var i = 0; i < pages.length; i++) | 59 for (let page of pages) |
| 63 { | 60 { |
| 64 let page = pages[i]; | |
| 65 let badge = null; | 61 let badge = null; |
| 66 | 62 |
| 67 if (Prefs.show_statsinicon) | 63 if (Prefs.show_statsinicon) |
| 68 { | 64 { |
| 69 let blocked = blockedPerPage.get(page); | 65 let blocked = blockedPerPage.get(page); |
| 70 if (blocked) | 66 if (blocked) |
| 71 { | 67 { |
| 72 badge = { | 68 badge = { |
| 73 color: badgeColor, | 69 color: badgeColor, |
| 74 number: blocked | 70 number: blocked |
| 75 }; | 71 }; |
| 76 } | 72 } |
| 77 } | 73 } |
| 78 | 74 |
| 79 page.browserAction.setBadge(badge); | 75 page.browserAction.setBadge(badge); |
| 80 } | 76 } |
| 81 }); | 77 }); |
| 82 }); | 78 }); |
| OLD | NEW |