Left: | ||
Right: |
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 |
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 (function() | 18 "use strict"; |
19 | |
19 { | 20 { |
20 var backgroundPage = ext.backgroundPage.getWindow(); | 21 const backgroundPage = ext.backgroundPage.getWindow(); |
21 var require = backgroundPage.require; | 22 const {require} = backgroundPage; |
Sebastian Noack
2017/01/18 11:24:30
Note that backgroundPage isn't used anywhere else,
kzar
2017/01/18 11:46:40
Done.
| |
22 var getBlockedPerPage = require("stats").getBlockedPerPage; | |
23 var FilterNotifier = require("filterNotifier").FilterNotifier; | |
24 var Prefs = require("prefs").Prefs; | |
25 | 23 |
26 var currentPage; | 24 const {getBlockedPerPage} = require("stats"); |
27 var shareURL = "https://adblockplus.org/"; | 25 const {FilterNotifier} = require("filterNotifier"); |
26 const {Prefs} = require("prefs"); | |
28 | 27 |
29 var messageMark = {}; | 28 let currentPage; |
30 var shareLinks = { | 29 const shareURL = "https://adblockplus.org/"; |
30 | |
31 let messageMark = {}; | |
32 let shareLinks = { | |
31 facebook: ["https://www.facebook.com/dialog/feed", { | 33 facebook: ["https://www.facebook.com/dialog/feed", { |
32 app_id: "475542399197328", | 34 app_id: "475542399197328", |
33 link: shareURL, | 35 link: shareURL, |
34 redirect_uri: "https://www.facebook.com/", | 36 redirect_uri: "https://www.facebook.com/", |
35 ref: "adcounter", | 37 ref: "adcounter", |
36 name: messageMark, | 38 name: messageMark, |
37 actions: JSON.stringify([ | 39 actions: JSON.stringify([ |
38 { | 40 { |
39 name: i18n.getMessage("stats_share_download"), | 41 name: i18n.getMessage("stats_share_download"), |
40 link: shareURL | 42 link: shareURL |
41 } | 43 } |
42 ]) | 44 ]) |
43 }], | 45 }], |
44 gplus: ["https://plus.google.com/share", { | 46 gplus: ["https://plus.google.com/share", { |
45 url: shareURL | 47 url: shareURL |
46 }], | 48 }], |
47 twitter: ["https://twitter.com/intent/tweet", { | 49 twitter: ["https://twitter.com/intent/tweet", { |
48 text: messageMark, | 50 text: messageMark, |
49 url: shareURL, | 51 url: shareURL, |
50 via: "AdblockPlus" | 52 via: "AdblockPlus" |
51 }] | 53 }] |
52 }; | 54 }; |
53 | 55 |
54 function createShareLink(network, blockedCount) | 56 function createShareLink(network, blockedCount) |
55 { | 57 { |
56 var url = shareLinks[network][0]; | 58 let url = shareLinks[network][0]; |
57 var params = shareLinks[network][1]; | 59 let params = shareLinks[network][1]; |
58 | 60 |
59 var querystring = []; | 61 let querystring = []; |
60 for (var key in params) | 62 for (let key in params) |
61 { | 63 { |
62 var value = params[key]; | 64 let value = params[key]; |
63 if (value == messageMark) | 65 if (value == messageMark) |
64 value = i18n.getMessage("stats_share_message", blockedCount); | 66 value = i18n.getMessage("stats_share_message", blockedCount); |
65 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) ); | 67 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) ); |
66 } | 68 } |
67 return url + "?" + querystring.join("&"); | 69 return url + "?" + querystring.join("&"); |
68 } | 70 } |
69 | 71 |
70 function onLoad() | 72 function onLoad() |
71 { | 73 { |
72 document.getElementById("share-box").addEventListener("click", share, false) ; | 74 document.getElementById("share-box").addEventListener("click", share, false) ; |
73 var showIconNumber = document.getElementById("show-iconnumber"); | 75 let showIconNumber = document.getElementById("show-iconnumber"); |
74 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); | 76 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); |
75 showIconNumber.addEventListener("click", toggleIconNumber, false); | 77 showIconNumber.addEventListener("click", toggleIconNumber, false); |
76 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false); | 78 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false); |
77 | 79 |
78 // Update stats | 80 // Update stats |
79 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 81 ext.pages.query({active: true, lastFocusedWindow: true}, pages => |
80 { | 82 { |
81 currentPage = pages[0]; | 83 currentPage = pages[0]; |
82 updateStats(); | 84 updateStats(); |
83 | 85 |
84 FilterNotifier.on("filter.hitCount", updateStats); | 86 FilterNotifier.on("filter.hitCount", updateStats); |
85 | 87 |
86 document.getElementById("stats-container").removeAttribute("hidden"); | 88 document.getElementById("stats-container").removeAttribute("hidden"); |
87 }); | 89 }); |
88 } | 90 } |
89 | 91 |
90 function onUnload() | 92 function onUnload() |
91 { | 93 { |
92 FilterNotifier.off("filter.hitCount", updateStats); | 94 FilterNotifier.off("filter.hitCount", updateStats); |
93 } | 95 } |
94 | 96 |
95 function updateStats() | 97 function updateStats() |
96 { | 98 { |
97 var statsPage = document.getElementById("stats-page"); | 99 let statsPage = document.getElementById("stats-page"); |
98 var blockedPage = getBlockedPerPage(currentPage).toLocaleString(); | 100 let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); |
99 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 101 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); |
100 | 102 |
101 var statsTotal = document.getElementById("stats-total"); | 103 let statsTotal = document.getElementById("stats-total"); |
102 var blockedTotal = Prefs.blocked_total.toLocaleString(); | 104 let blockedTotal = Prefs.blocked_total.toLocaleString(); |
103 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); | 105 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); |
104 } | 106 } |
105 | 107 |
106 function share(ev) | 108 function share(ev) |
107 { | 109 { |
108 // Easter Egg | 110 // Easter Egg |
109 var blocked = Prefs.blocked_total; | 111 let blocked = Prefs.blocked_total; |
110 if (blocked <= 9000 || blocked >= 10000) | 112 if (blocked <= 9000 || blocked >= 10000) |
111 blocked = blocked.toLocaleString(); | 113 blocked = blocked.toLocaleString(); |
112 else | 114 else |
113 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); | 115 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); |
114 | 116 |
115 ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); | 117 ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); |
116 } | 118 } |
117 | 119 |
118 function toggleIconNumber() | 120 function toggleIconNumber() |
119 { | 121 { |
120 Prefs.show_statsinicon = !Prefs.show_statsinicon; | 122 Prefs.show_statsinicon = !Prefs.show_statsinicon; |
121 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_statsinicon); | 123 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_statsinicon); |
122 } | 124 } |
123 | 125 |
124 document.addEventListener("DOMContentLoaded", onLoad, false); | 126 document.addEventListener("DOMContentLoaded", onLoad, false); |
125 window.addEventListener("unload", onUnload, false); | 127 window.addEventListener("unload", onUnload, false); |
126 })(); | 128 } |
OLD | NEW |