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

Side by Side Diff: stats.js

Issue 29570774: Issue 5593 - Merge notification.js and stats.js into popup.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Merge code Created Oct. 10, 2017, 4:58 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
« popup.js ('K') | « popup.js ('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
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 /* global getPref, togglePref */
19
20 "use strict";
21
22 (function()
23 {
24 let currentTab;
25 const shareURL = "https://adblockplus.org/";
26
27 let messageMark = {};
28 let shareLinks = {
29 facebook: ["https://www.facebook.com/dialog/feed", {
30 app_id: "475542399197328",
31 link: shareURL,
32 redirect_uri: "https://www.facebook.com/",
33 ref: "adcounter",
34 name: messageMark,
35 actions: JSON.stringify([
36 {
37 name: chrome.i18n.getMessage("stats_share_download"),
38 link: shareURL
39 }
40 ])
41 }],
42 gplus: ["https://plus.google.com/share", {
43 url: shareURL
44 }],
45 twitter: ["https://twitter.com/intent/tweet", {
46 text: messageMark,
47 url: shareURL,
48 via: "AdblockPlus"
49 }]
50 };
51
52 function createShareLink(network, blockedCount)
53 {
54 let url = shareLinks[network][0];
55 let params = shareLinks[network][1];
56
57 let querystring = [];
58 for (let key in params)
59 {
60 let value = params[key];
61 if (value == messageMark)
62 value = chrome.i18n.getMessage("stats_share_message", blockedCount);
63 querystring.push(
64 encodeURIComponent(key) + "=" + encodeURIComponent(value)
65 );
66 }
67 return url + "?" + querystring.join("&");
68 }
69
70 function onLoad()
71 {
72 document.getElementById("share-box").addEventListener("click", share,
73 false);
74 let showIconNumber = document.getElementById("show-iconnumber");
75 getPref("show_statsinicon", showStatsInIcon =>
76 {
77 showIconNumber.setAttribute("aria-checked", showStatsInIcon);
78 });
79 showIconNumber.addEventListener("click", toggleIconNumber, false);
80 document.querySelector("label[for='show-iconnumber']").addEventListener(
81 "click", toggleIconNumber, false
82 );
83
84 // Update stats
85 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
86 {
87 currentTab = tabs[0];
88 updateStats();
89
90 document.getElementById("stats-container").removeAttribute("hidden");
91 });
92 }
93
94 function updateStats()
95 {
96 let statsPage = document.getElementById("stats-page");
97 chrome.runtime.sendMessage({
98 type: "stats.getBlockedPerPage",
99 tab: currentTab
100 },
101 blockedPage =>
102 {
103 ext.i18n.setElementText(statsPage, "stats_label_page",
104 [blockedPage.toLocaleString()]);
105 });
106
107 let statsTotal = document.getElementById("stats-total");
108 getPref("blocked_total", blockedTotal =>
109 {
110 ext.i18n.setElementText(statsTotal, "stats_label_total",
111 [blockedTotal.toLocaleString()]);
112 });
113 }
114
115 function share(ev)
116 {
117 getPref("blocked_total", blockedTotal =>
118 {
119 // Easter Egg
120 if (blockedTotal <= 9000 || blockedTotal >= 10000)
121 {
122 blockedTotal = blockedTotal.toLocaleString();
123 }
124 else
125 {
126 blockedTotal = chrome.i18n.getMessage("stats_over",
127 (9000).toLocaleString());
128 }
129
130 chrome.tabs.create({
131 url: createShareLink(ev.target.dataset.social, blockedTotal)
132 });
133 });
134 }
135
136 function toggleIconNumber()
137 {
138 togglePref("show_statsinicon", showStatsInIcon =>
139 {
140 document.getElementById("show-iconnumber").setAttribute(
141 "aria-checked", showStatsInIcon
142 );
143 });
144 }
145
146 document.addEventListener("DOMContentLoaded", onLoad, false);
147 }());
OLDNEW
« popup.js ('K') | « popup.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld