| 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 port = require("messaging").port; | |
| 27 | 26 |
| 28 var page = null; | 27 var page = null; |
| 29 | 28 |
| 30 function onLoad() | 29 function onLoad() |
| 31 { | 30 { |
| 32 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) | 31 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
| 33 { | 32 { |
| 34 page = pages[0]; | 33 page = pages[0]; |
| 35 | 34 |
| 36 // Mark page as 'local' or 'nohtml' to hide non-relevant elements | 35 // Mark page as 'local' or 'nohtml' to hide non-relevant elements |
| 37 if (!page || (page.url.protocol != "http:" && | 36 if (!page || (page.url.protocol != "http:" && |
| 38 page.url.protocol != "https:")) | 37 page.url.protocol != "https:")) |
| 39 document.body.classList.add("local"); | 38 document.body.classList.add("local"); |
| 40 else if (!backgroundPage.htmlPages.has(page)) | 39 else if (!backgroundPage.htmlPages.has(page)) |
| 40 { |
| 41 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 } |
| 42 | 50 |
| 43 // 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
. |
| 44 // 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, |
| 45 // ask the user whether she wants those filters. | 53 // ask the user whether she wants those filters. |
| 46 // Otherwise, we are in default state. | 54 // Otherwise, we are in default state. |
| 47 if (page) | 55 if (page) |
| 48 { | 56 { |
| 49 if (checkWhitelisted(page)) | 57 if (checkWhitelisted(page)) |
| 50 document.body.classList.add("disabled"); | 58 document.body.classList.add("disabled"); |
| 51 | 59 |
| 52 page.sendMessage({type: "blockelement-get-state"}, function(response) | 60 page.sendMessage({type: "composer.content.getState"}, function(response) |
| 53 { | 61 { |
| 54 if (response && response.active) | 62 if (response && response.active) |
| 55 document.body.classList.add("clickhide-active"); | 63 document.body.classList.add("clickhide-active"); |
| 56 }); | 64 }); |
| 57 } | 65 } |
| 58 }); | 66 }); |
| 59 | 67 |
| 60 // Attach event listeners | |
| 61 port.on("composer.ready", onComposerReady); | |
| 62 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); | 68 document.getElementById("enabled").addEventListener("click", toggleEnabled, fa
lse); |
| 63 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); | 69 document.getElementById("clickhide").addEventListener("click", activateClickHi
de, false); |
| 64 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); | 70 document.getElementById("clickhide-cancel").addEventListener("click", cancelCl
ickHide, false); |
| 65 document.getElementById("options").addEventListener("click", function() | 71 document.getElementById("options").addEventListener("click", function() |
| 66 { | 72 { |
| 67 ext.showOptions(); | 73 ext.showOptions(); |
| 68 }, false); | 74 }, false); |
| 69 | 75 |
| 70 // Set up collapsing of menu items | 76 // Set up collapsing of menu items |
| 71 var collapsers = document.getElementsByClassName("collapse"); | 77 var collapsers = document.getElementsByClassName("collapse"); |
| 72 for (var i = 0; i < collapsers.length; i++) | 78 for (var i = 0; i < collapsers.length; i++) |
| 73 { | 79 { |
| 74 var collapser = collapsers[i]; | 80 var collapser = collapsers[i]; |
| 75 collapser.addEventListener("click", toggleCollapse, false); | 81 collapser.addEventListener("click", toggleCollapse, false); |
| 76 if (!Prefs[collapser.dataset.option]) | 82 if (!Prefs[collapser.dataset.option]) |
| 77 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); | 83 document.getElementById(collapser.dataset.collapsable).classList.add("coll
apsed"); |
| 78 } | 84 } |
| 79 } | |
| 80 | |
| 81 function onUnload() | |
| 82 { | |
| 83 port.off("composer.ready", onComposerReady); | |
| 84 } | |
| 85 | |
| 86 function onComposerReady(message, sender) | |
| 87 { | |
| 88 if (sender.page.id == page.id) | |
| 89 document.body.classList.remove("nohtml"); | |
| 90 } | 85 } |
| 91 | 86 |
| 92 function toggleEnabled() | 87 function toggleEnabled() |
| 93 { | 88 { |
| 94 var disabled = document.body.classList.toggle("disabled"); | 89 var disabled = document.body.classList.toggle("disabled"); |
| 95 if (disabled) | 90 if (disabled) |
| 96 { | 91 { |
| 97 var host = getDecodedHostname(page.url).replace(/^www\./, ""); | 92 var host = getDecodedHostname(page.url).replace(/^www\./, ""); |
| 98 var filter = Filter.fromText("@@||" + host + "^$document"); | 93 var filter = Filter.fromText("@@||" + host + "^$document"); |
| 99 if (filter.subscriptions.length && filter.disabled) | 94 if (filter.subscriptions.length && filter.disabled) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 114 if (filter.subscriptions.length) | 109 if (filter.subscriptions.length) |
| 115 filter.disabled = true; | 110 filter.disabled = true; |
| 116 filter = checkWhitelisted(page); | 111 filter = checkWhitelisted(page); |
| 117 } | 112 } |
| 118 } | 113 } |
| 119 } | 114 } |
| 120 | 115 |
| 121 function activateClickHide() | 116 function activateClickHide() |
| 122 { | 117 { |
| 123 document.body.classList.add("clickhide-active"); | 118 document.body.classList.add("clickhide-active"); |
| 124 page.sendMessage({type: "blockelement-start-picking-element"}); | 119 page.sendMessage({type: "composer.content.startPickingElement"}); |
| 125 | 120 |
| 126 // Close the popup after a few seconds, so user doesn't have to | 121 // Close the popup after a few seconds, so user doesn't have to |
| 127 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); | 122 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); |
| 128 } | 123 } |
| 129 | 124 |
| 130 function cancelClickHide() | 125 function cancelClickHide() |
| 131 { | 126 { |
| 132 if (activateClickHide.timeout) | 127 if (activateClickHide.timeout) |
| 133 { | 128 { |
| 134 window.clearTimeout(activateClickHide.timeout); | 129 window.clearTimeout(activateClickHide.timeout); |
| 135 activateClickHide.timeout = null; | 130 activateClickHide.timeout = null; |
| 136 } | 131 } |
| 137 document.body.classList.remove("clickhide-active"); | 132 document.body.classList.remove("clickhide-active"); |
| 138 page.sendMessage({type: "blockelement-finished"}); | 133 page.sendMessage({type: "composer.content.finished"}); |
| 139 } | 134 } |
| 140 | 135 |
| 141 function toggleCollapse(event) | 136 function toggleCollapse(event) |
| 142 { | 137 { |
| 143 var collapser = event.currentTarget; | 138 var collapser = event.currentTarget; |
| 144 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; | 139 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; |
| 145 collapser.parentNode.classList.toggle("collapsed"); | 140 collapser.parentNode.classList.toggle("collapsed"); |
| 146 } | 141 } |
| 147 | 142 |
| 148 document.addEventListener("DOMContentLoaded", onLoad, false); | 143 document.addEventListener("DOMContentLoaded", onLoad, false); |
| 149 window.addEventListener("unload", onUnload, false); | |
| LEFT | RIGHT |