From b1169e64de88990a6e2283cdf14da0c1a86751a0 Mon Sep 17 00:00:00 2001 From: Ankit Ahuja Date: Wed, 26 Jun 2013 11:21:02 -0700 Subject: [PATCH] Updated description. Track when the browser action closes in the background page to clean up any lagging previews on the current page --- stylebot/background/background.js | 1 + stylebot/background/browseraction.js | 23 +++++++++++++++++++++++ stylebot/browseraction/browseraction.js | 9 +++++++++ stylebot/editor/style.js | 2 +- stylebot/manifest.json | 5 +++-- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/stylebot/background/background.js b/stylebot/background/background.js index 6ff939ef..5f54f7ec 100644 --- a/stylebot/background/background.js +++ b/stylebot/background/background.js @@ -32,6 +32,7 @@ function init() { }); }); + BrowserAction.init(); attachListeners(); } diff --git a/stylebot/background/browseraction.js b/stylebot/background/browseraction.js index 2fd4639b..1a9d2d93 100644 --- a/stylebot/background/browseraction.js +++ b/stylebot/background/browseraction.js @@ -1,5 +1,28 @@ // Update the extension browser action var BrowserAction = { + init: function() { + // Track when the browser action closes to do cleanup on the current page + chrome.runtime.onConnect.addListener(function(port) { + if (port.name === "browserAction") { + var activeTab; + + port.onMessage.addListener(function(message) { + if (message.name === "activeTab") { + activeTab = message.tab; + } + }); + + port.onDisconnect.addListener(function() { + if (activeTab) { + chrome.tabs.sendRequest(activeTab.id, { + name: "resetPreview" + }, function(response){}); + } + }); + } + }); + }, + /** * Update browser action for the specified tab to indicate: * - stylebot is not visible diff --git a/stylebot/browseraction/browseraction.js b/stylebot/browseraction/browseraction.js index 10e55eba..6fe2bef8 100644 --- a/stylebot/browseraction/browseraction.js +++ b/stylebot/browseraction/browseraction.js @@ -9,18 +9,25 @@ var BrowserAction = { styles: {}, init: function() { + var port = chrome.runtime.connect({name: "browserAction"}); + chrome.windows.getCurrent({populate: true}, function(aWindow) { var tabs = aWindow.tabs; var len = tabs.length; + for (var i = 0; i < len; i++) { var tab = tabs[i]; if (tab.active) { + port.postMessage({name: "activeTab", tab: tab}); + $(".share").click(function(e) { BrowserAction.share(e, tab); }); + $(".open").click(function(e) { BrowserAction.open(e, tab); }); + $(".reset").click(function(e) { BrowserAction.reset(e, tab); }).mouseenter(function(e) { @@ -32,6 +39,7 @@ var BrowserAction = { name: "resetPreview" }, function(response){}); }) + $(".options").click(function(e) { BrowserAction.options(e, tab); }); @@ -130,6 +138,7 @@ var BrowserAction = { }); }); }); + return; } } diff --git a/stylebot/editor/style.js b/stylebot/editor/style.js index a7ae4e1e..df114f99 100644 --- a/stylebot/editor/style.js +++ b/stylebot/editor/style.js @@ -595,7 +595,7 @@ stylebot.style = { * Reset the preview of any style and reset to the specifed CSS. * @param {String} css The CSS to apply to the page. */ - resetPreview: function(css) { + resetPreview: function() { CSSUtils.crunchCSS(this.rules, true, true, $.proxy(function(css) { $(this.CSS_SELECTOR).html(css); }, this)); diff --git a/stylebot/manifest.json b/stylebot/manifest.json index d9dc7602..87db6231 100644 --- a/stylebot/manifest.json +++ b/stylebot/manifest.json @@ -2,7 +2,8 @@ "manifest_version": 2, "name" : "Stylebot", "version" : "2", - "description" : "Adapt the web's appearance", + "description" : "Change the appearance of websites instantly. + Preview and install styles created by users for your favorite websites", "background" : { "scripts": [ @@ -16,7 +17,7 @@ ] }, - "options_page" : "options/index.html", + "options_page": "options/index.html", "content_scripts": [{ "matches": [""],