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 = chrome.extension.getBackgroundPage(); | 18 var backgroundPage = ext.backgroundPage.getDOMWindow(); |
19 var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAnd
ContextMenu"]; | 19 var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAnd
ContextMenu"]; |
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 | 25 |
26 var tab = null; | 26 var tab = null; |
27 | 27 |
28 function init() | 28 function init() |
29 { | 29 { |
30 // Attach event listeners | 30 // Attach event listeners |
31 $("#enabled").click(toggleEnabled); | 31 $("#enabled").click(toggleEnabled); |
32 $("#clickHideButton").click(activateClickHide); | 32 $("#clickHideButton").click(activateClickHide); |
33 $("#cancelButton").click(cancelClickHide); | 33 $("#cancelButton").click(cancelClickHide); |
| 34 $("#optionsButton").click(openOptions); |
34 | 35 |
35 // Ask content script whether clickhide is active. If so, show cancel button. | 36 // Ask content script whether clickhide is active. If so, show cancel button. |
36 // If that isn't the case, ask background.html whether it has cached filters.
If so, | 37 // If that isn't the case, ask background.html whether it has cached filters.
If so, |
37 // ask the user whether she wants those filters. | 38 // ask the user whether she wants those filters. |
38 // Otherwise, we are in default state. | 39 // Otherwise, we are in default state. |
39 chrome.windows.getCurrent(function(w) | 40 ext.windows.getLastFocused(function(win) { |
40 { | 41 win.getActiveTab(function(t) { |
41 chrome.tabs.getSelected(w.id, function(t) | |
42 { | |
43 tab = t; | 42 tab = t; |
44 document.getElementById("enabled").checked = !isWhitelisted(tab.url); | 43 document.getElementById("enabled").checked = !isWhitelisted(tab.url); |
45 document.getElementById("enabledCheckboxAndLabel").style.display = "block"
; | 44 document.getElementById("enabledCheckboxAndLabel").style.display = "block"
; |
46 | 45 |
47 chrome.tabs.sendRequest(tab.id, {reqtype: "get-clickhide-state"}, function
(response) | 46 tab.sendMessage({type: "get-clickhide-state"}, function(response) { |
48 { | |
49 if(response.active) | 47 if(response.active) |
50 clickHideActiveStuff(); | 48 clickHideActiveStuff(); |
51 else | 49 else |
52 clickHideInactiveStuff(); | 50 clickHideInactiveStuff(); |
53 }); | 51 }); |
54 }); | 52 }); |
55 }); | 53 }); |
56 } | 54 } |
57 $(init); | 55 $(init); |
58 | 56 |
(...skipping 24 matching lines...) Expand all Loading... |
83 FilterStorage.addFilter(filter); | 81 FilterStorage.addFilter(filter); |
84 } | 82 } |
85 } | 83 } |
86 | 84 |
87 refreshIconAndContextMenu(tab); | 85 refreshIconAndContextMenu(tab); |
88 } | 86 } |
89 | 87 |
90 function activateClickHide() | 88 function activateClickHide() |
91 { | 89 { |
92 clickHideActiveStuff(); | 90 clickHideActiveStuff(); |
93 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-activate"}); | 91 tab.sendMessage({type: "clickhide-activate"}); |
94 | 92 |
95 // Close the popup after a few seconds, so user doesn't have to | 93 // Close the popup after a few seconds, so user doesn't have to |
96 activateClickHide.timeout = window.setTimeout(window.close, 5000); | 94 activateClickHide.timeout = window.setTimeout(window.close, 5000); |
97 } | 95 } |
98 | 96 |
99 function cancelClickHide() | 97 function cancelClickHide() |
100 { | 98 { |
101 if (activateClickHide.timeout) | 99 if (activateClickHide.timeout) |
102 { | 100 { |
103 window.clearTimeout(activateClickHide.timeout); | 101 window.clearTimeout(activateClickHide.timeout); |
104 activateClickHide.timeout = null; | 102 activateClickHide.timeout = null; |
105 } | 103 } |
106 clickHideInactiveStuff(); | 104 clickHideInactiveStuff(); |
107 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-deactivate"}); | 105 tab.sendMessage({type: "clickhide-deactivate"}); |
| 106 } |
| 107 |
| 108 function openOptions() |
| 109 { |
| 110 backgroundPage.openOptions(); |
108 } | 111 } |
109 | 112 |
110 function clickHideActiveStuff() | 113 function clickHideActiveStuff() |
111 { | 114 { |
112 document.getElementById("enabledCheckboxAndLabel").style.display = "none"; | 115 document.getElementById("enabledCheckboxAndLabel").style.display = "none"; |
113 document.getElementById("clickHideInactiveStuff").style.display = "none"; | 116 document.getElementById("clickHideInactiveStuff").style.display = "none"; |
114 document.getElementById("clickHideActiveStuff").style.display = "inherit"; | 117 document.getElementById("clickHideActiveStuff").style.display = "inherit"; |
115 } | 118 } |
116 | 119 |
117 function clickHideInactiveStuff() | 120 function clickHideInactiveStuff() |
118 { | 121 { |
119 document.getElementById("enabledCheckboxAndLabel").style.display = "block"; | 122 document.getElementById("enabledCheckboxAndLabel").style.display = "block"; |
120 document.getElementById("clickHideActiveStuff").style.display = "none"; | 123 document.getElementById("clickHideActiveStuff").style.display = "none"; |
121 document.getElementById("clickHideInactiveStuff").style.display = "inherit"; | 124 document.getElementById("clickHideInactiveStuff").style.display = "inherit"; |
122 } | 125 } |
OLD | NEW |