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

Side by Side Diff: stats.js

Issue 11627039: Added ad counting functionality (Closed)
Patch Set: Created Sept. 20, 2013, 3 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 | « popup.html ('k') | webrequest.js » ('j') | 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 <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 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 (function()
19 {
20 var backgroundPage = chrome.extension.getBackgroundPage();
21 var require = backgroundPage.require;
22 var getStats = require("stats").getStats;
23 var FilterNotifier = require("filterNotifier").FilterNotifier;
24
25 var currentTabId;
26 var shareURL = "https://adblockplus.org/";
27
28 var messageMark = {};
29 var shareLinks = {
30 facebook: ["https://www.facebook.com/dialog/feed", {
31 app_id: 475542399197328,
Wladimir Palant 2013/09/24 12:43:36 Just realized that this by far exceeds the 32 bit
32 link: shareURL,
33 redirect_uri: "https://www.facebook.com/",
34 ref: "adcounter",
35 name: messageMark,
36 actions: JSON.stringify([
37 {
38 name: i18n.getMessage("stats_share_download"),
39 link: shareURL
40 }
41 ])
42 }],
43 gplus: ["https://plus.google.com/share", {
44 url: shareURL
45 }],
46 twitter: ["https://twitter.com/intent/tweet", {
47 text: messageMark,
48 url: shareURL,
49 via: "AdblockPlus"
50 }]
51 };
52
53 function createShareLink(network, blockedCount)
54 {
55 var url = shareLinks[network][0];
56 var params = shareLinks[network][1];
57
58 var querystring = [];
59 for (var key in params)
60 {
61 var value = params[key];
62 if (value == messageMark)
63 value = i18n.getMessage("stats_share_message", blockedCount);
64 querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value) );
65 }
66 return url + "?" + querystring.join("&");
67 }
68
69 function onLoad()
70 {
71 document.getElementById("shareBox").addEventListener("click", share, false);
72 document.getElementById("share").addEventListener("click", toggleShareBox, f alse);
73
74 // Update stats
75 chrome.tabs.query({
76 active: true,
77 windowId: chrome.windows.WINDOW_ID_CURRENT
78 }, function(tabs)
79 {
80 if (tabs.length > 0)
81 {
82 currentTabId = tabs[0].id;
83 updateStats();
84
85 FilterNotifier.addListener(onNotify);
86
87 document.getElementById("statsContainer").removeAttribute("hidden");
88 }
Wladimir Palant 2013/09/24 12:43:36 How about |else window.close()| here just in case?
Thomas Greiner 2013/09/24 14:40:58 Closing the popup right after a user clicked on th
Wladimir Palant 2013/09/25 08:44:51 You are right of course. I forgot that the stats a
89 });
90 }
91
92 function onUnload()
93 {
94 FilterNotifier.removeListener(onNotify);
95 }
96
97 function onNotify(action, item)
98 {
99 if (action == "filter.hitCount")
100 updateStats();
101 }
102
103 function updateStats()
104 {
105 var statsPage = document.getElementById("statsPage");
106 var blockedPage = getStats("blocked", currentTabId).toLocaleString();
107 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]);
108
109 var statsTotal = document.getElementById("statsTotal");
110 var blockedTotal = getStats("blocked").toLocaleString();
111 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]);
112 }
113
114 function toggleShareBox(ev)
115 {
116 var shareBox = document.getElementById("shareBox");
117 shareBox.hidden = !shareBox.hidden;
118 }
119
120 function share(ev)
121 {
122 // Easter Egg
123 var blocked = getStats("blocked");
124 if (blocked <= 9000 || blocked >= 10000)
125 blocked = blocked.toLocaleString();
126 else
127 blocked = i18n.getMessage("stats_over", (9000).toLocaleString());
128
129 var url = createShareLink(ev.target.dataset.social, blocked);
130 chrome.tabs.create({url: url});
131 }
132
133 document.addEventListener("DOMContentLoaded", onLoad, false);
134 window.addEventListener("unload", onUnload, false);
135 })();
OLDNEW
« no previous file with comments | « popup.html ('k') | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld