Skip to content

Commit

Permalink
Updated description. Track when the browser action closes in the back…
Browse files Browse the repository at this point in the history
…ground page to clean up any lagging previews on the current page
  • Loading branch information
ankit committed Jun 26, 2013
1 parent d583466 commit b1169e6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions stylebot/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function init() {
});
});

BrowserAction.init();
attachListeners();
}

Expand Down
23 changes: 23 additions & 0 deletions stylebot/background/browseraction.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions stylebot/browseraction/browseraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -32,6 +39,7 @@ var BrowserAction = {
name: "resetPreview"
}, function(response){});
})

$(".options").click(function(e) {
BrowserAction.options(e, tab);
});
Expand Down Expand Up @@ -130,6 +138,7 @@ var BrowserAction = {
});
});
});

return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion stylebot/editor/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions stylebot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -16,7 +17,7 @@
]
},

"options_page" : "options/index.html",
"options_page": "options/index.html",

"content_scripts": [{
"matches": ["<all_urls>"],
Expand Down

0 comments on commit b1169e6

Please sign in to comment.