Skip to content

Commit 1db538f

Browse files
committed
Tab strategy
see background.js
1 parent 9db314b commit 1db538f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ chrome extension for webui-aria2, would open a new tab showing webui-aria2
55

66
1. Download zip of the repository and unzip the code
77
2. Go to chrome://extensions/ page and click Load unpacked extension button, and select the unzipped folder.
8-
3. Click the icon in menubar and enjoy.
8+
3. Click the icon in menubar and enjoy. If you like, you can click some times more.
99

1010
or you can
1111

@@ -19,5 +19,5 @@ maybe context menu function?
1919

2020
### License
2121

22-
Refer to the LICENSE file (MIT License). If the more liberal license is needed then add it as an issue.
22+
Refer to the LICENSE file (MIT License). If a liberal license is needed then add it as an issue.
2323

background.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
chrome.browserAction.onClicked.addListener(function() {
22
var indexUrl = chrome.extension.getURL('webui-aria2/index.html');
3-
chrome.tabs.create({ url: indexUrl });
3+
chrome.tabs.getSelected(null, function(tab) {
4+
var tabUrl = tab.url;
5+
// alert(tabUrl);
6+
// alert(tab.status);
7+
if(tabUrl == "chrome://newtab/") { // current tab is blank, open in current tab
8+
chrome.tabs.update(tab.id, { url: indexUrl });
9+
}
10+
else if(tabUrl == indexUrl) { // current tab is already in extension page, just refresh
11+
chrome.tabs.reload(new Number(tab.id));
12+
}
13+
else { // create a new tab for extension to run
14+
chrome.tabs.create({ url: indexUrl });
15+
}
16+
});
417
});
518

619

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"name": "wace",
55
"description": "chrome extension for webui-aria2, would open a new tab showing webui-aria2",
6-
"version": "0.0.2",
6+
"version": "0.0.3",
77
"icons": {
88
"32": "favicon32.png",
99
"64": "favicon64.png",

0 commit comments

Comments
 (0)