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