-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
60 lines (50 loc) · 1.25 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
'use strict';
var stowedWindows = [];
var stowWindow = function(id, callback) {
chrome.windows.get(id, {populate: true}, (window) => {
stowedWindows.push(window);
if (!callback) {
chrome.windows.remove(id);
} else {
chrome.windows.remove(id, callback);
}
});
};
var unstowWindow = function(index, callback) {
var window = stowedWindows[index];
var createData = {
type: window.type,
state: window.state
};
if (window.state !== 'maximized') {
createData.width = window.width;
createData.height = window.height;
createData.left = window.left;
createData.top = window.top;
}
var len = window.tabs.length;
if (len === 1) {
createData.url = window.tabs[0].url;
} else {
createData.url = [];
for (let i = 0; i < len; i++) {
createData.url.push(window.tabs[i].url);
}
}
removeWindow(index);
if (!callback) {
chrome.windows.create(createData);
} else {
chrome.windows.create(createData, callback);
}
};
var removeWindow = function(index) {
stowedWindows.splice(index, 1);
};
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
$.getJSON('defaultOptions.json', (data) => {
chrome.storage.sync.set(data);
});
}
});