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: Created Nov. 7, 2013, 5:44 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
« no previous file with comments | « 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 = chrome.extension.getBackgroundPage(); 20 var backgroundPage = chrome.extension.getBackgroundPage();
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 currentTabId; 26 var currentTabId;
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 document.getElementById("share").addEventListener("click", toggleShareBox, f alse);
74 var showIconNumber = document.getElementById("show-iconnumber");
75 showIconNumber.setAttribute("aria-checked", Prefs.show_iconnumber);
76 showIconNumber.addEventListener("click", toggleIconNumber, false);
77 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false);
73 78
74 // Update stats 79 // Update stats
75 chrome.tabs.query({ 80 chrome.tabs.query({
76 active: true, 81 active: true,
77 windowId: chrome.windows.WINDOW_ID_CURRENT 82 windowId: chrome.windows.WINDOW_ID_CURRENT
78 }, function(tabs) 83 }, function(tabs)
79 { 84 {
80 if (tabs.length > 0) 85 if (tabs.length > 0)
81 { 86 {
82 currentTabId = tabs[0].id; 87 currentTabId = tabs[0].id;
83 updateStats(); 88 updateStats();
84 89
85 FilterNotifier.addListener(onNotify); 90 FilterNotifier.addListener(onNotify);
86 91
87 document.getElementById("statsContainer").removeAttribute("hidden"); 92 document.getElementById("stats-container").removeAttribute("hidden");
88 } 93 }
89 }); 94 });
90 } 95 }
91 96
92 function onUnload() 97 function onUnload()
93 { 98 {
94 FilterNotifier.removeListener(onNotify); 99 FilterNotifier.removeListener(onNotify);
95 } 100 }
96 101
97 function onNotify(action, item) 102 function onNotify(action, item)
98 { 103 {
99 if (action == "filter.hitCount") 104 if (action == "filter.hitCount")
100 updateStats(); 105 updateStats();
101 } 106 }
102 107
103 function updateStats() 108 function updateStats()
104 { 109 {
105 var statsPage = document.getElementById("statsPage"); 110 var statsPage = document.getElementById("stats-page");
106 var blockedPage = getStats("blocked", currentTabId).toLocaleString(); 111 var blockedPage = getStats("blocked", currentTabId).toLocaleString();
107 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); 112 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
108 113
109 var statsTotal = document.getElementById("statsTotal"); 114 var statsTotal = document.getElementById("stats-total");
110 var blockedTotal = getStats("blocked").toLocaleString(); 115 var blockedTotal = getStats("blocked").toLocaleString();
111 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); 116 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
112 } 117 }
113 118
114 function toggleShareBox(ev) 119 function toggleShareBox(ev)
115 { 120 {
116 var shareBox = document.getElementById("shareBox"); 121 var shareBox = document.getElementById("share-box");
117 shareBox.hidden = !shareBox.hidden; 122 shareBox.hidden = !shareBox.hidden;
118 } 123 }
119 124
120 function share(ev) 125 function share(ev)
121 { 126 {
122 // Easter Egg 127 // Easter Egg
123 var blocked = getStats("blocked"); 128 var blocked = getStats("blocked");
124 if (blocked <= 9000 || blocked >= 10000) 129 if (blocked <= 9000 || blocked >= 10000)
125 blocked = blocked.toLocaleString(); 130 blocked = blocked.toLocaleString();
126 else 131 else
127 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); 132 blocked = i18n.getMessage("stats_over", (9000).toLocaleString());
128 133
129 var url = createShareLink(ev.target.dataset.social, blocked); 134 var url = createShareLink(ev.target.dataset.social, blocked);
130 chrome.tabs.create({url: url}); 135 chrome.tabs.create({url: url});
131 } 136 }
132 137
138 function toggleIconNumber()
139 {
140 Prefs.show_iconnumber = !Prefs.show_iconnumber;
141 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_iconnumber);
142 }
143
133 document.addEventListener("DOMContentLoaded", onLoad, false); 144 document.addEventListener("DOMContentLoaded", onLoad, false);
134 window.addEventListener("unload", onUnload, false); 145 window.addEventListener("unload", onUnload, false);
135 })(); 146 })();
OLDNEW
« no previous file with comments | « skin/popup.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld