-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbg.js
56 lines (54 loc) · 2.03 KB
/
bg.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
import {getOption, setOption} from "./lib/option.js";
const CASCADE = 0;
const SAME_AS_PARENT = 1;
const MAXIMIZE = 2;
chrome.tabs.onCreated.addListener(function(tab){
if (tab.index == 0){
return;
}
chrome.windows.get(tab.windowId, function(curWindow){
getOption("newWindowsPosition", function(newWindowsPosition){
var createData = {
tabId: tab.id,
incognito: tab.incognito,
state: curWindow.state
};
// if the default window position was used, simply create
// a new window and done.
if (newWindowsPosition == CASCADE){
chrome.windows.create(createData);
return;
}
// always maximize new window
if (newWindowsPosition == MAXIMIZE){
createData.state = "maximized";
chrome.windows.create(createData);
return;
}
// new window need to be placed to where the current window is.
chrome.runtime.getPlatformInfo(function(platformInfo){
// window states that cannot be
var nonPositionalStates = {
minimized: true,
maximized: true,
fullscreen: true
};
// ignores maximized state on OS X
if (platformInfo.os == "mac"){
nonPositionalStates.maximized = false;
}
// just create a new window and done if the current
// window is in special state.
if (nonPositionalStates[curWindow.state]){
chrome.windows.create(createData);
return;
}
// create a new window with position setting.
delete createData.state;
createData.top = curWindow.top;
createData.left = curWindow.left;
chrome.windows.create(createData);
});
});
});
});