-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
43 lines (40 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
chrome.commands.onCommand.addListener(async function (command) {
if (command === 'search-tabs') {
await chrome.storage.local.get(["popupWindowId"], function (result) {
if (result) {
let windowId = parseInt(result.popupWindowId);
if (typeof windowId !== "number" || Number.isNaN(windowId)) {
chrome.storage.local.remove(["popupWindowId"]);
newWindow();
} else {
chrome.windows.get(windowId, (window) => {
if (window)
chrome.windows.update(parseInt(result.popupWindowId), { focused: true });
else newWindow()
});
}
}
});
}
});
function newWindow() {
var maxWidth = window.screen.availWidth;
var maxHeight = window.screen.availHeight;
createData = {
url: "popup.html",
type: "popup",
left: Math.round((maxWidth / 2) - 307),
top: Math.round(maxHeight / 4),
width: 614,
height: Math.round((maxHeight / 2)),
focused: true
};
chrome.windows.create(createData, (window) => {
chrome.storage.local.set({ "popupWindowId": window.id });
chrome.windows.onRemoved.addListener((windowId) => {
if (windowId === window.id) {
chrome.storage.local.remove(["popupWindowId"]);
}
})
});
}