| 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 var backgroundPage = ext.backgroundPage.getWindow(); | 
| 19 var require = backgroundPage.require; | 19 var require = backgroundPage.require; | 
| 20 | 20 | 
| 21 var Filter = require("filterClasses").Filter; | 21 var Filter = require("filterClasses").Filter; | 
| 22 var FilterStorage = require("filterStorage").FilterStorage; | 22 var FilterStorage = require("filterStorage").FilterStorage; | 
| 23 var Prefs = require("prefs").Prefs; | 23 var Prefs = require("prefs").Prefs; | 
| 24 var isPageWhitelisted = require("whitelisting").isPageWhitelisted; | 24 var checkWhitelisted = require("whitelisting").checkWhitelisted; | 
| 25 var getDecodedHostname = require("url").getDecodedHostname; | 25 var getDecodedHostname = require("url").getDecodedHostname; | 
| 26 | 26 | 
| 27 var page = null; | 27 var page = null; | 
| 28 | 28 | 
| 29 function onLoad() | 29 function onLoad() | 
| 30 { | 30 { | 
| 31   ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 31   ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 
| 32   { | 32   { | 
| 33     page = pages[0]; | 33     page = pages[0]; | 
| 34 | 34 | 
| 35     // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 35     // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 
| 36     if (!page || (page.url.protocol != "http:" && | 36     if (!page || (page.url.protocol != "http:" && | 
| 37                   page.url.protocol != "https:")) | 37                   page.url.protocol != "https:")) | 
| 38       document.body.classList.add("local"); | 38       document.body.classList.add("local"); | 
| 39     else if (!backgroundPage.htmlPages.has(page)) | 39     else if (!backgroundPage.htmlPages.has(page)) | 
| 40       document.body.classList.add("nohtml"); | 40       document.body.classList.add("nohtml"); | 
| 41 | 41 | 
| 42     // Ask content script whether clickhide is active. If so, show cancel button
     . | 42     // Ask content script whether clickhide is active. If so, show cancel button
     . | 
| 43     // If that isn't the case, ask background.html whether it has cached filters
     . If so, | 43     // If that isn't the case, ask background.html whether it has cached filters
     . If so, | 
| 44     // ask the user whether she wants those filters. | 44     // ask the user whether she wants those filters. | 
| 45     // Otherwise, we are in default state. | 45     // Otherwise, we are in default state. | 
| 46     if (page) | 46     if (page) | 
| 47     { | 47     { | 
| 48       if (isPageWhitelisted(page)) | 48       if (checkWhitelisted(page)) | 
| 49         document.body.classList.add("disabled"); | 49         document.body.classList.add("disabled"); | 
| 50 | 50 | 
| 51       page.sendMessage({type: "get-clickhide-state"}, function(response) | 51       page.sendMessage({type: "get-clickhide-state"}, function(response) | 
| 52       { | 52       { | 
| 53         if (response && response.active) | 53         if (response && response.active) | 
| 54           document.body.classList.add("clickhide-active"); | 54           document.body.classList.add("clickhide-active"); | 
| 55       }); | 55       }); | 
| 56     } | 56     } | 
| 57   }); | 57   }); | 
| 58 | 58 | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 99       filter.disabled = false; | 99       filter.disabled = false; | 
| 100     else | 100     else | 
| 101     { | 101     { | 
| 102       filter.disabled = false; | 102       filter.disabled = false; | 
| 103       FilterStorage.addFilter(filter); | 103       FilterStorage.addFilter(filter); | 
| 104     } | 104     } | 
| 105   } | 105   } | 
| 106   else | 106   else | 
| 107   { | 107   { | 
| 108     // Remove any exception rules applying to this URL | 108     // Remove any exception rules applying to this URL | 
| 109     var filter = isPageWhitelisted(page); | 109     var filter = checkWhitelisted(page); | 
| 110     while (filter) | 110     while (filter) | 
| 111     { | 111     { | 
| 112       FilterStorage.removeFilter(filter); | 112       FilterStorage.removeFilter(filter); | 
| 113       if (filter.subscriptions.length) | 113       if (filter.subscriptions.length) | 
| 114         filter.disabled = true; | 114         filter.disabled = true; | 
| 115       filter = isPageWhitelisted(page); | 115       filter = checkWhitelisted(page); | 
| 116     } | 116     } | 
| 117   } | 117   } | 
| 118 } | 118 } | 
| 119 | 119 | 
| 120 function activateClickHide() | 120 function activateClickHide() | 
| 121 { | 121 { | 
| 122   document.body.classList.add("clickhide-active"); | 122   document.body.classList.add("clickhide-active"); | 
| 123   page.sendMessage({type: "clickhide-activate"}); | 123   page.sendMessage({type: "clickhide-activate"}); | 
| 124 | 124 | 
| 125   // Close the popup after a few seconds, so user doesn't have to | 125   // Close the popup after a few seconds, so user doesn't have to | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 139 | 139 | 
| 140 function toggleCollapse(event) | 140 function toggleCollapse(event) | 
| 141 { | 141 { | 
| 142   var collapser = event.currentTarget; | 142   var collapser = event.currentTarget; | 
| 143   Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 143   Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 
| 144   collapser.parentNode.classList.toggle("collapsed"); | 144   collapser.parentNode.classList.toggle("collapsed"); | 
| 145 } | 145 } | 
| 146 | 146 | 
| 147 document.addEventListener("DOMContentLoaded", onLoad, false); | 147 document.addEventListener("DOMContentLoaded", onLoad, false); | 
| 148 window.addEventListener("unload", onUnload, false); | 148 window.addEventListener("unload", onUnload, false); | 
| OLD | NEW | 
|---|