forked from Claymont/detach-tab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
83 lines (76 loc) · 2.46 KB
/
background.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
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
function handleDetached(tabId, detachInfo) {
window.undoWinId = detachInfo.oldWindowId;
window.undoPosId = detachInfo.oldPosition;
window.undoTabId = tabId;
}
browser.tabs.onDetached.addListener(handleDetached);
browser.commands.onCommand.addListener(function(command) {
function getCurrentWindowTabs() {
return browser.tabs.query({currentWindow: true});
}
function callOnActiveTab(callback) {
getCurrentWindowTabs().then((tabs) => {
for (var tab of tabs) {
if (tab.active) {
callback(tab, tabs);
}
}
});
}
if (command == "detach-tab") {
function logTabs(windowInfo) {
for (let tabInfo of windowInfo.tabs) {
var tabInformation = tabInfo.index;
if (tabInformation == '0') {
continue;
}
else {
callOnActiveTab((tab, tabs) => {
var creating = browser.windows.create({
tabId: tab.id
});
});
break;
}
}
}
let getTabs = browser.windows.getCurrent({populate: true});
getTabs.then(logTabs);
}
if (command == "reattach-tab") {
function AllTabsAllWins(windowInfoArray) {
for (let tabInfo of windowInfoArray) {
var tabIdAllWin = tabInfo.tabs.map((tab) => {return tab.id});
for (let tabtabInfo of tabIdAllWin) {
if (tabtabInfo == window.undoTabId) {
function AllWins(windowInfoArray) {
for (let windowInfo of windowInfoArray) {
var windowInformation = windowInfo.id;
if (windowInformation != window.undoWinId) {
continue;
}
else {
var moving = browser.tabs.move([window.undoTabId], {
windowId: window.undoWinId,
index: window.undoPosId
});
browser.windows.update(window.undoWinId, {focused: true});
browser.tabs.update(window.undoTabId, {active: true})
break;
}
}
}
var getAllWins = browser.windows.getAll({populate: true});
getAllWins.then(AllWins);
break;
}
else {
continue;
}
}
}
}
var getAllTabsAllWins = browser.windows.getAll({populate: true});
getAllTabsAllWins.then(AllTabsAllWins);
};
});