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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 /* global i18n */ | 18 /* global i18n */ |
19 | 19 |
20 "use strict"; | 20 "use strict"; |
21 | 21 |
22 (function() | 22 (function() |
23 { | 23 { |
24 const {require} = ext.backgroundPage.getWindow(); | 24 const {require} = ext.backgroundPage.getWindow(); |
25 | 25 |
26 const {getBlockedPerPage} = require("stats"); | 26 const {getBlockedPerPage} = require("stats"); |
27 const {FilterNotifier} = require("filterNotifier"); | 27 const {FilterNotifier} = require("filterNotifier"); |
28 const {Prefs} = require("prefs"); | |
29 | 28 |
30 let currentPage; | 29 let currentPage; |
31 const shareURL = "https://adblockplus.org/"; | 30 const shareURL = "https://adblockplus.org/"; |
32 | 31 |
33 let messageMark = {}; | 32 let messageMark = {}; |
34 let shareLinks = { | 33 let shareLinks = { |
35 facebook: ["https://www.facebook.com/dialog/feed", { | 34 facebook: ["https://www.facebook.com/dialog/feed", { |
36 app_id: "475542399197328", | 35 app_id: "475542399197328", |
37 link: shareURL, | 36 link: shareURL, |
38 redirect_uri: "https://www.facebook.com/", | 37 redirect_uri: "https://www.facebook.com/", |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 ); | 70 ); |
72 } | 71 } |
73 return url + "?" + querystring.join("&"); | 72 return url + "?" + querystring.join("&"); |
74 } | 73 } |
75 | 74 |
76 function onLoad() | 75 function onLoad() |
77 { | 76 { |
78 document.getElementById("share-box").addEventListener("click", share, | 77 document.getElementById("share-box").addEventListener("click", share, |
79 false); | 78 false); |
80 let showIconNumber = document.getElementById("show-iconnumber"); | 79 let showIconNumber = document.getElementById("show-iconnumber"); |
81 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); | 80 ext.prefs.get("show_statsinicon", showStatsInIcon => |
| 81 { |
| 82 showIconNumber.setAttribute("aria-checked", showStatsInIcon); |
| 83 }); |
82 showIconNumber.addEventListener("click", toggleIconNumber, false); | 84 showIconNumber.addEventListener("click", toggleIconNumber, false); |
83 document.querySelector("label[for='show-iconnumber']").addEventListener( | 85 document.querySelector("label[for='show-iconnumber']").addEventListener( |
84 "click", toggleIconNumber, false | 86 "click", toggleIconNumber, false |
85 ); | 87 ); |
86 | 88 |
87 // Update stats | 89 // Update stats |
88 ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 90 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => |
89 { | 91 { |
90 currentPage = pages[0]; | 92 currentPage = ext.createPageObject(tabs[0]); |
91 updateStats(); | 93 updateStats(); |
92 | 94 |
93 FilterNotifier.on("filter.hitCount", updateStats); | 95 FilterNotifier.on("filter.hitCount", updateStats); |
94 | 96 |
95 document.getElementById("stats-container").removeAttribute("hidden"); | 97 document.getElementById("stats-container").removeAttribute("hidden"); |
96 }); | 98 }); |
97 } | 99 } |
98 | 100 |
99 function onUnload() | 101 function onUnload() |
100 { | 102 { |
101 FilterNotifier.off("filter.hitCount", updateStats); | 103 FilterNotifier.off("filter.hitCount", updateStats); |
102 } | 104 } |
103 | 105 |
104 function updateStats() | 106 function updateStats() |
105 { | 107 { |
106 let statsPage = document.getElementById("stats-page"); | 108 let statsPage = document.getElementById("stats-page"); |
107 let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); | 109 let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); |
108 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 110 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); |
109 | 111 |
110 let statsTotal = document.getElementById("stats-total"); | 112 let statsTotal = document.getElementById("stats-total"); |
111 let blockedTotal = Prefs.blocked_total.toLocaleString(); | 113 ext.prefs.get("blocked_total", blockedTotal => |
112 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); | 114 { |
| 115 i18n.setElementText(statsTotal, "stats_label_total", |
| 116 [blockedTotal.toLocaleString()]); |
| 117 }); |
113 } | 118 } |
114 | 119 |
115 function share(ev) | 120 function share(ev) |
116 { | 121 { |
117 // Easter Egg | 122 ext.prefs.get("blocked_total", blockedTotal => |
118 let blocked = Prefs.blocked_total; | 123 { |
119 if (blocked <= 9000 || blocked >= 10000) | 124 // Easter Egg |
120 blocked = blocked.toLocaleString(); | 125 if (blockedTotal <= 9000 || blockedTotal >= 10000) |
121 else | 126 blockedTotal = blockedTotal.toLocaleString(); |
122 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); | 127 else |
| 128 blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString()); |
123 | 129 |
124 ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); | 130 chrome.tabs.create({ |
| 131 url: createShareLink(ev.target.dataset.social, blockedTotal) |
| 132 }); |
| 133 }); |
125 } | 134 } |
126 | 135 |
127 function toggleIconNumber() | 136 function toggleIconNumber() |
128 { | 137 { |
129 Prefs.show_statsinicon = !Prefs.show_statsinicon; | 138 ext.prefs.toggle("show_statsinicon", () => |
130 document.getElementById("show-iconnumber").setAttribute( | 139 { |
131 "aria-checked", Prefs.show_statsinicon | 140 ext.prefs.get("show_statsinicon", showStatsInIcon => |
132 ); | 141 { |
| 142 document.getElementById("show-iconnumber").setAttribute( |
| 143 "aria-checked", showStatsInIcon |
| 144 ); |
| 145 }); |
| 146 }); |
133 } | 147 } |
134 | 148 |
135 document.addEventListener("DOMContentLoaded", onLoad, false); | 149 document.addEventListener("DOMContentLoaded", onLoad, false); |
136 window.addEventListener("unload", onUnload, false); | 150 window.addEventListener("unload", onUnload, false); |
137 }()); | 151 }()); |
OLD | NEW |