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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 function onLoad() | 30 function onLoad() |
31 { | 31 { |
32 ext.pages.query({active: true, lastFocusedWindow: true}, pages => | 32 ext.pages.query({active: true, lastFocusedWindow: true}, pages => |
33 { | 33 { |
34 page = pages[0]; | 34 page = pages[0]; |
35 | 35 |
36 // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 36 // Mark page as 'local' or 'nohtml' to hide non-relevant elements |
37 if (!page || (page.url.protocol != "http:" && | 37 if (!page || (page.url.protocol != "http:" && |
38 page.url.protocol != "https:")) | 38 page.url.protocol != "https:")) |
| 39 { |
39 document.body.classList.add("local"); | 40 document.body.classList.add("local"); |
| 41 } |
40 else if (!require("filterComposer").isPageReady(page)) | 42 else if (!require("filterComposer").isPageReady(page)) |
41 { | 43 { |
42 document.body.classList.add("nohtml"); | 44 document.body.classList.add("nohtml"); |
43 require("messaging").getPort(window).on( | 45 require("messaging").getPort(window).on( |
44 "composer.ready", (message, sender) => | 46 "composer.ready", (message, sender) => |
45 { | 47 { |
46 if (sender.page.id == page.id) | 48 if (sender.page.id == page.id) |
47 document.body.classList.remove("nohtml"); | 49 document.body.classList.remove("nohtml"); |
48 } | 50 } |
49 ); | 51 ); |
50 } | 52 } |
51 | 53 |
52 // Ask content script whether clickhide is active. If so, show cancel button
. | 54 // Ask content script whether clickhide is active. If so, show |
53 // If that isn't the case, ask background.html whether it has cached filters
. If so, | 55 // cancel button. If that isn't the case, ask background.html |
54 // ask the user whether she wants those filters. | 56 // whether it has cached filters. If so, ask the user whether she |
55 // Otherwise, we are in default state. | 57 // wants those filters. Otherwise, we are in default state. |
56 if (page) | 58 if (page) |
57 { | 59 { |
58 if (checkWhitelisted(page)) | 60 if (checkWhitelisted(page)) |
59 document.body.classList.add("disabled"); | 61 document.body.classList.add("disabled"); |
60 | 62 |
61 page.sendMessage({type: "composer.content.getState"}, response => | 63 page.sendMessage({type: "composer.content.getState"}, response => |
62 { | 64 { |
63 if (response && response.active) | 65 if (response && response.active) |
64 document.body.classList.add("clickhide-active"); | 66 document.body.classList.add("clickhide-active"); |
65 }); | 67 }); |
66 } | 68 } |
67 }); | 69 }); |
68 | 70 |
69 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); | 71 document.getElementById("enabled").addEventListener( |
70 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); | 72 "click", toggleEnabled, false |
71 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); | 73 ); |
| 74 document.getElementById("clickhide").addEventListener( |
| 75 "click", activateClickHide, false |
| 76 ); |
| 77 document.getElementById("clickhide-cancel").addEventListener( |
| 78 "click", cancelClickHide, false |
| 79 ); |
72 document.getElementById("options").addEventListener("click", () => | 80 document.getElementById("options").addEventListener("click", () => |
73 { | 81 { |
74 ext.showOptions(); | 82 ext.showOptions(); |
75 }, false); | 83 }, false); |
76 | 84 |
77 // Set up collapsing of menu items | 85 // Set up collapsing of menu items |
78 for (let collapser of document.getElementsByClassName("collapse")) | 86 for (let collapser of document.getElementsByClassName("collapse")) |
79 { | 87 { |
80 collapser.addEventListener("click", toggleCollapse, false); | 88 collapser.addEventListener("click", toggleCollapse, false); |
81 if (!Prefs[collapser.dataset.option]) | 89 if (!Prefs[collapser.dataset.option]) |
82 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); | 90 { |
| 91 document.getElementById( |
| 92 collapser.dataset.collapsable |
| 93 ).classList.add("collapsed"); |
| 94 } |
83 } | 95 } |
84 } | 96 } |
85 | 97 |
86 function toggleEnabled() | 98 function toggleEnabled() |
87 { | 99 { |
88 let disabled = document.body.classList.toggle("disabled"); | 100 let disabled = document.body.classList.toggle("disabled"); |
89 if (disabled) | 101 if (disabled) |
90 { | 102 { |
91 let host = getDecodedHostname(page.url).replace(/^www\./, ""); | 103 let host = getDecodedHostname(page.url).replace(/^www\./, ""); |
92 let filter = Filter.fromText("@@||" + host + "^$document"); | 104 let filter = Filter.fromText("@@||" + host + "^$document"); |
93 if (filter.subscriptions.length && filter.disabled) | 105 if (filter.subscriptions.length && filter.disabled) |
| 106 { |
94 filter.disabled = false; | 107 filter.disabled = false; |
| 108 } |
95 else | 109 else |
96 { | 110 { |
97 filter.disabled = false; | 111 filter.disabled = false; |
98 FilterStorage.addFilter(filter); | 112 FilterStorage.addFilter(filter); |
99 } | 113 } |
100 } | 114 } |
101 else | 115 else |
102 { | 116 { |
103 // Remove any exception rules applying to this URL | 117 // Remove any exception rules applying to this URL |
104 let filter = checkWhitelisted(page); | 118 let filter = checkWhitelisted(page); |
(...skipping 28 matching lines...) Expand all Loading... |
133 } | 147 } |
134 | 148 |
135 function toggleCollapse(event) | 149 function toggleCollapse(event) |
136 { | 150 { |
137 let collapser = event.currentTarget; | 151 let collapser = event.currentTarget; |
138 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 152 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; |
139 collapser.parentNode.classList.toggle("collapsed"); | 153 collapser.parentNode.classList.toggle("collapsed"); |
140 } | 154 } |
141 | 155 |
142 document.addEventListener("DOMContentLoaded", onLoad, false); | 156 document.addEventListener("DOMContentLoaded", onLoad, false); |
OLD | NEW |