OLD | NEW |
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 | 24 |
25 var currentTabId; | 25 var currentTab; |
26 var shareURL = "https://adblockplus.org/"; | 26 var shareURL = "https://adblockplus.org/"; |
27 | 27 |
28 var messageMark = {}; | 28 var messageMark = {}; |
29 var shareLinks = { | 29 var shareLinks = { |
30 facebook: ["https://www.facebook.com/dialog/feed", { | 30 facebook: ["https://www.facebook.com/dialog/feed", { |
31 app_id: "475542399197328", | 31 app_id: "475542399197328", |
32 link: shareURL, | 32 link: shareURL, |
33 redirect_uri: "https://www.facebook.com/", | 33 redirect_uri: "https://www.facebook.com/", |
34 ref: "adcounter", | 34 ref: "adcounter", |
35 name: messageMark, | 35 name: messageMark, |
(...skipping 29 matching lines...) Expand all Loading... |
65 } | 65 } |
66 return url + "?" + querystring.join("&"); | 66 return url + "?" + querystring.join("&"); |
67 } | 67 } |
68 | 68 |
69 function onLoad() | 69 function onLoad() |
70 { | 70 { |
71 document.getElementById("shareBox").addEventListener("click", share, false); | 71 document.getElementById("shareBox").addEventListener("click", share, false); |
72 document.getElementById("share").addEventListener("click", toggleShareBox, f
alse); | 72 document.getElementById("share").addEventListener("click", toggleShareBox, f
alse); |
73 | 73 |
74 // Update stats | 74 // Update stats |
75 chrome.tabs.query({ | 75 ext.windows.getLastFocused(function(win) |
76 active: true, | |
77 windowId: chrome.windows.WINDOW_ID_CURRENT | |
78 }, function(tabs) | |
79 { | 76 { |
80 if (tabs.length > 0) | 77 win.getActiveTab(function(tab) |
81 { | 78 { |
82 currentTabId = tabs[0].id; | 79 currentTab = tab; |
83 updateStats(); | 80 updateStats(); |
84 | 81 |
85 FilterNotifier.addListener(onNotify); | 82 FilterNotifier.addListener(onNotify); |
86 | 83 |
87 document.getElementById("statsContainer").removeAttribute("hidden"); | 84 document.getElementById("statsContainer").removeAttribute("hidden"); |
88 } | 85 }); |
89 }); | 86 }); |
90 } | 87 } |
91 | 88 |
92 function onUnload() | 89 function onUnload() |
93 { | 90 { |
94 FilterNotifier.removeListener(onNotify); | 91 FilterNotifier.removeListener(onNotify); |
95 } | 92 } |
96 | 93 |
97 function onNotify(action, item) | 94 function onNotify(action, item) |
98 { | 95 { |
99 if (action == "filter.hitCount") | 96 if (action == "filter.hitCount") |
100 updateStats(); | 97 updateStats(); |
101 } | 98 } |
102 | 99 |
103 function updateStats() | 100 function updateStats() |
104 { | 101 { |
105 var statsPage = document.getElementById("statsPage"); | 102 var statsPage = document.getElementById("statsPage"); |
106 var blockedPage = getStats("blocked", currentTabId).toLocaleString(); | 103 var blockedPage = getStats("blocked", currentTab).toLocaleString(); |
107 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 104 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); |
108 | 105 |
109 var statsTotal = document.getElementById("statsTotal"); | 106 var statsTotal = document.getElementById("statsTotal"); |
110 var blockedTotal = getStats("blocked").toLocaleString(); | 107 var blockedTotal = getStats("blocked").toLocaleString(); |
111 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); | 108 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); |
112 } | 109 } |
113 | 110 |
114 function toggleShareBox(ev) | 111 function toggleShareBox(ev) |
115 { | 112 { |
116 var shareBox = document.getElementById("shareBox"); | 113 var shareBox = document.getElementById("shareBox"); |
117 shareBox.hidden = !shareBox.hidden; | 114 shareBox.hidden = !shareBox.hidden; |
118 } | 115 } |
119 | 116 |
120 function share(ev) | 117 function share(ev) |
121 { | 118 { |
122 // Easter Egg | 119 // Easter Egg |
123 var blocked = getStats("blocked"); | 120 var blocked = getStats("blocked"); |
124 if (blocked <= 9000 || blocked >= 10000) | 121 if (blocked <= 9000 || blocked >= 10000) |
125 blocked = blocked.toLocaleString(); | 122 blocked = blocked.toLocaleString(); |
126 else | 123 else |
127 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); | 124 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); |
128 | 125 |
129 var url = createShareLink(ev.target.dataset.social, blocked); | 126 var url = createShareLink(ev.target.dataset.social, blocked); |
130 chrome.tabs.create({url: url}); | 127 ext.windows.getLastFocused(function(win) { win.openTab(url); }); |
131 } | 128 } |
132 | 129 |
133 document.addEventListener("DOMContentLoaded", onLoad, false); | 130 document.addEventListener("DOMContentLoaded", onLoad, false); |
134 window.addEventListener("unload", onUnload, false); | 131 window.addEventListener("unload", onUnload, false); |
135 })(); | 132 })(); |
OLD | NEW |