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

Side by Side Diff: popup.js

Issue 29692555: Issue 5613 - Removal of social media: Share this number (Closed)
Patch Set: Addressed Manvel and Dave's feedback Created Feb. 19, 2018, 9:52 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 | « popup.html ('k') | skin/popup.css » ('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-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 "use strict"; 18 "use strict";
19 19
20 const shareURL = "https://adblockplus.org/";
21 const messageMark = {};
22
23 const shareLinks = {
24 facebook: ["https://www.facebook.com/dialog/feed", {
25 app_id: "475542399197328",
26 link: shareURL,
27 redirect_uri: "https://www.facebook.com/",
28 ref: "adcounter",
29 name: messageMark,
30 actions: JSON.stringify([
31 {
32 name: browser.i18n.getMessage("stats_share_download"),
33 link: shareURL
34 }
35 ])
36 }],
37 gplus: ["https://plus.google.com/share", {
38 url: shareURL
39 }],
40 twitter: ["https://twitter.com/intent/tweet", {
41 text: messageMark,
42 url: shareURL,
43 via: "AdblockPlus"
44 }]
45 };
46
47 let tab = null; 20 let tab = null;
48 21
49 function getPref(key, callback) 22 function getPref(key, callback)
50 { 23 {
51 browser.runtime.sendMessage({type: "prefs.get", key}, callback); 24 browser.runtime.sendMessage({type: "prefs.get", key}, callback);
52 } 25 }
53 26
54 function setPref(key, value, callback) 27 function setPref(key, value, callback)
55 { 28 {
56 browser.runtime.sendMessage({type: "prefs.set", key, value}, callback); 29 browser.runtime.sendMessage({type: "prefs.set", key, value}, callback);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 157
185 let newElement = document.createElement(tagName); 158 let newElement = document.createElement(tagName);
186 if (tagName == "a" && links && links.length) 159 if (tagName == "a" && links && links.length)
187 newElement.href = links.shift(); 160 newElement.href = links.shift();
188 insertMessage(newElement, value, links); 161 insertMessage(newElement, value, links);
189 element.appendChild(newElement); 162 element.appendChild(newElement);
190 163
191 insertMessage(element, after, links); 164 insertMessage(element, after, links);
192 } 165 }
193 166
194 function createShareLink(network, blockedCount)
195 {
196 let url = shareLinks[network][0];
197 let params = shareLinks[network][1];
198
199 let querystring = [];
200 for (let key in params)
201 {
202 let value = params[key];
203 if (value == messageMark)
204 value = browser.i18n.getMessage("stats_share_message", blockedCount);
205 querystring.push(
206 encodeURIComponent(key) + "=" + encodeURIComponent(value)
207 );
208 }
209 return url + "?" + querystring.join("&");
210 }
211
212 function updateStats() 167 function updateStats()
213 { 168 {
214 let statsPage = document.getElementById("stats-page"); 169 let statsPage = document.getElementById("stats-page");
215 browser.runtime.sendMessage({ 170 browser.runtime.sendMessage({
216 type: "stats.getBlockedPerPage", 171 type: "stats.getBlockedPerPage",
217 tab 172 tab
218 }, 173 },
219 blockedPage => 174 blockedPage =>
220 { 175 {
221 ext.i18n.setElementText(statsPage, "stats_label_page", 176 ext.i18n.setElementText(statsPage, "stats_label_page",
222 [blockedPage.toLocaleString()]); 177 [blockedPage.toLocaleString()]);
223 }); 178 });
224 179
225 let statsTotal = document.getElementById("stats-total"); 180 let statsTotal = document.getElementById("stats-total");
226 getPref("blocked_total", blockedTotal => 181 getPref("blocked_total", blockedTotal =>
227 { 182 {
228 ext.i18n.setElementText(statsTotal, "stats_label_total", 183 ext.i18n.setElementText(statsTotal, "stats_label_total",
229 [blockedTotal.toLocaleString()]); 184 [blockedTotal.toLocaleString()]);
230 }); 185 });
231 } 186 }
232 187
233 function share(event)
234 {
235 getPref("blocked_total", blockedTotal =>
236 {
237 // Easter Egg
238 if (blockedTotal <= 9000 || blockedTotal >= 10000)
239 {
240 blockedTotal = blockedTotal.toLocaleString();
241 }
242 else
243 {
244 blockedTotal = browser.i18n.getMessage("stats_over",
245 (9000).toLocaleString());
246 }
247
248 browser.tabs.create({
249 url: createShareLink(event.target.dataset.social, blockedTotal)
250 });
251 });
252 }
253
254 function toggleIconNumber() 188 function toggleIconNumber()
255 { 189 {
256 togglePref("show_statsinicon", showStatsInIcon => 190 togglePref("show_statsinicon", showStatsInIcon =>
257 { 191 {
258 document.getElementById("show-iconnumber").setAttribute( 192 document.getElementById("show-iconnumber").setAttribute(
259 "aria-checked", showStatsInIcon 193 "aria-checked", showStatsInIcon
260 ); 194 );
261 }); 195 });
262 } 196 }
263 197
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 { 270 {
337 if (value) 271 if (value)
338 { 272 {
339 document.getElementById( 273 document.getElementById(
340 collapser.dataset.collapsible 274 collapser.dataset.collapsible
341 ).classList.remove("collapsed"); 275 ).classList.remove("collapsed");
342 } 276 }
343 }); 277 });
344 } 278 }
345 279
346 document.getElementById("share-box").addEventListener("click", share);
347 let showIconNumber = document.getElementById("show-iconnumber"); 280 let showIconNumber = document.getElementById("show-iconnumber");
348 getPref("show_statsinicon", showStatsInIcon => 281 getPref("show_statsinicon", showStatsInIcon =>
349 { 282 {
350 showIconNumber.setAttribute("aria-checked", showStatsInIcon); 283 showIconNumber.setAttribute("aria-checked", showStatsInIcon);
351 }); 284 });
352 showIconNumber.addEventListener("click", toggleIconNumber); 285 showIconNumber.addEventListener("click", toggleIconNumber);
353 document.querySelector("label[for='show-iconnumber']").addEventListener( 286 document.querySelector("label[for='show-iconnumber']").addEventListener(
354 "click", toggleIconNumber 287 "click", toggleIconNumber
355 ); 288 );
356 }); 289 });
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 { 332 {
400 if (event.target.id == "notification-optout") 333 if (event.target.id == "notification-optout")
401 setPref("notifications_ignoredcategories", true); 334 setPref("notifications_ignoredcategories", true);
402 335
403 notificationElement.hidden = true; 336 notificationElement.hidden = true;
404 notification.onClicked(); 337 notification.onClicked();
405 } 338 }
406 }, true); 339 }, true);
407 }); 340 });
408 }); 341 });
OLDNEW
« no previous file with comments | « popup.html ('k') | skin/popup.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld