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

Delta Between Two Patch Sets: stats.js

Issue 29317001: Relocated icon and redesigned icon popup (Closed)
Left Patch Set: Created Nov. 7, 2013, 5:44 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« skin/popup.css ('K') | « skin/popup.png ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 = 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 var Prefs = require("prefs").Prefs;
25 25
26 var currentTabId; 26 var currentTab;
27 var shareURL = "https://adblockplus.org/"; 27 var shareURL = "https://adblockplus.org/";
28 28
29 var messageMark = {}; 29 var messageMark = {};
30 var shareLinks = { 30 var shareLinks = {
31 facebook: ["https://www.facebook.com/dialog/feed", { 31 facebook: ["https://www.facebook.com/dialog/feed", {
32 app_id: "475542399197328", 32 app_id: "475542399197328",
33 link: shareURL, 33 link: shareURL,
34 redirect_uri: "https://www.facebook.com/", 34 redirect_uri: "https://www.facebook.com/",
35 ref: "adcounter", 35 ref: "adcounter",
36 name: messageMark, 36 name: messageMark,
(...skipping 26 matching lines...) Expand all
63 if (value == messageMark) 63 if (value == messageMark)
64 value = i18n.getMessage("stats_share_message", blockedCount); 64 value = i18n.getMessage("stats_share_message", blockedCount);
65 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) ); 65 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) );
66 } 66 }
67 return url + "?" + querystring.join("&"); 67 return url + "?" + querystring.join("&");
68 } 68 }
69 69
70 function onLoad() 70 function onLoad()
71 { 71 {
72 document.getElementById("share-box").addEventListener("click", share, false) ; 72 document.getElementById("share-box").addEventListener("click", share, false) ;
73 document.getElementById("share").addEventListener("click", toggleShareBox, f alse);
74 var showIconNumber = document.getElementById("show-iconnumber"); 73 var showIconNumber = document.getElementById("show-iconnumber");
75 showIconNumber.setAttribute("aria-checked", Prefs.show_iconnumber); 74 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon);
76 showIconNumber.addEventListener("click", toggleIconNumber, false); 75 showIconNumber.addEventListener("click", toggleIconNumber, false);
77 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false); 76 document.querySelector("label[for='show-iconnumber']").addEventListener("cli ck", toggleIconNumber, false);
78 77
79 // Update stats 78 // Update stats
80 chrome.tabs.query({ 79 ext.windows.getLastFocused(function(win)
81 active: true,
82 windowId: chrome.windows.WINDOW_ID_CURRENT
83 }, function(tabs)
84 { 80 {
85 if (tabs.length > 0) 81 win.getActiveTab(function(tab)
86 { 82 {
87 currentTabId = tabs[0].id; 83 currentTab = tab;
88 updateStats(); 84 updateStats();
89 85
90 FilterNotifier.addListener(onNotify); 86 FilterNotifier.addListener(onNotify);
91 87
92 document.getElementById("stats-container").removeAttribute("hidden"); 88 document.getElementById("stats-container").removeAttribute("hidden");
93 } 89 });
94 }); 90 });
95 } 91 }
96 92
97 function onUnload() 93 function onUnload()
98 { 94 {
99 FilterNotifier.removeListener(onNotify); 95 FilterNotifier.removeListener(onNotify);
100 } 96 }
101 97
102 function onNotify(action, item) 98 function onNotify(action, item)
103 { 99 {
104 if (action == "filter.hitCount") 100 if (action == "filter.hitCount")
105 updateStats(); 101 updateStats();
106 } 102 }
107 103
108 function updateStats() 104 function updateStats()
109 { 105 {
110 var statsPage = document.getElementById("stats-page"); 106 var statsPage = document.getElementById("stats-page");
111 var blockedPage = getStats("blocked", currentTabId).toLocaleString(); 107 var blockedPage = getStats("blocked", currentTab).toLocaleString();
112 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); 108 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
113 109
114 var statsTotal = document.getElementById("stats-total"); 110 var statsTotal = document.getElementById("stats-total");
115 var blockedTotal = getStats("blocked").toLocaleString(); 111 var blockedTotal = getStats("blocked").toLocaleString();
116 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); 112 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
117 }
118
119 function toggleShareBox(ev)
120 {
121 var shareBox = document.getElementById("share-box");
122 shareBox.hidden = !shareBox.hidden;
123 } 113 }
124 114
125 function share(ev) 115 function share(ev)
126 { 116 {
127 // Easter Egg 117 // Easter Egg
128 var blocked = getStats("blocked"); 118 var blocked = getStats("blocked");
129 if (blocked <= 9000 || blocked >= 10000) 119 if (blocked <= 9000 || blocked >= 10000)
130 blocked = blocked.toLocaleString(); 120 blocked = blocked.toLocaleString();
131 else 121 else
132 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); 122 blocked = i18n.getMessage("stats_over", (9000).toLocaleString());
133 123
134 var url = createShareLink(ev.target.dataset.social, blocked); 124 var url = createShareLink(ev.target.dataset.social, blocked);
135 chrome.tabs.create({url: url}); 125 ext.windows.getLastFocused(function(win) { win.openTab(url); });
136 } 126 }
137 127
138 function toggleIconNumber() 128 function toggleIconNumber()
139 { 129 {
140 Prefs.show_iconnumber = !Prefs.show_iconnumber; 130 Prefs.show_statsinicon = !Prefs.show_statsinicon;
141 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_iconnumber); 131 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref s.show_statsinicon);
142 } 132 }
143 133
144 document.addEventListener("DOMContentLoaded", onLoad, false); 134 document.addEventListener("DOMContentLoaded", onLoad, false);
145 window.addEventListener("unload", onUnload, false); 135 window.addEventListener("unload", onUnload, false);
146 })(); 136 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld