LEFT | RIGHT |
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 checkWhitelisted = require("whitelisting").checkWhitelisted; | 24 var checkWhitelisted = require("whitelisting").checkWhitelisted; |
25 var getDecodedHostname = require("url").getDecodedHostname; | 25 var getDecodedHostname = require("url").getDecodedHostname; |
26 var isPageReady = require("filterComposer").isPageReady; | |
27 var port = require("messaging").port; | |
28 | 26 |
29 var page = null; | 27 var page = null; |
30 | 28 |
31 function onLoad() | 29 function onLoad() |
32 { | 30 { |
33 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 31 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
34 { | 32 { |
35 page = pages[0]; | 33 page = pages[0]; |
36 | 34 |
37 // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 35 // Mark page as 'local' or 'nohtml' to hide non-relevant elements |
38 if (!page || (page.url.protocol != "http:" && | 36 if (!page || (page.url.protocol != "http:" && |
39 page.url.protocol != "https:")) | 37 page.url.protocol != "https:")) |
40 document.body.classList.add("local"); | 38 document.body.classList.add("local"); |
41 else if (!isPageReady(page)) | 39 else if (!require("filterComposer").isPageReady(page)) |
| 40 { |
42 document.body.classList.add("nohtml"); | 41 document.body.classList.add("nohtml"); |
| 42 require("messaging").getPort(window).on( |
| 43 "composer.ready", function(message, sender) |
| 44 { |
| 45 if (sender.page.id == page.id) |
| 46 document.body.classList.remove("nohtml"); |
| 47 } |
| 48 ); |
| 49 } |
43 | 50 |
44 // Ask content script whether clickhide is active. If so, show cancel button
. | 51 // Ask content script whether clickhide is active. If so, show cancel button
. |
45 // If that isn't the case, ask background.html whether it has cached filters
. If so, | 52 // If that isn't the case, ask background.html whether it has cached filters
. If so, |
46 // ask the user whether she wants those filters. | 53 // ask the user whether she wants those filters. |
47 // Otherwise, we are in default state. | 54 // Otherwise, we are in default state. |
48 if (page) | 55 if (page) |
49 { | 56 { |
50 if (checkWhitelisted(page)) | 57 if (checkWhitelisted(page)) |
51 document.body.classList.add("disabled"); | 58 document.body.classList.add("disabled"); |
52 | 59 |
53 page.sendMessage({type: "composer.content.getState"}, function(response) | 60 page.sendMessage({type: "composer.content.getState"}, function(response) |
54 { | 61 { |
55 if (response && response.active) | 62 if (response && response.active) |
56 document.body.classList.add("clickhide-active"); | 63 document.body.classList.add("clickhide-active"); |
57 }); | 64 }); |
58 } | 65 } |
59 }); | 66 }); |
60 | 67 |
61 // Attach event listeners | |
62 port.on("composer.ready", onComposerReady); | |
63 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); | 68 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); |
64 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); | 69 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); |
65 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); | 70 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); |
66 document.getElementById("options").addEventListener("click", function() | 71 document.getElementById("options").addEventListener("click", function() |
67 { | 72 { |
68 ext.showOptions(); | 73 ext.showOptions(); |
69 }, false); | 74 }, false); |
70 | 75 |
71 // Set up collapsing of menu items | 76 // Set up collapsing of menu items |
72 var collapsers = document.getElementsByClassName("collapse"); | 77 var collapsers = document.getElementsByClassName("collapse"); |
73 for (var i = 0; i < collapsers.length; i++) | 78 for (var i = 0; i < collapsers.length; i++) |
74 { | 79 { |
75 var collapser = collapsers[i]; | 80 var collapser = collapsers[i]; |
76 collapser.addEventListener("click", toggleCollapse, false); | 81 collapser.addEventListener("click", toggleCollapse, false); |
77 if (!Prefs[collapser.dataset.option]) | 82 if (!Prefs[collapser.dataset.option]) |
78 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); | 83 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); |
79 } | 84 } |
80 } | |
81 | |
82 function onUnload() | |
83 { | |
84 port.off("composer.ready", onComposerReady); | |
85 } | |
86 | |
87 function onComposerReady(message, sender) | |
88 { | |
89 if (sender.page.id == page.id) | |
90 document.body.classList.remove("nohtml"); | |
91 } | 85 } |
92 | 86 |
93 function toggleEnabled() | 87 function toggleEnabled() |
94 { | 88 { |
95 var disabled = document.body.classList.toggle("disabled"); | 89 var disabled = document.body.classList.toggle("disabled"); |
96 if (disabled) | 90 if (disabled) |
97 { | 91 { |
98 var host = getDecodedHostname(page.url).replace(/^www\./, ""); | 92 var host = getDecodedHostname(page.url).replace(/^www\./, ""); |
99 var filter = Filter.fromText("@@||" + host + "^$document"); | 93 var filter = Filter.fromText("@@||" + host + "^$document"); |
100 if (filter.subscriptions.length && filter.disabled) | 94 if (filter.subscriptions.length && filter.disabled) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 134 } |
141 | 135 |
142 function toggleCollapse(event) | 136 function toggleCollapse(event) |
143 { | 137 { |
144 var collapser = event.currentTarget; | 138 var collapser = event.currentTarget; |
145 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 139 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; |
146 collapser.parentNode.classList.toggle("collapsed"); | 140 collapser.parentNode.classList.toggle("collapsed"); |
147 } | 141 } |
148 | 142 |
149 document.addEventListener("DOMContentLoaded", onLoad, false); | 143 document.addEventListener("DOMContentLoaded", onLoad, false); |
150 window.addEventListener("unload", onUnload, false); | |
LEFT | RIGHT |