-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackground.html
More file actions
77 lines (72 loc) · 1.98 KB
/
background.html
File metadata and controls
77 lines (72 loc) · 1.98 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
<head>
<!-- borrowed, with a tiny amount of modification, from
vimlike_smooziee.js -->
<script type='text/javascript'>
var closed_tabs = [];
var now_tab;
chrome.tabs.getSelected(null, function(tab) {
now_tab = tab;
});
chrome.tabs.onSelectionChanged.addListener(function(tabId) {
chrome.tabs.get(tabId, function(tab) {
now_tab = tab;
});
});
chrome.tabs.onUpdated.addListener(function(tabId) {
chrome.tabs.get(tabId, function(tab) {
if (now_tab && now_tab.id == tab.id) {
now_tab = tab;
}
});
});
chrome.tabs.onRemoved.addListener(function(tabId) {
if(now_tab) {
closed_tabs.push(now_tab);
};
});
chrome.extension.onConnect.addListener(function(port, name) {
port.onMessage.addListener(function(msg) {
var tab = port.tab;
switch(msg.action){
case "close_tab":
chrome.tabs.remove(tab.id);
break;
case "reopen_tab":
if (closed_tabs.length > 0) {
var last_closed_tab = closed_tabs[closed_tabs.length - 1]
closed_tabs.pop();
chrome.tabs.create({url: last_closed_tab.url, index: last_closed_tab.index});
}
break;
case "previous_tab":
chrome.tabs.getAllInWindow(tab.windowId, function(tabs) {
var previous_tab = tabs[tab.index - 1] || tabs[tabs.length - 1];
if (previous_tab) {
chrome.tabs.update(previous_tab.id, {selected: true});
}
});
break;
case "next_tab":
chrome.tabs.getAllInWindow(tab.windowId, function(tabs) {
var next_tab = tabs[tab.index + 1] || tabs[0];
if (next_tab) {
chrome.tabs.update(next_tab.id, {selected: true});
}
});
break;
case "open_url":
if (msg.newtab) {
chrome.tabs.create({url: msg.url, index: tab.index + 1});
var myport = chrome.tabs.connect(tab.id, {});
myport.postMessage({action: "remove_hints"});
} else {
chrome.tabs.update(tab.id, {url: msg.url});
}
break;
};
});
});
</script>
</head>
</html>