OLD | NEW |
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 port = require("messaging").port; |
26 | 27 |
27 var page = null; | 28 var page = null; |
28 | 29 |
29 function onLoad() | 30 function onLoad() |
30 { | 31 { |
31 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 32 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
32 { | 33 { |
33 page = pages[0]; | 34 page = pages[0]; |
34 | 35 |
35 // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 36 // Mark page as 'local' or 'nohtml' to hide non-relevant elements |
(...skipping 14 matching lines...) Expand all Loading... |
50 | 51 |
51 page.sendMessage({type: "blockelement-get-state"}, function(response) | 52 page.sendMessage({type: "blockelement-get-state"}, function(response) |
52 { | 53 { |
53 if (response && response.active) | 54 if (response && response.active) |
54 document.body.classList.add("clickhide-active"); | 55 document.body.classList.add("clickhide-active"); |
55 }); | 56 }); |
56 } | 57 } |
57 }); | 58 }); |
58 | 59 |
59 // Attach event listeners | 60 // Attach event listeners |
60 ext.onMessage.addListener(onMessage); | 61 port.on("composer.ready", onComposerReady); |
61 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); | 62 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); |
62 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); | 63 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); |
63 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); | 64 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); |
64 document.getElementById("options").addEventListener("click", function() | 65 document.getElementById("options").addEventListener("click", function() |
65 { | 66 { |
66 ext.showOptions(); | 67 ext.showOptions(); |
67 }, false); | 68 }, false); |
68 | 69 |
69 // Set up collapsing of menu items | 70 // Set up collapsing of menu items |
70 var collapsers = document.getElementsByClassName("collapse"); | 71 var collapsers = document.getElementsByClassName("collapse"); |
71 for (var i = 0; i < collapsers.length; i++) | 72 for (var i = 0; i < collapsers.length; i++) |
72 { | 73 { |
73 var collapser = collapsers[i]; | 74 var collapser = collapsers[i]; |
74 collapser.addEventListener("click", toggleCollapse, false); | 75 collapser.addEventListener("click", toggleCollapse, false); |
75 if (!Prefs[collapser.dataset.option]) | 76 if (!Prefs[collapser.dataset.option]) |
76 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); | 77 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
80 function onUnload() | 81 function onUnload() |
81 { | 82 { |
82 ext.onMessage.removeListener(onMessage); | 83 port.off("composer.ready", onComposerReady); |
83 } | 84 } |
84 | 85 |
85 function onMessage(message, sender, callback) | 86 function onComposerReady(message, sender) |
86 { | 87 { |
87 if (message.type == "report-html-page" && sender.page.id == page.id) | 88 if (sender.page.id == page.id) |
88 document.body.classList.remove("nohtml"); | 89 document.body.classList.remove("nohtml"); |
89 } | 90 } |
90 | 91 |
91 function toggleEnabled() | 92 function toggleEnabled() |
92 { | 93 { |
93 var disabled = document.body.classList.toggle("disabled"); | 94 var disabled = document.body.classList.toggle("disabled"); |
94 if (disabled) | 95 if (disabled) |
95 { | 96 { |
96 var host = getDecodedHostname(page.url).replace(/^www\./, ""); | 97 var host = getDecodedHostname(page.url).replace(/^www\./, ""); |
97 var filter = Filter.fromText("@@||" + host + "^$document"); | 98 var filter = Filter.fromText("@@||" + host + "^$document"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 140 |
140 function toggleCollapse(event) | 141 function toggleCollapse(event) |
141 { | 142 { |
142 var collapser = event.currentTarget; | 143 var collapser = event.currentTarget; |
143 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 144 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; |
144 collapser.parentNode.classList.toggle("collapsed"); | 145 collapser.parentNode.classList.toggle("collapsed"); |
145 } | 146 } |
146 | 147 |
147 document.addEventListener("DOMContentLoaded", onLoad, false); | 148 document.addEventListener("DOMContentLoaded", onLoad, false); |
148 window.addEventListener("unload", onUnload, false); | 149 window.addEventListener("unload", onUnload, false); |
OLD | NEW |