| Left: | ||
| Right: |
| 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 window["openOptions"] = backgroundPage["openOptions"]; | |
| 20 | |
| 21 var tab = null; | |
| 22 | |
| 23 function init() | |
| 24 { | |
| 25 // Mark page as local to hide non-relevant elements | |
| 26 ext.windows.getLastFocused(function(win) | |
| 27 { | |
| 28 win.getActiveTab(function(t) | |
| 29 { | |
| 30 tab = t; | |
| 31 | |
| 32 if (!/^https?:\/\//.exec(tab.url)) | |
|
Thomas Greiner
2014/09/29 16:19:49
You can replace both the check and the class assig
saroyanm
2014/10/02 07:53:56
Awesome! Didn't know about second attribute.
| |
| 33 document.body.classList.add("local"); | |
| 34 }); | |
| 35 }); | |
| 36 | |
| 37 // Initialize features | |
| 38 initClickHide(); | |
| 39 initReportIssue(); | |
| 40 initBlockable(); | |
| 41 | |
| 42 document.getElementById("options").addEventListener("click", function() | |
| 43 { | |
| 44 openOptions(); | |
| 45 }, false); | |
| 46 } | |
| 47 window.addEventListener("DOMContentLoaded", init, false); | |
| 48 | |
| 49 function initClickHide() | |
| 50 { | |
| 51 if (!("activateClickHide" in ext)) | |
| 52 return; | |
| 53 | |
| 54 var menuItem1 = document.getElementById("clickhide"); | |
|
Thomas Greiner
2014/09/29 16:19:49
A bit more descriptive variable names would be nic
saroyanm
2014/10/02 07:53:56
Done.
| |
| 55 menuItem1.addEventListener("click", activateClickHide, false); | |
| 56 menuItem1.removeAttribute("hidden"); | |
| 57 var menuItem2 = document.getElementById("clickhide-cancel"); | |
| 58 menuItem2.addEventListener("click", cancelClickHide, false); | |
| 59 menuItem2.removeAttribute("hidden"); | |
| 60 | |
| 61 // Ask content script whether clickhide is active. If so, show cancel button. | |
| 62 // If that isn't the case, ask background.html whether it has cached filters. If so, | |
| 63 // ask the user whether she wants those filters. | |
| 64 // Otherwise, we are in default state. | |
|
Thomas Greiner
2014/09/29 16:19:49
The description doesn't need to mention what's goi
saroyanm
2014/10/02 07:53:56
Done.
| |
| 65 ext.windows.getLastFocused(function(win) | |
| 66 { | |
| 67 win.getActiveTab(function(tab) | |
| 68 { | |
| 69 tab.sendMessage({type: "get-clickhide-state"}, function(response) | |
| 70 { | |
| 71 if (response && response.active) | |
| 72 document.body.classList.add("clickhide-active"); | |
| 73 }); | |
| 74 }); | |
| 75 }); | |
| 76 } | |
| 77 | |
| 78 function initReportIssue() | |
| 79 { | |
| 80 if (!("reportIssue" in ext) || !ext.showReportIssue()) | |
| 81 return; | |
| 82 | |
| 83 var menuItem = document.getElementById("report-issue"); | |
| 84 menuItem.addEventListener("click", function() | |
| 85 { | |
| 86 ext.reportIssue(); | |
| 87 }, false); | |
| 88 menuItem.removeAttribute("hidden"); | |
| 89 } | |
| 90 | |
| 91 function initBlockable() | |
| 92 { | |
| 93 if (!ext.showBlockable()) | |
|
Thomas Greiner
2014/09/29 16:19:49
In regard to my suggestion to get rid of showBlock
saroyanm
2014/10/02 07:53:56
I guess I'm not catching on this part.
Can you ple
Thomas Greiner
2014/10/08 10:40:43
This menu item should always be shown on platforms
saroyanm
2014/10/10 12:05:58
Got it, please let me know if you think we can giv
Thomas Greiner
2014/10/13 13:18:23
The new implementation looks good.
| |
| 94 return; | |
| 95 | |
| 96 var menuItem = document.getElementById("blockable"); | |
| 97 menuItem.addEventListener("click", function() | |
| 98 { | |
| 99 ext.openBlockable(); | |
| 100 }, false); | |
| 101 menuItem.removeAttribute("hidden"); | |
| 102 } | |
| 103 | |
| 104 function activateClickHide() | |
| 105 { | |
| 106 document.body.classList.add("clickhide-active"); | |
| 107 ext.activateClickHide(true); | |
| 108 | |
| 109 // Close the popup after a few seconds, so user doesn't have to | |
| 110 activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); | |
| 111 } | |
| 112 | |
| 113 function cancelClickHide() | |
| 114 { | |
| 115 if (activateClickHide.timeout) | |
| 116 { | |
| 117 window.clearTimeout(activateClickHide.timeout); | |
| 118 activateClickHide.timeout = null; | |
| 119 } | |
| 120 document.body.classList.remove("clickhide-active"); | |
| 121 ext.activateClickHide(false); | |
| 122 } | |
| OLD | NEW |