-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.html
37 lines (34 loc) · 969 Bytes
/
background.html
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
<html>
<head>
<script type="text/javascript">
var tabIds = new Array();
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if(request.call == "changeTab") {
var currentTab = tabIds.shift();
var lastTab = tabIds.shift();
tabIds.unshift(currentTab);
chrome.tabs.update(lastTab, {selected: true}, null);
console.log('changed to tab' + lastTab);
}
});
chrome.tabs.onSelectionChanged.addListener(function(tabId, selectInfo) {
for(var i=0; i<tabIds.length; i++ ) {
if(tabIds[i]==tabId)
tabIds.splice(i,1);
}
tabIds.unshift(tabId);
console.log('changed to tab ' + tabId);
console.log(tabIds);
});
chrome.tabs.onRemoved.addListener(function(tabId) {
console.log(tabId + ' closed');
for(var i=0; i<tabIds.length; i++ ) {
if(tabIds[i]==tabId)
tabIds.splice(i,1);
}
var lastTab = tabIds.shift();
chrome.tabs.update(lastTab, {selected: true}, null);
});
</script>
</html>
</head>