| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 /* global i18n */ | 18 /* global i18n, getPref, togglePref */ |
| 19 | 19 |
| 20 "use strict"; | 20 "use strict"; |
| 21 | 21 |
| 22 (function() | 22 (function() |
| 23 { | 23 { |
| 24 const {require} = ext.backgroundPage.getWindow(); | 24 const {require} = ext.backgroundPage.getWindow(); |
| 25 | 25 |
| 26 const {getBlockedPerPage} = require("stats"); | |
| 27 const {FilterNotifier} = require("filterNotifier"); | 26 const {FilterNotifier} = require("filterNotifier"); |
| 28 | 27 |
| 29 let currentPage; | 28 let currentTab; |
| 30 const shareURL = "https://adblockplus.org/"; | 29 const shareURL = "https://adblockplus.org/"; |
| 31 | 30 |
| 32 let messageMark = {}; | 31 let messageMark = {}; |
| 33 let shareLinks = { | 32 let shareLinks = { |
| 34 facebook: ["https://www.facebook.com/dialog/feed", { | 33 facebook: ["https://www.facebook.com/dialog/feed", { |
| 35 app_id: "475542399197328", | 34 app_id: "475542399197328", |
| 36 link: shareURL, | 35 link: shareURL, |
| 37 redirect_uri: "https://www.facebook.com/", | 36 redirect_uri: "https://www.facebook.com/", |
| 38 ref: "adcounter", | 37 ref: "adcounter", |
| 39 name: messageMark, | 38 name: messageMark, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 70 ); | 69 ); |
| 71 } | 70 } |
| 72 return url + "?" + querystring.join("&"); | 71 return url + "?" + querystring.join("&"); |
| 73 } | 72 } |
| 74 | 73 |
| 75 function onLoad() | 74 function onLoad() |
| 76 { | 75 { |
| 77 document.getElementById("share-box").addEventListener("click", share, | 76 document.getElementById("share-box").addEventListener("click", share, |
| 78 false); | 77 false); |
| 79 let showIconNumber = document.getElementById("show-iconnumber"); | 78 let showIconNumber = document.getElementById("show-iconnumber"); |
| 80 ext.prefs.get("show_statsinicon", showStatsInIcon => | 79 getPref("show_statsinicon", showStatsInIcon => |
| 81 { | 80 { |
| 82 showIconNumber.setAttribute("aria-checked", showStatsInIcon); | 81 showIconNumber.setAttribute("aria-checked", showStatsInIcon); |
| 83 }); | 82 }); |
| 84 showIconNumber.addEventListener("click", toggleIconNumber, false); | 83 showIconNumber.addEventListener("click", toggleIconNumber, false); |
| 85 document.querySelector("label[for='show-iconnumber']").addEventListener( | 84 document.querySelector("label[for='show-iconnumber']").addEventListener( |
| 86 "click", toggleIconNumber, false | 85 "click", toggleIconNumber, false |
| 87 ); | 86 ); |
| 88 | 87 |
| 89 // Update stats | 88 // Update stats |
| 90 ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 89 chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => |
| 91 { | 90 { |
| 92 currentPage = pages[0]; | 91 currentTab = tabs[0]; |
| 93 updateStats(); | 92 updateStats(); |
| 94 | 93 |
| 95 FilterNotifier.on("filter.hitCount", updateStats); | 94 FilterNotifier.on("filter.hitCount", updateStats); |
| 96 | 95 |
| 97 document.getElementById("stats-container").removeAttribute("hidden"); | 96 document.getElementById("stats-container").removeAttribute("hidden"); |
| 98 }); | 97 }); |
| 99 } | 98 } |
| 100 | 99 |
| 101 function onUnload() | 100 function onUnload() |
| 102 { | 101 { |
| 103 FilterNotifier.off("filter.hitCount", updateStats); | 102 FilterNotifier.off("filter.hitCount", updateStats); |
| 104 } | 103 } |
| 105 | 104 |
| 106 function updateStats() | 105 function updateStats() |
| 107 { | 106 { |
| 108 let statsPage = document.getElementById("stats-page"); | 107 let statsPage = document.getElementById("stats-page"); |
| 109 let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); | 108 chrome.runtime.sendMessage({ |
| 110 i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 109 type: "stats.getBlockedPerPage", |
| 110 tab: currentTab | |
| 111 }, | |
| 112 blockedPage => | |
| 113 { | |
| 114 i18n.setElementText(statsPage, "stats_label_page", | |
| 115 [blockedPage.toLocaleString()]); | |
| 116 }); | |
| 111 | 117 |
| 112 let statsTotal = document.getElementById("stats-total"); | 118 let statsTotal = document.getElementById("stats-total"); |
| 113 ext.prefs.get("blocked_total", blockedTotal => | 119 getPref("blocked_total", blockedTotal => |
| 114 { | 120 { |
| 115 i18n.setElementText(statsTotal, "stats_label_total", | 121 i18n.setElementText(statsTotal, "stats_label_total", |
| 116 [blockedTotal.toLocaleString()]); | 122 [blockedTotal.toLocaleString()]); |
| 117 }); | 123 }); |
| 118 } | 124 } |
| 119 | 125 |
| 120 function share(ev) | 126 function share(ev) |
| 121 { | 127 { |
| 122 ext.prefs.get("blocked_total", blockedTotal => | 128 getPref("blocked_total", blockedTotal => |
| 123 { | 129 { |
| 124 // Easter Egg | 130 // Easter Egg |
| 125 if (blockedTotal <= 9000 || blockedTotal >= 10000) | 131 if (blockedTotal <= 9000 || blockedTotal >= 10000) |
| 126 blockedTotal = blockedTotal.toLocaleString(); | 132 blockedTotal = blockedTotal.toLocaleString(); |
| 127 else | 133 else |
| 128 blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString()); | 134 blockedTotal = i18n.getMessage("stats_over", (9000).toLocaleString()); |
| 129 | 135 |
| 130 ext.pages.open(createShareLink(ev.target.dataset.social, blockedTotal)); | 136 ext.pages.open(createShareLink(ev.target.dataset.social, blockedTotal)); |
|
Manish Jethani
2017/09/27 09:42:32
Sorry, I forgot this one.
| |
| 131 }); | 137 }); |
| 132 } | 138 } |
| 133 | 139 |
| 134 function toggleIconNumber() | 140 function toggleIconNumber() |
| 135 { | 141 { |
| 136 ext.prefs.toggle("show_statsinicon", () => | 142 togglePref("show_statsinicon", showStatsInIcon => |
| 137 { | 143 { |
| 138 ext.prefs.get("show_statsinicon", showStatsInIcon => | 144 document.getElementById("show-iconnumber").setAttribute( |
|
Manish Jethani
2017/09/01 15:56:20
Calling prefs.get here to get the new value should
| |
| 139 { | 145 "aria-checked", showStatsInIcon |
| 140 document.getElementById("show-iconnumber").setAttribute( | 146 ); |
| 141 "aria-checked", showStatsInIcon | |
| 142 ); | |
| 143 }); | |
| 144 }); | 147 }); |
| 145 } | 148 } |
| 146 | 149 |
| 147 document.addEventListener("DOMContentLoaded", onLoad, false); | 150 document.addEventListener("DOMContentLoaded", onLoad, false); |
| 148 window.addEventListener("unload", onUnload, false); | 151 window.addEventListener("unload", onUnload, false); |
| 149 }()); | 152 }()); |
| LEFT | RIGHT |