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