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

Side by Side Diff: stats.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Patch Set: Merged setBadgeNumber and setBadgeBackgroundColor Created Dec. 13, 2013, 10:36 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
« skin/popup.css ('K') | « skin/popup.png ('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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 (function() 18 (function()
19 { 19 {
20 var backgroundPage = ext.backgroundPage.getWindow(); 20 var backgroundPage = ext.backgroundPage.getWindow();
21 var require = backgroundPage.require; 21 var require = backgroundPage.require;
22 var getStats = require("stats").getStats; 22 var getStats = require("stats").getStats;
23 var FilterNotifier = require("filterNotifier").FilterNotifier; 23 var FilterNotifier = require("filterNotifier").FilterNotifier;
24 var Prefs = require("prefs").Prefs;
24 25
25 var currentTab; 26 var currentTab;
26 var shareURL = "https://adblockplus.org/"; 27 var shareURL = "https://adblockplus.org/";
27 28
28 var messageMark = {}; 29 var messageMark = {};
29 var shareLinks = { 30 var shareLinks = {
30 facebook: ["https://www.facebook.com/dialog/feed", { 31 facebook: ["https://www.facebook.com/dialog/feed", {
31 app_id: "475542399197328", 32 app_id: "475542399197328",
32 link: shareURL, 33 link: shareURL,
33 redirect_uri: "https://www.facebook.com/", 34 redirect_uri: "https://www.facebook.com/",
(...skipping 27 matching lines...) Expand all
61 var value = params[key]; 62 var value = params[key];
62 if (value == messageMark) 63 if (value == messageMark)
63 value = i18n.getMessage("stats_share_message", blockedCount); 64 value = i18n.getMessage("stats_share_message", blockedCount);
64 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) ); 65 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) );
65 } 66 }
66 return url + "?" + querystring.join("&"); 67 return url + "?" + querystring.join("&");
67 } 68 }
68 69
69 function onLoad() 70 function onLoad()
70 { 71 {
71 document.getElementById("shareBox").addEventListener("click", share, false); 72 document.getElementById("share-box").addEventListener("click", share, false) ;
72 document.getElementById("share").addEventListener("click", toggleShareBox, f alse); 73 var showIconNumber = document.getElementById("show-iconnumber");
74 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon);
75 showIconNumber.addEventListener("click", toggleIconNumber, false);
76 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false);
73 77
74 // Update stats 78 // Update stats
75 ext.windows.getLastFocused(function(win) 79 ext.windows.getLastFocused(function(win)
76 { 80 {
77 win.getActiveTab(function(tab) 81 win.getActiveTab(function(tab)
78 { 82 {
79 currentTab = tab; 83 currentTab = tab;
80 updateStats(); 84 updateStats();
81 85
82 FilterNotifier.addListener(onNotify); 86 FilterNotifier.addListener(onNotify);
83 87
84 document.getElementById("statsContainer").removeAttribute("hidden"); 88 document.getElementById("stats-container").removeAttribute("hidden");
85 }); 89 });
86 }); 90 });
87 } 91 }
88 92
89 function onUnload() 93 function onUnload()
90 { 94 {
91 FilterNotifier.removeListener(onNotify); 95 FilterNotifier.removeListener(onNotify);
92 } 96 }
93 97
94 function onNotify(action, item) 98 function onNotify(action, item)
95 { 99 {
96 if (action == "filter.hitCount") 100 if (action == "filter.hitCount")
97 updateStats(); 101 updateStats();
98 } 102 }
99 103
100 function updateStats() 104 function updateStats()
101 { 105 {
102 var statsPage = document.getElementById("statsPage"); 106 var statsPage = document.getElementById("stats-page");
103 var blockedPage = getStats("blocked", currentTab).toLocaleString(); 107 var blockedPage = getStats("blocked", currentTab).toLocaleString();
104 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); 108 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
105 109
106 var statsTotal = document.getElementById("statsTotal"); 110 var statsTotal = document.getElementById("stats-total");
107 var blockedTotal = getStats("blocked").toLocaleString(); 111 var blockedTotal = getStats("blocked").toLocaleString();
108 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); 112 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
109 } 113 }
110 114
111 function toggleShareBox(ev)
112 {
113 var shareBox = document.getElementById("shareBox");
114 shareBox.hidden = !shareBox.hidden;
115 }
116
117 function share(ev) 115 function share(ev)
118 { 116 {
119 // Easter Egg 117 // Easter Egg
120 var blocked = getStats("blocked"); 118 var blocked = getStats("blocked");
121 if (blocked <= 9000 || blocked >= 10000) 119 if (blocked <= 9000 || blocked >= 10000)
122 blocked = blocked.toLocaleString(); 120 blocked = blocked.toLocaleString();
123 else 121 else
124 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); 122 blocked = i18n.getMessage("stats_over", (9000).toLocaleString());
125 123
126 var url = createShareLink(ev.target.dataset.social, blocked); 124 var url = createShareLink(ev.target.dataset.social, blocked);
127 ext.windows.getLastFocused(function(win) { win.openTab(url); }); 125 ext.windows.getLastFocused(function(win) { win.openTab(url); });
128 } 126 }
129 127
128 function toggleIconNumber()
129 {
130 Prefs.show_statsinicon = !Prefs.show_statsinicon;
131 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_statsinicon);
132 }
133
130 document.addEventListener("DOMContentLoaded", onLoad, false); 134 document.addEventListener("DOMContentLoaded", onLoad, false);
131 window.addEventListener("unload", onUnload, false); 135 window.addEventListener("unload", onUnload, false);
132 })(); 136 })();
OLDNEW
« skin/popup.css ('K') | « skin/popup.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld