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

Side by Side Diff: stats.js

Issue 29532767: Issue 5593 - Use messaging in popup for prefs, whitelisting, and stats (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Revert to using ext.pages.open Created Sept. 26, 2017, 11:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« popup.js ('K') | « skin/popup.css ('k') | no next file » | 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-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 const {Prefs} = require("prefs");
29 27
30 let currentPage; 28 let currentTab;
31 const shareURL = "https://adblockplus.org/"; 29 const shareURL = "https://adblockplus.org/";
32 30
33 let messageMark = {}; 31 let messageMark = {};
34 let shareLinks = { 32 let shareLinks = {
35 facebook: ["https://www.facebook.com/dialog/feed", { 33 facebook: ["https://www.facebook.com/dialog/feed", {
36 app_id: "475542399197328", 34 app_id: "475542399197328",
37 link: shareURL, 35 link: shareURL,
38 redirect_uri: "https://www.facebook.com/", 36 redirect_uri: "https://www.facebook.com/",
39 ref: "adcounter", 37 ref: "adcounter",
40 name: messageMark, 38 name: messageMark,
(...skipping 30 matching lines...) Expand all
71 ); 69 );
72 } 70 }
73 return url + "?" + querystring.join("&"); 71 return url + "?" + querystring.join("&");
74 } 72 }
75 73
76 function onLoad() 74 function onLoad()
77 { 75 {
78 document.getElementById("share-box").addEventListener("click", share, 76 document.getElementById("share-box").addEventListener("click", share,
79 false); 77 false);
80 let showIconNumber = document.getElementById("show-iconnumber"); 78 let showIconNumber = document.getElementById("show-iconnumber");
81 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); 79 getPref("show_statsinicon", showStatsInIcon =>
80 {
81 showIconNumber.setAttribute("aria-checked", showStatsInIcon);
82 });
82 showIconNumber.addEventListener("click", toggleIconNumber, false); 83 showIconNumber.addEventListener("click", toggleIconNumber, false);
83 document.querySelector("label[for='show-iconnumber']").addEventListener( 84 document.querySelector("label[for='show-iconnumber']").addEventListener(
84 "click", toggleIconNumber, false 85 "click", toggleIconNumber, false
85 ); 86 );
86 87
87 // Update stats 88 // Update stats
88 ext.pages.query({active: true, lastFocusedWindow: true}, pages => 89 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
89 { 90 {
90 currentPage = pages[0]; 91 currentTab = tabs[0];
91 updateStats(); 92 updateStats();
92 93
93 FilterNotifier.on("filter.hitCount", updateStats); 94 FilterNotifier.on("filter.hitCount", updateStats);
94 95
95 document.getElementById("stats-container").removeAttribute("hidden"); 96 document.getElementById("stats-container").removeAttribute("hidden");
96 }); 97 });
97 } 98 }
98 99
99 function onUnload() 100 function onUnload()
100 { 101 {
101 FilterNotifier.off("filter.hitCount", updateStats); 102 FilterNotifier.off("filter.hitCount", updateStats);
102 } 103 }
103 104
104 function updateStats() 105 function updateStats()
105 { 106 {
106 let statsPage = document.getElementById("stats-page"); 107 let statsPage = document.getElementById("stats-page");
107 let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); 108 chrome.runtime.sendMessage({
108 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 });
109 117
110 let statsTotal = document.getElementById("stats-total"); 118 let statsTotal = document.getElementById("stats-total");
111 let blockedTotal = Prefs.blocked_total.toLocaleString(); 119 getPref("blocked_total", blockedTotal =>
112 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); 120 {
121 i18n.setElementText(statsTotal, "stats_label_total",
122 [blockedTotal.toLocaleString()]);
123 });
113 } 124 }
114 125
115 function share(ev) 126 function share(ev)
116 { 127 {
117 // Easter Egg 128 getPref("blocked_total", blockedTotal =>
118 let blocked = Prefs.blocked_total; 129 {
119 if (blocked <= 9000 || blocked >= 10000) 130 // Easter Egg
120 blocked = blocked.toLocaleString(); 131 if (blockedTotal <= 9000 || blockedTotal >= 10000)
121 else 132 blockedTotal = blockedTotal.toLocaleString();
122 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); 133 else
134 blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString());
123 135
124 ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); 136 chrome.tabs.create({
137 url: createShareLink(ev.target.dataset.social, blockedTotal)
138 });
139 });
125 } 140 }
126 141
127 function toggleIconNumber() 142 function toggleIconNumber()
128 { 143 {
129 Prefs.show_statsinicon = !Prefs.show_statsinicon; 144 togglePref("show_statsinicon", showStatsInIcon =>
130 document.getElementById("show-iconnumber").setAttribute( 145 {
131 "aria-checked", Prefs.show_statsinicon 146 document.getElementById("show-iconnumber").setAttribute(
132 ); 147 "aria-checked", showStatsInIcon
148 );
149 });
133 } 150 }
134 151
135 document.addEventListener("DOMContentLoaded", onLoad, false); 152 document.addEventListener("DOMContentLoaded", onLoad, false);
136 window.addEventListener("unload", onUnload, false); 153 window.addEventListener("unload", onUnload, false);
137 }()); 154 }());
OLDNEW
« popup.js ('K') | « skin/popup.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld