Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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", "openOptions"]; | 19 var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAnd ContextMenu", "openOptions"]; |
Sebastian Noack
2013/11/19 15:22:08
I like that you have added openOptions to the impo
Thomas Greiner
2013/11/26 17:50:51
Done.
| |
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 | 26 |
27 var tab = null; | 27 var tab = null; |
28 | 28 |
29 function init() | 29 function init() |
(...skipping 14 matching lines...) Expand all Loading... | |
44 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false); | 44 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl ickHide, false); |
45 document.getElementById("options").addEventListener("click", function() | 45 document.getElementById("options").addEventListener("click", function() |
46 { | 46 { |
47 openOptions(); | 47 openOptions(); |
48 }, false); | 48 }, false); |
49 | 49 |
50 // Set up collapsing of menu items | 50 // Set up collapsing of menu items |
51 var collapsers = document.getElementsByClassName("collapse"); | 51 var collapsers = document.getElementsByClassName("collapse"); |
52 for (var i = 0; i < collapsers.length; i++) | 52 for (var i = 0; i < collapsers.length; i++) |
53 { | 53 { |
54 collapsers[i].addEventListener("click", toggleCollapse.bind(collapsers[i]), true); | 54 var collapser = collapsers[i]; |
55 if (Prefs[collapsers[i].dataset.option]) | 55 collapser.addEventListener("click", toggleCollapse, false); |
56 document.getElementById(collapsers[i].dataset.collapsable).classList.add(" collapsed"); | 56 if (!Prefs[collapser.dataset.option]) |
57 document.getElementById(collapser.dataset.collapsable).classList.add("coll apsed"); | |
57 } | 58 } |
58 | 59 |
59 // Ask content script whether clickhide is active. If so, show cancel button. | 60 // Ask content script whether clickhide is active. If so, show cancel button. |
60 // If that isn't the case, ask background.html whether it has cached filters. If so, | 61 // If that isn't the case, ask background.html whether it has cached filters. If so, |
61 // ask the user whether she wants those filters. | 62 // ask the user whether she wants those filters. |
62 // Otherwise, we are in default state. | 63 // Otherwise, we are in default state. |
63 ext.windows.getLastFocused(function(win) | 64 ext.windows.getLastFocused(function(win) |
64 { | 65 { |
65 win.getActiveTab(function(t) | 66 win.getActiveTab(function(t) |
66 { | 67 { |
67 tab = t; | 68 tab = t; |
68 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url)); | 69 document.getElementById("enabled").classList.toggle("off", isWhitelisted(t ab.url)); |
69 | 70 |
70 tab.sendMessage({type: "get-clickhide-state"}, function(response) | 71 tab.sendMessage({type: "get-clickhide-state"}, function(response) |
71 { | 72 { |
72 document.body.classList.toggle("clickhide-active", response.active); | 73 document.body.classList.toggle("clickhide-active", response.active); |
73 }); | 74 }); |
74 }); | 75 }); |
75 }); | 76 }); |
76 } | 77 } |
77 window.addEventListener("DOMContentLoaded", init, false); | 78 window.addEventListener("DOMContentLoaded", init, false); |
78 | 79 |
79 function toggleEnabled() | 80 function toggleEnabled() |
80 { | 81 { |
81 var enabledButton = document.getElementById("enabled") | 82 var enabledButton = document.getElementById("enabled") |
82 var checked = enabledButton.classList.contains("off"); | 83 var disabled = enabledButton.classList.toggle("off"); |
83 if (checked) | 84 if (disabled) |
85 { | |
86 var host = extractHostFromURL(tab.url).replace(/^www\./, ""); | |
87 var filter = Filter.fromText("@@||" + host + "^$document"); | |
88 if (filter.subscriptions.length && filter.disabled) | |
89 filter.disabled = false; | |
90 else | |
91 { | |
92 filter.disabled = false; | |
93 FilterStorage.addFilter(filter); | |
94 } | |
95 } | |
96 else | |
84 { | 97 { |
85 // Remove any exception rules applying to this URL | 98 // Remove any exception rules applying to this URL |
86 var filter = isWhitelisted(tab.url); | 99 var filter = isWhitelisted(tab.url); |
87 while (filter) | 100 while (filter) |
88 { | 101 { |
89 FilterStorage.removeFilter(filter); | 102 FilterStorage.removeFilter(filter); |
90 if (filter.subscriptions.length) | 103 if (filter.subscriptions.length) |
91 filter.disabled = true; | 104 filter.disabled = true; |
92 filter = isWhitelisted(tab.url); | 105 filter = isWhitelisted(tab.url); |
93 } | 106 } |
94 } | 107 } |
95 else | 108 |
96 { | |
97 var host = extractHostFromURL(tab.url).replace(/^www\./, ""); | |
98 var filter = Filter.fromText("@@||" + host + "^$document"); | |
99 if (filter.subscriptions.length && filter.disabled) | |
100 filter.disabled = false; | |
101 else | |
102 { | |
103 filter.disabled = false; | |
104 FilterStorage.addFilter(filter); | |
105 } | |
106 } | |
107 | |
108 enabledButton.classList.toggle("off"); | |
109 refreshIconAndContextMenu(tab); | 109 refreshIconAndContextMenu(tab); |
110 } | 110 } |
111 | 111 |
112 function activateClickHide() | 112 function activateClickHide() |
113 { | 113 { |
114 document.body.classList.add("clickhide-active"); | 114 document.body.classList.add("clickhide-active"); |
115 tab.sendMessage({type: "clickhide-activate"}); | 115 tab.sendMessage({type: "clickhide-activate"}); |
116 | 116 |
117 // Close the popup after a few seconds, so user doesn't have to | 117 // Close the popup after a few seconds, so user doesn't have to |
118 activateClickHide.timeout = window.setTimeout(window.close, 5000); | 118 activateClickHide.timeout = window.setTimeout(window.close, 5000); |
119 } | 119 } |
120 | 120 |
121 function cancelClickHide() | 121 function cancelClickHide() |
122 { | 122 { |
123 if (activateClickHide.timeout) | 123 if (activateClickHide.timeout) |
124 { | 124 { |
125 window.clearTimeout(activateClickHide.timeout); | 125 window.clearTimeout(activateClickHide.timeout); |
126 activateClickHide.timeout = null; | 126 activateClickHide.timeout = null; |
127 } | 127 } |
128 document.body.classList.remove("clickhide-active"); | 128 document.body.classList.remove("clickhide-active"); |
129 tab.sendMessage({type: "clickhide-deactivate"}); | 129 tab.sendMessage({type: "clickhide-deactivate"}); |
130 } | 130 } |
131 | 131 |
132 function openOptions() | 132 function toggleCollapse(event) |
133 { | 133 { |
134 backgroundPage.openOptions(); | 134 var collapser = event.currentTarget; |
135 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | |
136 collapser.parentNode.classList.toggle("collapsed"); | |
135 } | 137 } |
136 | |
137 function toggleCollapse(ev) | |
138 { | |
139 Prefs[this.dataset.option] = !Prefs[this.dataset.option]; | |
140 this.parentNode.classList.toggle("collapsed"); | |
141 } | |
LEFT | RIGHT |