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

Delta Between Two Patch Sets: stats.js

Issue 29532767: Issue 5593 - Use messaging in popup for prefs, whitelisting, and stats (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Use promises for page ready check Created Sept. 19, 2017, 9:23 a.m.
Right Patch Set: Revert one more instance of ext.pages.open Created Sept. 27, 2017, 9:40 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « skin/popup.css ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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, getPref, togglePref */
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");
27 const {FilterNotifier} = require("filterNotifier"); 26 const {FilterNotifier} = require("filterNotifier");
28 27
29 let currentPage; 28 let currentTab;
30 const shareURL = "https://adblockplus.org/"; 29 const shareURL = "https://adblockplus.org/";
31 30
32 let messageMark = {}; 31 let messageMark = {};
33 let shareLinks = { 32 let shareLinks = {
34 facebook: ["https://www.facebook.com/dialog/feed", { 33 facebook: ["https://www.facebook.com/dialog/feed", {
35 app_id: "475542399197328", 34 app_id: "475542399197328",
36 link: shareURL, 35 link: shareURL,
37 redirect_uri: "https://www.facebook.com/", 36 redirect_uri: "https://www.facebook.com/",
38 ref: "adcounter", 37 ref: "adcounter",
39 name: messageMark, 38 name: messageMark,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 showIconNumber.setAttribute("aria-checked", showStatsInIcon); 81 showIconNumber.setAttribute("aria-checked", showStatsInIcon);
83 }); 82 });
84 showIconNumber.addEventListener("click", toggleIconNumber, false); 83 showIconNumber.addEventListener("click", toggleIconNumber, false);
85 document.querySelector("label[for='show-iconnumber']").addEventListener( 84 document.querySelector("label[for='show-iconnumber']").addEventListener(
86 "click", toggleIconNumber, false 85 "click", toggleIconNumber, false
87 ); 86 );
88 87
89 // Update stats 88 // Update stats
90 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => 89 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
91 { 90 {
92 currentPage = createPageObject(tabs[0]); 91 currentTab = tabs[0];
93 updateStats(); 92 updateStats();
94 93
95 FilterNotifier.on("filter.hitCount", updateStats); 94 FilterNotifier.on("filter.hitCount", updateStats);
96 95
97 document.getElementById("stats-container").removeAttribute("hidden"); 96 document.getElementById("stats-container").removeAttribute("hidden");
98 }); 97 });
99 } 98 }
100 99
101 function onUnload() 100 function onUnload()
102 { 101 {
103 FilterNotifier.off("filter.hitCount", updateStats); 102 FilterNotifier.off("filter.hitCount", updateStats);
104 } 103 }
105 104
106 function updateStats() 105 function updateStats()
107 { 106 {
108 let statsPage = document.getElementById("stats-page"); 107 let statsPage = document.getElementById("stats-page");
109 let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); 108 chrome.runtime.sendMessage({
110 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); 109 type: "stats.getBlockedPerPage",
110 tab: currentTab
111 },
112 blockedPage =>
113 {
114 i18n.setElementText(statsPage, "stats_label_page",
115 [blockedPage.toLocaleString()]);
116 });
111 117
112 let statsTotal = document.getElementById("stats-total"); 118 let statsTotal = document.getElementById("stats-total");
113 getPref("blocked_total", blockedTotal => 119 getPref("blocked_total", blockedTotal =>
114 { 120 {
115 i18n.setElementText(statsTotal, "stats_label_total", 121 i18n.setElementText(statsTotal, "stats_label_total",
116 [blockedTotal.toLocaleString()]); 122 [blockedTotal.toLocaleString()]);
117 }); 123 });
118 } 124 }
119 125
120 function share(ev) 126 function share(ev)
121 { 127 {
122 getPref("blocked_total", blockedTotal => 128 getPref("blocked_total", blockedTotal =>
123 { 129 {
124 // Easter Egg 130 // Easter Egg
125 if (blockedTotal <= 9000 || blockedTotal >= 10000) 131 if (blockedTotal <= 9000 || blockedTotal >= 10000)
126 blockedTotal = blockedTotal.toLocaleString(); 132 blockedTotal = blockedTotal.toLocaleString();
127 else 133 else
128 blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString()); 134 blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString());
129 135
130 chrome.tabs.create({ 136 ext.pages.open(createShareLink(ev.target.dataset.social, blockedTotal));
Manish Jethani 2017/09/27 09:42:32 Sorry, I forgot this one.
131 url: createShareLink(ev.target.dataset.social, blockedTotal)
132 });
133 }); 137 });
134 } 138 }
135 139
136 function toggleIconNumber() 140 function toggleIconNumber()
137 { 141 {
138 togglePref("show_statsinicon", showStatsInIcon => 142 togglePref("show_statsinicon", showStatsInIcon =>
139 { 143 {
140 document.getElementById("show-iconnumber").setAttribute( 144 document.getElementById("show-iconnumber").setAttribute(
141 "aria-checked", showStatsInIcon 145 "aria-checked", showStatsInIcon
142 ); 146 );
143 }); 147 });
144 } 148 }
145 149
146 document.addEventListener("DOMContentLoaded", onLoad, false); 150 document.addEventListener("DOMContentLoaded", onLoad, false);
147 window.addEventListener("unload", onUnload, false); 151 window.addEventListener("unload", onUnload, false);
148 }()); 152 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld