-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvim_bg.html
More file actions
99 lines (92 loc) · 3.56 KB
/
vim_bg.html
File metadata and controls
99 lines (92 loc) · 3.56 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script>
function newTab() {
chrome.tabs.create();
}
//these two functions are horrible
function changeTab(inFunc) {
chrome.windows.getCurrent(function (win) {
console.log(win);
chrome.tabs.getAllInWindow(win.id, function (tabs) {
console.log(tabs);
chrome.tabs.getSelected(null, function (tab) {
console.log(tab);
prev_index = inFunc(tab.index, tabs.length);
chrome.tabs.update(tabs[prev_index].id, {selected: true});
});
});
});
}
function prevTab() {
changeTab(function (index, length) {
out_index = index - 1;
if (out_index < 0) {
out_index = length -1;
}
return out_index;
});
}
function nextTab() {
changeTab(function (index, length) {
out_index = index + 1;
if (out_index > length -1) {
out_index = 0;
}
return out_index;
});
}
function prevTabOld() {
chrome.windows.getCurrent(function (win) {
console.log(win);
chrome.tabs.getAllInWindow(win.id, function (tabs) {
console.log(tabs);
chrome.tabs.getSelected(null, function (tab) {
console.log(tab);
prev_index = tab.index - 1;
if (prev_index < 0) {
prev_index = tabs.length -1;
}
chrome.tabs.update(tabs[prev_index].id, {selected: true});
});
});
});
}
function nextTabOld() {
chrome.windows.getCurrent(function (win) {
console.log(win);
chrome.tabs.getAllInWindow(win.id, function (tabs) {
console.log(tabs);
chrome.tabs.getSelected(null, function (tab) {
console.log(tab);
next_index = tab.index + 1;
if (next_index > tabs.length -1) {
next_index = 0;
}
chrome.tabs.update(tabs[next_index].id, {selected: true});
});
});
});
}
chrome.extension.onConnect.addListener(function(port) {
console.assert(name == "tabs");
port.onMessage.addListener(function(msg) {
console.log(msg);
switch(msg.method)
{
case "delete":
chrome.tabs.getSelected(null, function (tab) {
console.log(tab);
chrome.tabs.remove(tab.id);
});
break;
case "next":
nextTab();
break;
case "previous":
prevTab();
break;
default:
console.log("message failed");
}
});
});
</script>