| 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 = 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 var Prefs = require("prefs").Prefs; |
| 25 | 25 |
| 26 var currentTab; | 26 var currentPage; |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 var showIconNumber = document.getElementById("show-iconnumber"); | 73 var showIconNumber = document.getElementById("show-iconnumber"); |
| 74 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); | 74 showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); |
| 75 showIconNumber.addEventListener("click", toggleIconNumber, false); | 75 showIconNumber.addEventListener("click", toggleIconNumber, false); |
| 76 document.querySelector("label[for='show-iconnumber']").addEventListener("cli
ck", toggleIconNumber, false); | 76 document.querySelector("label[for='show-iconnumber']").addEventListener("cli
ck", toggleIconNumber, false); |
| 77 | 77 |
| 78 // Update stats | 78 // Update stats |
| 79 ext.windows.getLastFocused(function(win) | 79 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
| 80 { | 80 { |
| 81 win.getActiveTab(function(tab) | 81 currentPage = pages[0]; |
| 82 { | 82 updateStats(); |
| 83 currentTab = tab; | |
| 84 updateStats(); | |
| 85 | 83 |
| 86 FilterNotifier.addListener(onNotify); | 84 FilterNotifier.addListener(onNotify); |
| 87 | 85 |
| 88 document.getElementById("stats-container").removeAttribute("hidden"); | 86 document.getElementById("stats-container").removeAttribute("hidden"); |
| 89 }); | |
| 90 }); | 87 }); |
| 91 } | 88 } |
| 92 | 89 |
| 93 function onUnload() | 90 function onUnload() |
| 94 { | 91 { |
| 95 FilterNotifier.removeListener(onNotify); | 92 FilterNotifier.removeListener(onNotify); |
| 96 } | 93 } |
| 97 | 94 |
| 98 function onNotify(action, item) | 95 function onNotify(action, item) |
| 99 { | 96 { |
| 100 if (action == "filter.hitCount") | 97 if (action == "filter.hitCount") |
| 101 updateStats(); | 98 updateStats(); |
| 102 } | 99 } |
| 103 | 100 |
| 104 function updateStats() | 101 function updateStats() |
| 105 { | 102 { |
| 106 var statsPage = document.getElementById("stats-page"); | 103 var statsPage = document.getElementById("stats-page"); |
| 107 var blockedPage = getStats("blocked", currentTab).toLocaleString(); | 104 var blockedPage = getStats("blocked", currentPage).toLocaleString(); |
| 108 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 105 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); |
| 109 | 106 |
| 110 var statsTotal = document.getElementById("stats-total"); | 107 var statsTotal = document.getElementById("stats-total"); |
| 111 var blockedTotal = getStats("blocked").toLocaleString(); | 108 var blockedTotal = getStats("blocked").toLocaleString(); |
| 112 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); | 109 i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); |
| 113 } | 110 } |
| 114 | 111 |
| 115 function share(ev) | 112 function share(ev) |
| 116 { | 113 { |
| 117 // Easter Egg | 114 // Easter Egg |
| 118 var blocked = getStats("blocked"); | 115 var blocked = getStats("blocked"); |
| 119 if (blocked <= 9000 || blocked >= 10000) | 116 if (blocked <= 9000 || blocked >= 10000) |
| 120 blocked = blocked.toLocaleString(); | 117 blocked = blocked.toLocaleString(); |
| 121 else | 118 else |
| 122 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); | 119 blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); |
| 123 | 120 |
| 124 var url = createShareLink(ev.target.dataset.social, blocked); | 121 ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); |
| 125 ext.windows.getLastFocused(function(win) { win.openTab(url); }); | |
| 126 } | 122 } |
| 127 | 123 |
| 128 function toggleIconNumber() | 124 function toggleIconNumber() |
| 129 { | 125 { |
| 130 Prefs.show_statsinicon = !Prefs.show_statsinicon; | 126 Prefs.show_statsinicon = !Prefs.show_statsinicon; |
| 131 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref
s.show_statsinicon); | 127 document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref
s.show_statsinicon); |
| 132 } | 128 } |
| 133 | 129 |
| 134 document.addEventListener("DOMContentLoaded", onLoad, false); | 130 document.addEventListener("DOMContentLoaded", onLoad, false); |
| 135 window.addEventListener("unload", onUnload, false); | 131 window.addEventListener("unload", onUnload, false); |
| 136 })(); | 132 })(); |
| OLD | NEW |