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

Unified Diff: stats.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Workaround limiation with iterating element collections in older versions of Chrome Created Jan. 16, 2017, 8:46 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: stats.js
diff --git a/stats.js b/stats.js
index 416f0bbafd0edaf86b6fdf4f71aefd7208c55d5a..a7832ae24442b1fce761396843b535ef0765cb07 100644
--- a/stats.js
+++ b/stats.js
@@ -15,19 +15,20 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-(function()
+"use strict";
+
{
- var backgroundPage = ext.backgroundPage.getWindow();
- var require = backgroundPage.require;
- var getBlockedPerPage = require("stats").getBlockedPerPage;
- var FilterNotifier = require("filterNotifier").FilterNotifier;
- var Prefs = require("prefs").Prefs;
+ let backgroundPage = ext.backgroundPage.getWindow();
+ let require = backgroundPage.require;
+ let getBlockedPerPage = require("stats").getBlockedPerPage;
+ let FilterNotifier = require("filterNotifier").FilterNotifier;
+ let Prefs = require("prefs").Prefs;
- var currentPage;
- var shareURL = "https://adblockplus.org/";
+ let currentPage;
+ let shareURL = "https://adblockplus.org/";
- var messageMark = {};
- var shareLinks = {
+ let messageMark = {};
+ let shareLinks = {
facebook: ["https://www.facebook.com/dialog/feed", {
app_id: "475542399197328",
link: shareURL,
@@ -53,13 +54,13 @@
function createShareLink(network, blockedCount)
{
- var url = shareLinks[network][0];
- var params = shareLinks[network][1];
+ let url = shareLinks[network][0];
+ let params = shareLinks[network][1];
- var querystring = [];
- for (var key in params)
+ let querystring = [];
+ for (let key in params)
{
- var value = params[key];
+ let value = params[key];
if (value == messageMark)
value = i18n.getMessage("stats_share_message", blockedCount);
querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
@@ -70,13 +71,13 @@
function onLoad()
{
document.getElementById("share-box").addEventListener("click", share, false);
- var showIconNumber = document.getElementById("show-iconnumber");
+ let showIconNumber = document.getElementById("show-iconnumber");
showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon);
showIconNumber.addEventListener("click", toggleIconNumber, false);
document.querySelector("label[for='show-iconnumber']").addEventListener("click", toggleIconNumber, false);
// Update stats
- ext.pages.query({active: true, lastFocusedWindow: true}, function(pages)
+ ext.pages.query({active: true, lastFocusedWindow: true}, pages =>
{
currentPage = pages[0];
updateStats();
@@ -94,19 +95,19 @@
function updateStats()
{
- var statsPage = document.getElementById("stats-page");
- var blockedPage = getBlockedPerPage(currentPage).toLocaleString();
+ let statsPage = document.getElementById("stats-page");
+ let blockedPage = getBlockedPerPage(currentPage).toLocaleString();
i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
- var statsTotal = document.getElementById("stats-total");
- var blockedTotal = Prefs.blocked_total.toLocaleString();
+ let statsTotal = document.getElementById("stats-total");
+ let blockedTotal = Prefs.blocked_total.toLocaleString();
i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
}
function share(ev)
{
// Easter Egg
- var blocked = Prefs.blocked_total;
+ let blocked = Prefs.blocked_total;
if (blocked <= 9000 || blocked >= 10000)
blocked = blocked.toLocaleString();
else
@@ -123,4 +124,4 @@
document.addEventListener("DOMContentLoaded", onLoad, false);
window.addEventListener("unload", onUnload, false);
-})();
+}

Powered by Google App Engine
This is Rietveld