Index: popup.js |
=================================================================== |
--- a/popup.js |
+++ b/popup.js |
@@ -1,6 +1,6 @@ |
/* |
* This file is part of Adblock Plus <http://adblockplus.org/>, |
- * Copyright (C) 2006-2013 Eyeo GmbH |
+ * Copyright (C) 2006-2014 Eyeo GmbH |
* |
* Adblock Plus is free software: you can redistribute it and/or modify |
* it under the terms of the GNU General Public License version 3 as |
@@ -16,26 +16,42 @@ |
*/ |
var backgroundPage = ext.backgroundPage.getWindow(); |
-var imports = ["require", "isWhitelisted", "extractHostFromURL", "refreshIconAndContextMenu", "openOptions"]; |
+var imports = ["require", "extractHostFromURL", "openOptions"]; |
for (var i = 0; i < imports.length; i++) |
window[imports[i]] = backgroundPage[imports[i]]; |
var Filter = require("filterClasses").Filter; |
var FilterStorage = require("filterStorage").FilterStorage; |
var Prefs = require("prefs").Prefs; |
+var isWhitelisted = require("whitelisting").isWhitelisted; |
-var tab = null; |
+var page = null; |
function init() |
{ |
- // Mark page as local to hide non-relevant elements |
- ext.windows.getLastFocused(function(win) |
+ ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) |
{ |
- win.getActiveTab(function(tab) |
+ page = pages[0]; |
+ |
+ // Mark page as local to hide non-relevant elements |
+ if (!page || !/^https?:\/\//.test(page.url)) |
+ document.body.classList.add("local"); |
+ |
+ // Ask content script whether clickhide is active. If so, show cancel button. |
+ // If that isn't the case, ask background.html whether it has cached filters. If so, |
+ // ask the user whether she wants those filters. |
+ // Otherwise, we are in default state. |
+ if (page) |
{ |
- if (!/^https?:\/\//.exec(tab.url)) |
- document.body.classList.add("local"); |
- }); |
+ if (isWhitelisted(page.url)) |
+ document.getElementById("enabled").classList.add("off"); |
+ |
+ page.sendMessage({type: "get-clickhide-state"}, function(response) |
+ { |
+ if (response && response.active) |
+ document.body.classList.add("clickhide-active"); |
+ }); |
+ } |
}); |
// Attach event listeners |
@@ -56,26 +72,6 @@ |
if (!Prefs[collapser.dataset.option]) |
document.getElementById(collapser.dataset.collapsable).classList.add("collapsed"); |
} |
- |
- // Ask content script whether clickhide is active. If so, show cancel button. |
- // If that isn't the case, ask background.html whether it has cached filters. If so, |
- // ask the user whether she wants those filters. |
- // Otherwise, we are in default state. |
- ext.windows.getLastFocused(function(win) |
- { |
- win.getActiveTab(function(t) |
- { |
- tab = t; |
- if (isWhitelisted(tab.url)) |
- document.getElementById("enabled").classList.add("off"); |
- |
- tab.sendMessage({type: "get-clickhide-state"}, function(response) |
- { |
- if (response && response.active) |
- document.body.classList.add("clickhide-active"); |
- }); |
- }); |
- }); |
} |
window.addEventListener("DOMContentLoaded", init, false); |
@@ -85,7 +81,7 @@ |
var disabled = enabledButton.classList.toggle("off"); |
if (disabled) |
{ |
- var host = extractHostFromURL(tab.url).replace(/^www\./, ""); |
+ var host = extractHostFromURL(page.url).replace(/^www\./, ""); |
var filter = Filter.fromText("@@||" + host + "^$document"); |
if (filter.subscriptions.length && filter.disabled) |
filter.disabled = false; |
@@ -98,26 +94,24 @@ |
else |
{ |
// Remove any exception rules applying to this URL |
- var filter = isWhitelisted(tab.url); |
+ var filter = isWhitelisted(page.url); |
while (filter) |
{ |
FilterStorage.removeFilter(filter); |
if (filter.subscriptions.length) |
filter.disabled = true; |
- filter = isWhitelisted(tab.url); |
+ filter = isWhitelisted(page.url); |
} |
} |
- |
- refreshIconAndContextMenu(tab); |
} |
function activateClickHide() |
{ |
document.body.classList.add("clickhide-active"); |
- tab.sendMessage({type: "clickhide-activate"}); |
+ page.sendMessage({type: "clickhide-activate"}); |
// Close the popup after a few seconds, so user doesn't have to |
- activateClickHide.timeout = window.setTimeout(window.close, 5000); |
+ activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000); |
} |
function cancelClickHide() |
@@ -128,7 +122,7 @@ |
activateClickHide.timeout = null; |
} |
document.body.classList.remove("clickhide-active"); |
- tab.sendMessage({type: "clickhide-deactivate"}); |
+ page.sendMessage({type: "clickhide-deactivate"}); |
} |
function toggleCollapse(event) |