OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 var backgroundPage = ext.backgroundPage.getWindow(); |
| 19 var openOptions = backgroundPage.openOptions; |
| 20 var page = null; |
| 21 |
| 22 function init() |
| 23 { |
| 24 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
| 25 { |
| 26 page = pages[0]; |
| 27 if (page) |
| 28 { |
| 29 document.body.classList.toggle("local", !/^https?:\/\//.test(page.url)); |
| 30 |
| 31 // Ask content script whether clickhide is active. If so, show cancel butt
on. |
| 32 page.sendMessage({type: "get-clickhide-state"}, function(response) |
| 33 { |
| 34 if (response && response.active) |
| 35 document.body.classList.add("clickhide-active"); |
| 36 }); |
| 37 } |
| 38 }); |
| 39 |
| 40 // Initialize features |
| 41 initClickHide(); |
| 42 initReportIssue(); |
| 43 initBlockable(); |
| 44 |
| 45 document.getElementById("options").addEventListener("click", function() |
| 46 { |
| 47 openOptions(); |
| 48 }, false); |
| 49 } |
| 50 window.addEventListener("DOMContentLoaded", init, false); |
| 51 |
| 52 function initClickHide() |
| 53 { |
| 54 if (!("activateClickHide" in ext)) |
| 55 return; |
| 56 |
| 57 var menuItemActivate = document.getElementById("clickhide"); |
| 58 menuItemActivate.addEventListener("click", activateClickHide, false); |
| 59 menuItemActivate.removeAttribute("hidden"); |
| 60 var menuItemCancel = document.getElementById("clickhide-cancel"); |
| 61 menuItemCancel.addEventListener("click", cancelClickHide, false); |
| 62 menuItemCancel.removeAttribute("hidden"); |
| 63 } |
| 64 |
| 65 function initReportIssue() |
| 66 { |
| 67 if (!("reportIssue" in ext) || !ext.showReportIssue()) |
| 68 return; |
| 69 |
| 70 var menuItem = document.getElementById("report-issue"); |
| 71 menuItem.addEventListener("click", function() |
| 72 { |
| 73 ext.reportIssue(); |
| 74 }, false); |
| 75 menuItem.removeAttribute("hidden"); |
| 76 } |
| 77 |
| 78 function initBlockable() |
| 79 { |
| 80 if (!("openBlockable" in ext)) |
| 81 return; |
| 82 |
| 83 var menuItem = document.getElementById("blockable"); |
| 84 menuItem.classList.toggle("open", ext.isBlockableOpen()); |
| 85 menuItem.addEventListener("click", function() |
| 86 { |
| 87 ext.openBlockable(); |
| 88 }, false); |
| 89 menuItem.removeAttribute("hidden"); |
| 90 } |
| 91 |
| 92 function activateClickHide() |
| 93 { |
| 94 document.body.classList.add("clickhide-active"); |
| 95 ext.activateClickHide(true); |
| 96 |
| 97 // Close the popup after a few seconds, so user doesn't have to |
| 98 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); |
| 99 } |
| 100 |
| 101 function cancelClickHide() |
| 102 { |
| 103 if (activateClickHide.timeout) |
| 104 { |
| 105 window.clearTimeout(activateClickHide.timeout); |
| 106 activateClickHide.timeout = null; |
| 107 } |
| 108 document.body.classList.remove("clickhide-active"); |
| 109 ext.activateClickHide(false); |
| 110 } |
OLD | NEW |