Skip to content

Commit b1169e6

Browse files
committed
Updated description. Track when the browser action closes in the background page to clean up any lagging previews on the current page
1 parent d583466 commit b1169e6

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

stylebot/background/background.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function init() {
3232
});
3333
});
3434

35+
BrowserAction.init();
3536
attachListeners();
3637
}
3738

stylebot/background/browseraction.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
// Update the extension browser action
22
var BrowserAction = {
3+
init: function() {
4+
// Track when the browser action closes to do cleanup on the current page
5+
chrome.runtime.onConnect.addListener(function(port) {
6+
if (port.name === "browserAction") {
7+
var activeTab;
8+
9+
port.onMessage.addListener(function(message) {
10+
if (message.name === "activeTab") {
11+
activeTab = message.tab;
12+
}
13+
});
14+
15+
port.onDisconnect.addListener(function() {
16+
if (activeTab) {
17+
chrome.tabs.sendRequest(activeTab.id, {
18+
name: "resetPreview"
19+
}, function(response){});
20+
}
21+
});
22+
}
23+
});
24+
},
25+
326
/**
427
* Update browser action for the specified tab to indicate:
528
* - stylebot is not visible

stylebot/browseraction/browseraction.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ var BrowserAction = {
99
styles: {},
1010

1111
init: function() {
12+
var port = chrome.runtime.connect({name: "browserAction"});
13+
1214
chrome.windows.getCurrent({populate: true}, function(aWindow) {
1315
var tabs = aWindow.tabs;
1416
var len = tabs.length;
17+
1518
for (var i = 0; i < len; i++) {
1619
var tab = tabs[i];
1720
if (tab.active) {
21+
port.postMessage({name: "activeTab", tab: tab});
22+
1823
$(".share").click(function(e) {
1924
BrowserAction.share(e, tab);
2025
});
26+
2127
$(".open").click(function(e) {
2228
BrowserAction.open(e, tab);
2329
});
30+
2431
$(".reset").click(function(e) {
2532
BrowserAction.reset(e, tab);
2633
}).mouseenter(function(e) {
@@ -32,6 +39,7 @@ var BrowserAction = {
3239
name: "resetPreview"
3340
}, function(response){});
3441
})
42+
3543
$(".options").click(function(e) {
3644
BrowserAction.options(e, tab);
3745
});
@@ -130,6 +138,7 @@ var BrowserAction = {
130138
});
131139
});
132140
});
141+
133142
return;
134143
}
135144
}

stylebot/editor/style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ stylebot.style = {
595595
* Reset the preview of any style and reset to the specifed CSS.
596596
* @param {String} css The CSS to apply to the page.
597597
*/
598-
resetPreview: function(css) {
598+
resetPreview: function() {
599599
CSSUtils.crunchCSS(this.rules, true, true, $.proxy(function(css) {
600600
$(this.CSS_SELECTOR).html(css);
601601
}, this));

stylebot/manifest.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"manifest_version": 2,
33
"name" : "Stylebot",
44
"version" : "2",
5-
"description" : "Adapt the web's appearance",
5+
"description" : "Change the appearance of websites instantly.
6+
Preview and install styles created by users for your favorite websites",
67

78
"background" : {
89
"scripts": [
@@ -16,7 +17,7 @@
1617
]
1718
},
1819

19-
"options_page" : "options/index.html",
20+
"options_page": "options/index.html",
2021

2122
"content_scripts": [{
2223
"matches": ["<all_urls>"],

0 commit comments

Comments
 (0)