| 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 var backgroundPage = ext.backgroundPage.getWindow(); | 18 "use strict"; | 
| 19 var require = backgroundPage.require; |  | 
| 20 | 19 | 
| 21 var Filter = require("filterClasses").Filter; | 20 const backgroundPage = ext.backgroundPage.getWindow(); | 
| 22 var FilterStorage = require("filterStorage").FilterStorage; | 21 const require = backgroundPage.require; | 
| 23 var Prefs = require("prefs").Prefs; |  | 
| 24 var checkWhitelisted = require("whitelisting").checkWhitelisted; |  | 
| 25 var getDecodedHostname = require("url").getDecodedHostname; |  | 
| 26 | 22 | 
| 27 var page = null; | 23 const {Filter} = require("filterClasses"); | 
|  | 24 const {FilterStorage} = require("filterStorage"); | 
|  | 25 const {Prefs} = require("prefs"); | 
|  | 26 const {checkWhitelisted} = require("whitelisting"); | 
|  | 27 const {getDecodedHostname} = require("url"); | 
|  | 28 | 
|  | 29 let page = null; | 
| 28 | 30 | 
| 29 function onLoad() | 31 function onLoad() | 
| 30 { | 32 { | 
| 31   ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 33   ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 
| 32   { | 34   { | 
| 33     page = pages[0]; | 35     page = pages[0]; | 
| 34 | 36 | 
| 35     // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 37     // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 
| 36     if (!page || (page.url.protocol != "http:" && | 38     if (!page || (page.url.protocol != "http:" && | 
| 37                   page.url.protocol != "https:")) | 39                   page.url.protocol != "https:")) | 
| 38       document.body.classList.add("local"); | 40       document.body.classList.add("local"); | 
| 39     else if (!require("filterComposer").isPageReady(page)) | 41     else if (!require("filterComposer").isPageReady(page)) | 
| 40     { | 42     { | 
| 41       document.body.classList.add("nohtml"); | 43       document.body.classList.add("nohtml"); | 
| 42       require("messaging").getPort(window).on( | 44       require("messaging").getPort(window).on( | 
| 43         "composer.ready", function(message, sender) | 45         "composer.ready", (message, sender) => | 
| 44         { | 46         { | 
| 45           if (sender.page.id == page.id) | 47           if (sender.page.id == page.id) | 
| 46             document.body.classList.remove("nohtml"); | 48             document.body.classList.remove("nohtml"); | 
| 47         } | 49         } | 
| 48       ); | 50       ); | 
| 49     } | 51     } | 
| 50 | 52 | 
| 51     // Ask content script whether clickhide is active. If so, show cancel button
     . | 53     // Ask content script whether clickhide is active. If so, show cancel button
     . | 
| 52     // If that isn't the case, ask background.html whether it has cached filters
     . If so, | 54     // If that isn't the case, ask background.html whether it has cached filters
     . If so, | 
| 53     // ask the user whether she wants those filters. | 55     // ask the user whether she wants those filters. | 
| 54     // Otherwise, we are in default state. | 56     // Otherwise, we are in default state. | 
| 55     if (page) | 57     if (page) | 
| 56     { | 58     { | 
| 57       if (checkWhitelisted(page)) | 59       if (checkWhitelisted(page)) | 
| 58         document.body.classList.add("disabled"); | 60         document.body.classList.add("disabled"); | 
| 59 | 61 | 
| 60       page.sendMessage({type: "composer.content.getState"}, function(response) | 62       page.sendMessage({type: "composer.content.getState"}, response => | 
| 61       { | 63       { | 
| 62         if (response && response.active) | 64         if (response && response.active) | 
| 63           document.body.classList.add("clickhide-active"); | 65           document.body.classList.add("clickhide-active"); | 
| 64       }); | 66       }); | 
| 65     } | 67     } | 
| 66   }); | 68   }); | 
| 67 | 69 | 
| 68   document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
     lse); | 70   document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
     lse); | 
| 69   document.getElementById("clickhide").addEventListener("click", activateClickHi
     de, false); | 71   document.getElementById("clickhide").addEventListener("click", activateClickHi
     de, false); | 
| 70   document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
     ickHide, false); | 72   document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
     ickHide, false); | 
| 71   document.getElementById("options").addEventListener("click", function() | 73   document.getElementById("options").addEventListener("click", () => | 
| 72   { | 74   { | 
| 73     ext.showOptions(); | 75     ext.showOptions(); | 
| 74   }, false); | 76   }, false); | 
| 75 | 77 | 
| 76   // Set up collapsing of menu items | 78   // Set up collapsing of menu items | 
| 77   var collapsers = document.getElementsByClassName("collapse"); | 79   for (let collapser of document.getElementsByClassName("collapse")) | 
| 78   for (var i = 0; i < collapsers.length; i++) |  | 
| 79   { | 80   { | 
| 80     var collapser = collapsers[i]; |  | 
| 81     collapser.addEventListener("click", toggleCollapse, false); | 81     collapser.addEventListener("click", toggleCollapse, false); | 
| 82     if (!Prefs[collapser.dataset.option]) | 82     if (!Prefs[collapser.dataset.option]) | 
| 83       document.getElementById(collapser.dataset.collapsable).classList.add("coll
     apsed"); | 83       document.getElementById(collapser.dataset.collapsable).classList.add("coll
     apsed"); | 
| 84   } | 84   } | 
| 85 } | 85 } | 
| 86 | 86 | 
| 87 function toggleEnabled() | 87 function toggleEnabled() | 
| 88 { | 88 { | 
| 89   var disabled = document.body.classList.toggle("disabled"); | 89   let disabled = document.body.classList.toggle("disabled"); | 
| 90   if (disabled) | 90   if (disabled) | 
| 91   { | 91   { | 
| 92     var host = getDecodedHostname(page.url).replace(/^www\./, ""); | 92     let host = getDecodedHostname(page.url).replace(/^www\./, ""); | 
| 93     var filter = Filter.fromText("@@||" + host + "^$document"); | 93     let filter = Filter.fromText("@@||" + host + "^$document"); | 
| 94     if (filter.subscriptions.length && filter.disabled) | 94     if (filter.subscriptions.length && filter.disabled) | 
| 95       filter.disabled = false; | 95       filter.disabled = false; | 
| 96     else | 96     else | 
| 97     { | 97     { | 
| 98       filter.disabled = false; | 98       filter.disabled = false; | 
| 99       FilterStorage.addFilter(filter); | 99       FilterStorage.addFilter(filter); | 
| 100     } | 100     } | 
| 101   } | 101   } | 
| 102   else | 102   else | 
| 103   { | 103   { | 
| 104     // Remove any exception rules applying to this URL | 104     // Remove any exception rules applying to this URL | 
| 105     var filter = checkWhitelisted(page); | 105     let filter = checkWhitelisted(page); | 
| 106     while (filter) | 106     while (filter) | 
| 107     { | 107     { | 
| 108       FilterStorage.removeFilter(filter); | 108       FilterStorage.removeFilter(filter); | 
| 109       if (filter.subscriptions.length) | 109       if (filter.subscriptions.length) | 
| 110         filter.disabled = true; | 110         filter.disabled = true; | 
| 111       filter = checkWhitelisted(page); | 111       filter = checkWhitelisted(page); | 
| 112     } | 112     } | 
| 113   } | 113   } | 
| 114 } | 114 } | 
| 115 | 115 | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 128   { | 128   { | 
| 129     window.clearTimeout(activateClickHide.timeout); | 129     window.clearTimeout(activateClickHide.timeout); | 
| 130     activateClickHide.timeout = null; | 130     activateClickHide.timeout = null; | 
| 131   } | 131   } | 
| 132   document.body.classList.remove("clickhide-active"); | 132   document.body.classList.remove("clickhide-active"); | 
| 133   page.sendMessage({type: "composer.content.finished"}); | 133   page.sendMessage({type: "composer.content.finished"}); | 
| 134 } | 134 } | 
| 135 | 135 | 
| 136 function toggleCollapse(event) | 136 function toggleCollapse(event) | 
| 137 { | 137 { | 
| 138   var collapser = event.currentTarget; | 138   let collapser = event.currentTarget; | 
| 139   Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 139   Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 
| 140   collapser.parentNode.classList.toggle("collapsed"); | 140   collapser.parentNode.classList.toggle("collapsed"); | 
| 141 } | 141 } | 
| 142 | 142 | 
| 143 document.addEventListener("DOMContentLoaded", onLoad, false); | 143 document.addEventListener("DOMContentLoaded", onLoad, false); | 
| OLD | NEW | 
|---|