| 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-2014 Eyeo GmbH | 3  * Copyright (C) 2006-2014 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 imports = ["require", "extractHostFromURL", "openOptions"]; | 19 var imports = ["require", "extractHostFromURL", "openOptions"]; | 
| 20 for (var i = 0; i < imports.length; i++) | 20 for (var i = 0; i < imports.length; i++) | 
| 21   window[imports[i]] = backgroundPage[imports[i]]; | 21   window[imports[i]] = backgroundPage[imports[i]]; | 
| 22 | 22 | 
| 23 var Filter = require("filterClasses").Filter; | 23 var Filter = require("filterClasses").Filter; | 
| 24 var FilterStorage = require("filterStorage").FilterStorage; | 24 var FilterStorage = require("filterStorage").FilterStorage; | 
| 25 var Prefs = require("prefs").Prefs; | 25 var Prefs = require("prefs").Prefs; | 
| 26 var isWhitelisted = require("whitelisting").isWhitelisted; | 26 var isWhitelisted = require("whitelisting").isWhitelisted; | 
| 27 | 27 | 
| 28 var tab = null; | 28 var page = null; | 
| 29 | 29 | 
| 30 function init() | 30 function init() | 
| 31 { | 31 { | 
| 32   // Mark page as local to hide non-relevant elements | 32   ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 
| 33   ext.windows.getLastFocused(function(win) |  | 
| 34   { | 33   { | 
| 35     win.getActiveTab(function(tab) | 34     page = pages[0]; | 
|  | 35 | 
|  | 36     // Mark page as local to hide non-relevant elements | 
|  | 37     if (!page || !/^https?:\/\//.test(page.url)) | 
|  | 38       document.body.classList.add("local"); | 
|  | 39 | 
|  | 40     // Ask content script whether clickhide is active. If so, show cancel button
     . | 
|  | 41     // If that isn't the case, ask background.html whether it has cached filters
     . If so, | 
|  | 42     // ask the user whether she wants those filters. | 
|  | 43     // Otherwise, we are in default state. | 
|  | 44     if (page) | 
| 36     { | 45     { | 
| 37       if (!/^https?:\/\//.exec(tab.url)) | 46       if (isWhitelisted(page.url)) | 
| 38         document.body.classList.add("local"); | 47         document.getElementById("enabled").classList.add("off"); | 
| 39     }); | 48 | 
|  | 49       page.sendMessage({type: "get-clickhide-state"}, function(response) | 
|  | 50       { | 
|  | 51         if (response && response.active) | 
|  | 52           document.body.classList.add("clickhide-active"); | 
|  | 53       }); | 
|  | 54     } | 
| 40   }); | 55   }); | 
| 41 | 56 | 
| 42   // Attach event listeners | 57   // Attach event listeners | 
| 43   document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
     lse); | 58   document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
     lse); | 
| 44   document.getElementById("clickhide").addEventListener("click", activateClickHi
     de, false); | 59   document.getElementById("clickhide").addEventListener("click", activateClickHi
     de, false); | 
| 45   document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
     ickHide, false); | 60   document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
     ickHide, false); | 
| 46   document.getElementById("options").addEventListener("click", function() | 61   document.getElementById("options").addEventListener("click", function() | 
| 47   { | 62   { | 
| 48     openOptions(); | 63     openOptions(); | 
| 49   }, false); | 64   }, false); | 
| 50 | 65 | 
| 51   // Set up collapsing of menu items | 66   // Set up collapsing of menu items | 
| 52   var collapsers = document.getElementsByClassName("collapse"); | 67   var collapsers = document.getElementsByClassName("collapse"); | 
| 53   for (var i = 0; i < collapsers.length; i++) | 68   for (var i = 0; i < collapsers.length; i++) | 
| 54   { | 69   { | 
| 55     var collapser = collapsers[i]; | 70     var collapser = collapsers[i]; | 
| 56     collapser.addEventListener("click", toggleCollapse, false); | 71     collapser.addEventListener("click", toggleCollapse, false); | 
| 57     if (!Prefs[collapser.dataset.option]) | 72     if (!Prefs[collapser.dataset.option]) | 
| 58       document.getElementById(collapser.dataset.collapsable).classList.add("coll
     apsed"); | 73       document.getElementById(collapser.dataset.collapsable).classList.add("coll
     apsed"); | 
| 59   } | 74   } | 
| 60 |  | 
| 61   // Ask content script whether clickhide is active. If so, show cancel button. |  | 
| 62   // If that isn't the case, ask background.html whether it has cached filters. 
     If so, |  | 
| 63   // ask the user whether she wants those filters. |  | 
| 64   // Otherwise, we are in default state. |  | 
| 65   ext.windows.getLastFocused(function(win) |  | 
| 66   { |  | 
| 67     win.getActiveTab(function(t) |  | 
| 68     { |  | 
| 69       tab = t; |  | 
| 70       if (isWhitelisted(tab.url)) |  | 
| 71         document.getElementById("enabled").classList.add("off"); |  | 
| 72 |  | 
| 73       tab.sendMessage({type: "get-clickhide-state"}, function(response) |  | 
| 74       { |  | 
| 75         if (response && response.active) |  | 
| 76           document.body.classList.add("clickhide-active"); |  | 
| 77       }); |  | 
| 78     }); |  | 
| 79   }); |  | 
| 80 } | 75 } | 
| 81 window.addEventListener("DOMContentLoaded", init, false); | 76 window.addEventListener("DOMContentLoaded", init, false); | 
| 82 | 77 | 
| 83 function toggleEnabled() | 78 function toggleEnabled() | 
| 84 { | 79 { | 
| 85   var enabledButton = document.getElementById("enabled") | 80   var enabledButton = document.getElementById("enabled") | 
| 86   var disabled = enabledButton.classList.toggle("off"); | 81   var disabled = enabledButton.classList.toggle("off"); | 
| 87   if (disabled) | 82   if (disabled) | 
| 88   { | 83   { | 
| 89     var host = extractHostFromURL(tab.url).replace(/^www\./, ""); | 84     var host = extractHostFromURL(page.url).replace(/^www\./, ""); | 
| 90     var filter = Filter.fromText("@@||" + host + "^$document"); | 85     var filter = Filter.fromText("@@||" + host + "^$document"); | 
| 91     if (filter.subscriptions.length && filter.disabled) | 86     if (filter.subscriptions.length && filter.disabled) | 
| 92       filter.disabled = false; | 87       filter.disabled = false; | 
| 93     else | 88     else | 
| 94     { | 89     { | 
| 95       filter.disabled = false; | 90       filter.disabled = false; | 
| 96       FilterStorage.addFilter(filter); | 91       FilterStorage.addFilter(filter); | 
| 97     } | 92     } | 
| 98   } | 93   } | 
| 99   else | 94   else | 
| 100   { | 95   { | 
| 101     // Remove any exception rules applying to this URL | 96     // Remove any exception rules applying to this URL | 
| 102     var filter = isWhitelisted(tab.url); | 97     var filter = isWhitelisted(page.url); | 
| 103     while (filter) | 98     while (filter) | 
| 104     { | 99     { | 
| 105       FilterStorage.removeFilter(filter); | 100       FilterStorage.removeFilter(filter); | 
| 106       if (filter.subscriptions.length) | 101       if (filter.subscriptions.length) | 
| 107         filter.disabled = true; | 102         filter.disabled = true; | 
| 108       filter = isWhitelisted(tab.url); | 103       filter = isWhitelisted(page.url); | 
| 109     } | 104     } | 
| 110   } | 105   } | 
| 111 } | 106 } | 
| 112 | 107 | 
| 113 function activateClickHide() | 108 function activateClickHide() | 
| 114 { | 109 { | 
| 115   document.body.classList.add("clickhide-active"); | 110   document.body.classList.add("clickhide-active"); | 
| 116   tab.sendMessage({type: "clickhide-activate"}); | 111   page.sendMessage({type: "clickhide-activate"}); | 
| 117 | 112 | 
| 118   // Close the popup after a few seconds, so user doesn't have to | 113   // Close the popup after a few seconds, so user doesn't have to | 
| 119   activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); | 114   activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); | 
| 120 } | 115 } | 
| 121 | 116 | 
| 122 function cancelClickHide() | 117 function cancelClickHide() | 
| 123 { | 118 { | 
| 124   if (activateClickHide.timeout) | 119   if (activateClickHide.timeout) | 
| 125   { | 120   { | 
| 126     window.clearTimeout(activateClickHide.timeout); | 121     window.clearTimeout(activateClickHide.timeout); | 
| 127     activateClickHide.timeout = null; | 122     activateClickHide.timeout = null; | 
| 128   } | 123   } | 
| 129   document.body.classList.remove("clickhide-active"); | 124   document.body.classList.remove("clickhide-active"); | 
| 130   tab.sendMessage({type: "clickhide-deactivate"}); | 125   page.sendMessage({type: "clickhide-deactivate"}); | 
| 131 } | 126 } | 
| 132 | 127 | 
| 133 function toggleCollapse(event) | 128 function toggleCollapse(event) | 
| 134 { | 129 { | 
| 135   var collapser = event.currentTarget; | 130   var collapser = event.currentTarget; | 
| 136   Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 131   Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 
| 137   collapser.parentNode.classList.toggle("collapsed"); | 132   collapser.parentNode.classList.toggle("collapsed"); | 
| 138 } | 133 } | 
| OLD | NEW | 
|---|