Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const shareURL = "https://adblockplus.org/"; | 20 const shareURL = "https://adblockplus.org/"; |
Manish Jethani
2017/10/10 05:08:56
These from stats.js are now constants here.
| |
21 const messageMark = {}; | 21 const messageMark = {}; |
22 | 22 |
23 const shareLinks = { | 23 const shareLinks = { |
24 facebook: ["https://www.facebook.com/dialog/feed", { | 24 facebook: ["https://www.facebook.com/dialog/feed", { |
25 app_id: "475542399197328", | 25 app_id: "475542399197328", |
26 link: shareURL, | 26 link: shareURL, |
27 redirect_uri: "https://www.facebook.com/", | 27 redirect_uri: "https://www.facebook.com/", |
28 ref: "adcounter", | 28 ref: "adcounter", |
29 name: messageMark, | 29 name: messageMark, |
30 actions: JSON.stringify([ | 30 actions: JSON.stringify([ |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 } | 129 } |
130 | 130 |
131 function toggleCollapse(event) | 131 function toggleCollapse(event) |
132 { | 132 { |
133 let collapser = event.currentTarget; | 133 let collapser = event.currentTarget; |
134 let collapsible = document.getElementById(collapser.dataset.collapsible); | 134 let collapsible = document.getElementById(collapser.dataset.collapsible); |
135 collapsible.classList.toggle("collapsed"); | 135 collapsible.classList.toggle("collapsed"); |
136 togglePref(collapser.dataset.option); | 136 togglePref(collapser.dataset.option); |
137 } | 137 } |
138 | 138 |
139 function getDocLinks(notification) | 139 function getDocLinks(notification) |
Manish Jethani
2017/10/10 05:08:56
This is from notification.js
| |
140 { | 140 { |
141 if (!notification.links) | 141 if (!notification.links) |
142 return Promise.resolve([]); | 142 return Promise.resolve([]); |
143 | 143 |
144 return Promise.all( | 144 return Promise.all( |
145 notification.links.map(link => | 145 notification.links.map(link => |
146 { | 146 { |
147 return new Promise((resolve, reject) => | 147 return new Promise((resolve, reject) => |
148 { | 148 { |
149 chrome.runtime.sendMessage({ | 149 chrome.runtime.sendMessage({ |
(...skipping 24 matching lines...) Expand all Loading... | |
174 | 174 |
175 let newElement = document.createElement(tagName); | 175 let newElement = document.createElement(tagName); |
176 if (tagName == "a" && links && links.length) | 176 if (tagName == "a" && links && links.length) |
177 newElement.href = links.shift(); | 177 newElement.href = links.shift(); |
178 insertMessage(newElement, value, links); | 178 insertMessage(newElement, value, links); |
179 element.appendChild(newElement); | 179 element.appendChild(newElement); |
180 | 180 |
181 insertMessage(element, after, links); | 181 insertMessage(element, after, links); |
182 } | 182 } |
183 | 183 |
184 function createShareLink(network, blockedCount) | 184 function createShareLink(network, blockedCount) |
Manish Jethani
2017/10/10 05:08:56
This is from stats.js
| |
185 { | 185 { |
186 let url = shareLinks[network][0]; | 186 let url = shareLinks[network][0]; |
187 let params = shareLinks[network][1]; | 187 let params = shareLinks[network][1]; |
188 | 188 |
189 let querystring = []; | 189 let querystring = []; |
190 for (let key in params) | 190 for (let key in params) |
191 { | 191 { |
192 let value = params[key]; | 192 let value = params[key]; |
193 if (value == messageMark) | 193 if (value == messageMark) |
194 value = chrome.i18n.getMessage("stats_share_message", blockedCount); | 194 value = chrome.i18n.getMessage("stats_share_message", blockedCount); |
(...skipping 18 matching lines...) Expand all Loading... | |
213 }); | 213 }); |
214 | 214 |
215 let statsTotal = document.getElementById("stats-total"); | 215 let statsTotal = document.getElementById("stats-total"); |
216 getPref("blocked_total", blockedTotal => | 216 getPref("blocked_total", blockedTotal => |
217 { | 217 { |
218 ext.i18n.setElementText(statsTotal, "stats_label_total", | 218 ext.i18n.setElementText(statsTotal, "stats_label_total", |
219 [blockedTotal.toLocaleString()]); | 219 [blockedTotal.toLocaleString()]); |
220 }); | 220 }); |
221 } | 221 } |
222 | 222 |
223 function share(ev) | 223 function share(event) |
224 { | 224 { |
225 getPref("blocked_total", blockedTotal => | 225 getPref("blocked_total", blockedTotal => |
226 { | 226 { |
227 // Easter Egg | 227 // Easter Egg |
228 if (blockedTotal <= 9000 || blockedTotal >= 10000) | 228 if (blockedTotal <= 9000 || blockedTotal >= 10000) |
229 { | 229 { |
230 blockedTotal = blockedTotal.toLocaleString(); | 230 blockedTotal = blockedTotal.toLocaleString(); |
231 } | 231 } |
232 else | 232 else |
233 { | 233 { |
234 blockedTotal = chrome.i18n.getMessage("stats_over", | 234 blockedTotal = chrome.i18n.getMessage("stats_over", |
235 (9000).toLocaleString()); | 235 (9000).toLocaleString()); |
236 } | 236 } |
237 | 237 |
238 chrome.tabs.create({ | 238 chrome.tabs.create({ |
239 url: createShareLink(ev.target.dataset.social, blockedTotal) | 239 url: createShareLink(event.target.dataset.social, blockedTotal) |
240 }); | 240 }); |
241 }); | 241 }); |
242 } | 242 } |
243 | 243 |
244 function toggleIconNumber() | 244 function toggleIconNumber() |
245 { | 245 { |
246 togglePref("show_statsinicon", showStatsInIcon => | 246 togglePref("show_statsinicon", showStatsInIcon => |
247 { | 247 { |
248 document.getElementById("show-iconnumber").setAttribute( | 248 document.getElementById("show-iconnumber").setAttribute( |
249 "aria-checked", showStatsInIcon | 249 "aria-checked", showStatsInIcon |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 chrome.tabs.sendMessage(tab.id, { | 289 chrome.tabs.sendMessage(tab.id, { |
290 type: "composer.content.getState" | 290 type: "composer.content.getState" |
291 }, | 291 }, |
292 response => | 292 response => |
293 { | 293 { |
294 if (response && response.active) | 294 if (response && response.active) |
295 document.body.classList.add("clickhide-active"); | 295 document.body.classList.add("clickhide-active"); |
296 }); | 296 }); |
297 } | 297 } |
298 | 298 |
299 updateStats(); | 299 updateStats(); |
Manish Jethani
2017/10/10 05:08:56
These two lines from the previously separate onLoa
| |
300 document.getElementById("stats-container").removeAttribute("hidden"); | 300 document.getElementById("stats-container").removeAttribute("hidden"); |
301 }); | 301 }); |
302 | 302 |
303 document.getElementById("enabled").addEventListener( | 303 document.getElementById("enabled").addEventListener( |
304 "click", toggleEnabled, false | 304 "click", toggleEnabled |
305 ); | 305 ); |
306 document.getElementById("clickhide").addEventListener( | 306 document.getElementById("clickhide").addEventListener( |
307 "click", activateClickHide, false | 307 "click", activateClickHide |
308 ); | 308 ); |
309 document.getElementById("clickhide-cancel").addEventListener( | 309 document.getElementById("clickhide-cancel").addEventListener( |
310 "click", cancelClickHide, false | 310 "click", cancelClickHide |
311 ); | 311 ); |
312 document.getElementById("options").addEventListener("click", () => | 312 document.getElementById("options").addEventListener("click", () => |
313 { | 313 { |
314 chrome.runtime.sendMessage({type: "app.open", what: "options"}); | 314 chrome.runtime.sendMessage({type: "app.open", what: "options"}); |
315 window.close(); | 315 window.close(); |
316 }, false); | 316 }); |
317 | 317 |
318 // Set up collapsing of menu items | 318 // Set up collapsing of menu items |
319 for (let collapser of document.getElementsByClassName("collapse")) | 319 for (let collapser of document.getElementsByClassName("collapse")) |
320 { | 320 { |
321 collapser.addEventListener("click", toggleCollapse, false); | 321 collapser.addEventListener("click", toggleCollapse); |
322 getPref(collapser.dataset.option, value => | 322 getPref(collapser.dataset.option, value => |
323 { | 323 { |
324 if (value) | 324 if (value) |
325 { | 325 { |
326 document.getElementById( | 326 document.getElementById( |
327 collapser.dataset.collapsible | 327 collapser.dataset.collapsible |
328 ).classList.remove("collapsed"); | 328 ).classList.remove("collapsed"); |
329 } | 329 } |
330 }); | 330 }); |
331 } | 331 } |
332 | 332 |
333 document.getElementById("share-box").addEventListener("click", share, | 333 document.getElementById("share-box").addEventListener("click", share); |
Manish Jethani
2017/10/10 05:08:56
onLoad code from stats.js
| |
334 false); | |
335 let showIconNumber = document.getElementById("show-iconnumber"); | 334 let showIconNumber = document.getElementById("show-iconnumber"); |
336 getPref("show_statsinicon", showStatsInIcon => | 335 getPref("show_statsinicon", showStatsInIcon => |
337 { | 336 { |
338 showIconNumber.setAttribute("aria-checked", showStatsInIcon); | 337 showIconNumber.setAttribute("aria-checked", showStatsInIcon); |
339 }); | 338 }); |
340 showIconNumber.addEventListener("click", toggleIconNumber, false); | 339 showIconNumber.addEventListener("click", toggleIconNumber); |
341 document.querySelector("label[for='show-iconnumber']").addEventListener( | 340 document.querySelector("label[for='show-iconnumber']").addEventListener( |
342 "click", toggleIconNumber, false | 341 "click", toggleIconNumber |
343 ); | 342 ); |
344 }, false); | 343 }); |
345 | 344 |
346 window.addEventListener("load", () => | 345 window.addEventListener("load", () => |
Manish Jethani
2017/10/10 05:08:56
Nothing has changed in the window's "load" handler
| |
347 { | 346 { |
348 chrome.runtime.sendMessage({ | 347 chrome.runtime.sendMessage({ |
349 type: "notifications.get", | 348 type: "notifications.get", |
350 displayMethod: "popup" | 349 displayMethod: "popup" |
351 }, notification => | 350 }, notification => |
352 { | 351 { |
353 if (!notification) | 352 if (!notification) |
354 return; | 353 return; |
355 | 354 |
356 let titleElement = document.getElementById("notification-title"); | 355 let titleElement = document.getElementById("notification-title"); |
(...skipping 29 matching lines...) Expand all Loading... | |
386 event.target.id == "notification-hide") | 385 event.target.id == "notification-hide") |
387 { | 386 { |
388 if (event.target.id == "notification-optout") | 387 if (event.target.id == "notification-optout") |
389 setPref("notifications_ignoredcategories", true); | 388 setPref("notifications_ignoredcategories", true); |
390 | 389 |
391 notificationElement.hidden = true; | 390 notificationElement.hidden = true; |
392 notification.onClicked(); | 391 notification.onClicked(); |
393 } | 392 } |
394 }, true); | 393 }, true); |
395 }); | 394 }); |
396 }, false); | 395 }); |
LEFT | RIGHT |