Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: stats.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Use method shorthand Created Jan. 16, 2017, 4:07 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « qunit/tests/versionComparator.js ('k') | subscriptionLink.postload.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 let backgroundPage = ext.backgroundPage.getWindow();
21 var require = backgroundPage.require; 22 let require = backgroundPage.require;
22 var getBlockedPerPage = require("stats").getBlockedPerPage; 23 let getBlockedPerPage = require("stats").getBlockedPerPage;
23 var FilterNotifier = require("filterNotifier").FilterNotifier; 24 let FilterNotifier = require("filterNotifier").FilterNotifier;
24 var Prefs = require("prefs").Prefs; 25 let Prefs = require("prefs").Prefs;
25 26
26 var currentPage; 27 let currentPage;
27 var shareURL = "https://adblockplus.org/"; 28 let shareURL = "https://adblockplus.org/";
28 29
29 var messageMark = {}; 30 let messageMark = {};
30 var shareLinks = { 31 let shareLinks = {
31 facebook: ["https://www.facebook.com/dialog/feed", { 32 facebook: ["https://www.facebook.com/dialog/feed", {
32 app_id: "475542399197328", 33 app_id: "475542399197328",
33 link: shareURL, 34 link: shareURL,
34 redirect_uri: "https://www.facebook.com/", 35 redirect_uri: "https://www.facebook.com/",
35 ref: "adcounter", 36 ref: "adcounter",
36 name: messageMark, 37 name: messageMark,
37 actions: JSON.stringify([ 38 actions: JSON.stringify([
38 { 39 {
39 name: i18n.getMessage("stats_share_download"), 40 name: i18n.getMessage("stats_share_download"),
40 link: shareURL 41 link: shareURL
41 } 42 }
42 ]) 43 ])
43 }], 44 }],
44 gplus: ["https://plus.google.com/share", { 45 gplus: ["https://plus.google.com/share", {
45 url: shareURL 46 url: shareURL
46 }], 47 }],
47 twitter: ["https://twitter.com/intent/tweet", { 48 twitter: ["https://twitter.com/intent/tweet", {
48 text: messageMark, 49 text: messageMark,
49 url: shareURL, 50 url: shareURL,
50 via: "AdblockPlus" 51 via: "AdblockPlus"
51 }] 52 }]
52 }; 53 };
53 54
54 function createShareLink(network, blockedCount) 55 function createShareLink(network, blockedCount)
55 { 56 {
56 var url = shareLinks[network][0]; 57 let url = shareLinks[network][0];
57 var params = shareLinks[network][1]; 58 let params = shareLinks[network][1];
58 59
59 var querystring = []; 60 let querystring = [];
60 for (var key in params) 61 for (let key in params)
61 { 62 {
62 var value = params[key]; 63 let value = params[key];
63 if (value == messageMark) 64 if (value == messageMark)
64 value = i18n.getMessage("stats_share_message", blockedCount); 65 value = i18n.getMessage("stats_share_message", blockedCount);
65 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) ); 66 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) );
66 } 67 }
67 return url + "?" + querystring.join("&"); 68 return url + "?" + querystring.join("&");
68 } 69 }
69 70
70 function onLoad() 71 function onLoad()
71 { 72 {
72 document.getElementById("share-box").addEventListener("click", share, false) ; 73 document.getElementById("share-box").addEventListener("click", share, false) ;
73 var showIconNumber = document.getElementById("show-iconnumber"); 74 let showIconNumber = document.getElementById("show-iconnumber");
74 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); 75 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon);
75 showIconNumber.addEventListener("click", toggleIconNumber, false); 76 showIconNumber.addEventListener("click", toggleIconNumber, false);
76 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false); 77 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false);
77 78
78 // Update stats 79 // Update stats
79 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) 80 ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
80 { 81 {
81 currentPage = pages[0]; 82 currentPage = pages[0];
82 updateStats(); 83 updateStats();
83 84
84 FilterNotifier.on("filter.hitCount", updateStats); 85 FilterNotifier.on("filter.hitCount", updateStats);
85 86
86 document.getElementById("stats-container").removeAttribute("hidden"); 87 document.getElementById("stats-container").removeAttribute("hidden");
87 }); 88 });
88 } 89 }
89 90
90 function onUnload() 91 function onUnload()
91 { 92 {
92 FilterNotifier.off("filter.hitCount", updateStats); 93 FilterNotifier.off("filter.hitCount", updateStats);
93 } 94 }
94 95
95 function updateStats() 96 function updateStats()
96 { 97 {
97 var statsPage = document.getElementById("stats-page"); 98 let statsPage = document.getElementById("stats-page");
98 var blockedPage = getBlockedPerPage(currentPage).toLocaleString(); 99 let blockedPage = getBlockedPerPage(currentPage).toLocaleString();
99 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); 100 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
100 101
101 var statsTotal = document.getElementById("stats-total"); 102 let statsTotal = document.getElementById("stats-total");
102 var blockedTotal = Prefs.blocked_total.toLocaleString(); 103 let blockedTotal = Prefs.blocked_total.toLocaleString();
103 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); 104 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
104 } 105 }
105 106
106 function share(ev) 107 function share(ev)
107 { 108 {
108 // Easter Egg 109 // Easter Egg
109 var blocked = Prefs.blocked_total; 110 let blocked = Prefs.blocked_total;
110 if (blocked <= 9000 || blocked >= 10000) 111 if (blocked <= 9000 || blocked >= 10000)
111 blocked = blocked.toLocaleString(); 112 blocked = blocked.toLocaleString();
112 else 113 else
113 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); 114 blocked = i18n.getMessage("stats_over", (9000).toLocaleString());
114 115
115 ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); 116 ext.pages.open(createShareLink(ev.target.dataset.social, blocked));
116 } 117 }
117 118
118 function toggleIconNumber() 119 function toggleIconNumber()
119 { 120 {
120 Prefs.show_statsinicon = !Prefs.show_statsinicon; 121 Prefs.show_statsinicon = !Prefs.show_statsinicon;
121 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_statsinicon); 122 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_statsinicon);
122 } 123 }
123 124
124 document.addEventListener("DOMContentLoaded", onLoad, false); 125 document.addEventListener("DOMContentLoaded", onLoad, false);
125 window.addEventListener("unload", onUnload, false); 126 window.addEventListener("unload", onUnload, false);
126 })(); 127 }
OLDNEW
« no previous file with comments | « qunit/tests/versionComparator.js ('k') | subscriptionLink.postload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld