forked from cloudroc/baidu-nolimit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
46 lines (42 loc) · 884 Bytes
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$(function() {
$("#blog").click(function() {
openHelper('http://blog.jarjar.cn/');
});
$("#github").click(function() {
openHelper('https://github.com/cloudroc/baidu-nolimit');
});
function focusOrCreateTab(url) {
chrome.windows.getAll({
"populate": true
}, function(windows) {
var existing_tab = null;
for(var i in windows) {
var tabs = windows[i].tabs;
for(var j in tabs) {
var tab = tabs[j];
if(tab.url == url) {
existing_tab = tab;
break;
}
}
}
if(existing_tab) {
chrome.tabs.update(existing_tab.id, {
"selected": true
});
} else {
chrome.tabs.create({
"url": url,
"selected": true
});
}
});
}
function openHelper(url) {
var manager_url = url;
if(url.indexOf("http") != 0) {
manager_url = chrome.extension.getURL(url);
}
focusOrCreateTab(manager_url);
}
});