| OLD | NEW | 
|---|
| 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-2016 Eyeo GmbH | 3  * Copyright (C) 2006-2016 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() |  | 
| 19 { | 18 { | 
| 20   var backgroundPage = ext.backgroundPage.getWindow(); | 19   let backgroundPage = ext.backgroundPage.getWindow(); | 
| 21   var require = backgroundPage.require; | 20   let require = backgroundPage.require; | 
| 22   var getBlockedPerPage = require("stats").getBlockedPerPage; | 21   let getBlockedPerPage = require("stats").getBlockedPerPage; | 
| 23   var FilterNotifier = require("filterNotifier").FilterNotifier; | 22   let FilterNotifier = require("filterNotifier").FilterNotifier; | 
| 24   var Prefs = require("prefs").Prefs; | 23   let Prefs = require("prefs").Prefs; | 
| 25 | 24 | 
| 26   var currentPage; | 25   let currentPage; | 
| 27   var shareURL = "https://adblockplus.org/"; | 26   let shareURL = "https://adblockplus.org/"; | 
| 28 | 27 | 
| 29   var messageMark = {}; | 28   let messageMark = {}; | 
| 30   var shareLinks = { | 29   let shareLinks = { | 
| 31     facebook: ["https://www.facebook.com/dialog/feed", { | 30     facebook: ["https://www.facebook.com/dialog/feed", { | 
| 32       app_id: "475542399197328", | 31       app_id: "475542399197328", | 
| 33       link: shareURL, | 32       link: shareURL, | 
| 34       redirect_uri: "https://www.facebook.com/", | 33       redirect_uri: "https://www.facebook.com/", | 
| 35       ref: "adcounter", | 34       ref: "adcounter", | 
| 36       name: messageMark, | 35       name: messageMark, | 
| 37       actions: JSON.stringify([ | 36       actions: JSON.stringify([ | 
| 38         { | 37         { | 
| 39           name: i18n.getMessage("stats_share_download"), | 38           name: i18n.getMessage("stats_share_download"), | 
| 40           link: shareURL | 39           link: shareURL | 
| 41         } | 40         } | 
| 42       ]) | 41       ]) | 
| 43     }], | 42     }], | 
| 44     gplus: ["https://plus.google.com/share", { | 43     gplus: ["https://plus.google.com/share", { | 
| 45       url: shareURL | 44       url: shareURL | 
| 46     }], | 45     }], | 
| 47     twitter: ["https://twitter.com/intent/tweet", { | 46     twitter: ["https://twitter.com/intent/tweet", { | 
| 48       text: messageMark, | 47       text: messageMark, | 
| 49       url: shareURL, | 48       url: shareURL, | 
| 50       via: "AdblockPlus" | 49       via: "AdblockPlus" | 
| 51     }] | 50     }] | 
| 52   }; | 51   }; | 
| 53 | 52 | 
| 54   function createShareLink(network, blockedCount) | 53   function createShareLink(network, blockedCount) | 
| 55   { | 54   { | 
| 56     var url = shareLinks[network][0]; | 55     let url = shareLinks[network][0]; | 
| 57     var params = shareLinks[network][1]; | 56     let params = shareLinks[network][1]; | 
| 58 | 57 | 
| 59     var querystring = []; | 58     let querystring = []; | 
| 60     for (var key in params) | 59     for (let key in params) | 
| 61     { | 60     { | 
| 62       var value = params[key]; | 61       let value = params[key]; | 
| 63       if (value == messageMark) | 62       if (value == messageMark) | 
| 64         value = i18n.getMessage("stats_share_message", blockedCount); | 63         value = i18n.getMessage("stats_share_message", blockedCount); | 
| 65       querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value)
     ); | 64       querystring.push(encodeURIComponent(key) + "=" + encodeURIComponent(value)
     ); | 
| 66     } | 65     } | 
| 67     return url + "?" + querystring.join("&"); | 66     return url + "?" + querystring.join("&"); | 
| 68   } | 67   } | 
| 69 | 68 | 
| 70   function onLoad() | 69   function onLoad() | 
| 71   { | 70   { | 
| 72     document.getElementById("share-box").addEventListener("click", share, false)
     ; | 71     document.getElementById("share-box").addEventListener("click", share, false)
     ; | 
| 73     var showIconNumber = document.getElementById("show-iconnumber"); | 72     let showIconNumber = document.getElementById("show-iconnumber"); | 
| 74     showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); | 73     showIconNumber.setAttribute("aria-checked", Prefs.show_statsinicon); | 
| 75     showIconNumber.addEventListener("click", toggleIconNumber, false); | 74     showIconNumber.addEventListener("click", toggleIconNumber, false); | 
| 76     document.querySelector("label[for='show-iconnumber']").addEventListener("cli
     ck", toggleIconNumber, false); | 75     document.querySelector("label[for='show-iconnumber']").addEventListener("cli
     ck", toggleIconNumber, false); | 
| 77 | 76 | 
| 78     // Update stats | 77     // Update stats | 
| 79     ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 78     ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 
| 80     { | 79     { | 
| 81       currentPage = pages[0]; | 80       currentPage = pages[0]; | 
| 82       updateStats(); | 81       updateStats(); | 
| 83 | 82 | 
| 84       FilterNotifier.on("filter.hitCount", updateStats); | 83       FilterNotifier.on("filter.hitCount", updateStats); | 
| 85 | 84 | 
| 86       document.getElementById("stats-container").removeAttribute("hidden"); | 85       document.getElementById("stats-container").removeAttribute("hidden"); | 
| 87     }); | 86     }); | 
| 88   } | 87   } | 
| 89 | 88 | 
| 90   function onUnload() | 89   function onUnload() | 
| 91   { | 90   { | 
| 92     FilterNotifier.off("filter.hitCount", updateStats); | 91     FilterNotifier.off("filter.hitCount", updateStats); | 
| 93   } | 92   } | 
| 94 | 93 | 
| 95   function updateStats() | 94   function updateStats() | 
| 96   { | 95   { | 
| 97     var statsPage = document.getElementById("stats-page"); | 96     let statsPage = document.getElementById("stats-page"); | 
| 98     var blockedPage = getBlockedPerPage(currentPage).toLocaleString(); | 97     let blockedPage = getBlockedPerPage(currentPage).toLocaleString(); | 
| 99     i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 98     i18n.setElementText(statsPage, "stats_label_page", [blockedPage]); | 
| 100 | 99 | 
| 101     var statsTotal = document.getElementById("stats-total"); | 100     let statsTotal = document.getElementById("stats-total"); | 
| 102     var blockedTotal = Prefs.blocked_total.toLocaleString(); | 101     let blockedTotal = Prefs.blocked_total.toLocaleString(); | 
| 103     i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); | 102     i18n.setElementText(statsTotal, "stats_label_total", [blockedTotal]); | 
| 104   } | 103   } | 
| 105 | 104 | 
| 106   function share(ev) | 105   function share(ev) | 
| 107   { | 106   { | 
| 108     // Easter Egg | 107     // Easter Egg | 
| 109     var blocked = Prefs.blocked_total; | 108     let blocked = Prefs.blocked_total; | 
| 110     if (blocked <= 9000 || blocked >= 10000) | 109     if (blocked <= 9000 || blocked >= 10000) | 
| 111       blocked = blocked.toLocaleString(); | 110       blocked = blocked.toLocaleString(); | 
| 112     else | 111     else | 
| 113       blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); | 112       blocked = i18n.getMessage("stats_over", (9000).toLocaleString()); | 
| 114 | 113 | 
| 115     ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); | 114     ext.pages.open(createShareLink(ev.target.dataset.social, blocked)); | 
| 116   } | 115   } | 
| 117 | 116 | 
| 118   function toggleIconNumber() | 117   function toggleIconNumber() | 
| 119   { | 118   { | 
| 120     Prefs.show_statsinicon = !Prefs.show_statsinicon; | 119     Prefs.show_statsinicon = !Prefs.show_statsinicon; | 
| 121     document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref
     s.show_statsinicon); | 120     document.getElementById("show-iconnumber").setAttribute("aria-checked", Pref
     s.show_statsinicon); | 
| 122   } | 121   } | 
| 123 | 122 | 
| 124   document.addEventListener("DOMContentLoaded", onLoad, false); | 123   document.addEventListener("DOMContentLoaded", onLoad, false); | 
| 125   window.addEventListener("unload", onUnload, false); | 124   window.addEventListener("unload", onUnload, false); | 
| 126 })(); | 125 } | 
| OLD | NEW | 
|---|