-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
69 lines (63 loc) · 1.96 KB
/
Copy pathbackground.js
File metadata and controls
69 lines (63 loc) · 1.96 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
var opened = false;
var pluginPanelId = null;
var tabsFromLastWindow = null;
var tabsFromAllWindows = null;
function createNewWindow() {
let createData = {
type: "detached_panel",
url: "find-tab.html",
width: window.screen.width / 2, // find reasonable size
height: window.screen.height / 2,
// current bug 1271047 prevents from pos being set
left: window.screen.width / 2, // position in the centre
top: window.screen.height / 2
};
let pluginPanel = browser.windows.create(createData);
waitForPanelId(pluginPanel);
opened = true;
};
async function waitForPanelId(pluginPanel) {
pluginPanelId = await pluginPanel.then(pluginPanel => pluginPanel.id);
}
// Requests tabs, from all windows and the current one.
async function getTabs() {
await browser.tabs.query({currentWindow: true}).then((allT) => {tabsFromLastWindow = allT});
await browser.tabs.query({}).then((allT) => {tabsFromAllWindows = allT});
}
function sendTabs() {
browser.runtime.sendMessage({
msg: "all-tabs",
tabsLastW: tabsFromLastWindow,
tabsAllW: tabsFromAllWindows
});
}
// Listeners
browser.browserAction.onClicked.addListener(() => {
// check if already open
if (opened)
return;
createNewWindow();
getTabs();
});
browser.commands.onCommand.addListener(function (command) {
if (command == "toggle-plugin") {
// Toggle the plugin on and off
if (opened)
{
browser.windows.remove(pluginPanelId);
// opened is set to false and handled by find-tab.js by handlePanelClose
}
else {
createNewWindow();
getTabs();
}
}
else if (command == "close-Tab") {
if (opened)
browser.runtime.sendMessage({msg: "close-tab"});
}
else if (command == "toggle-search-mode") {
if (opened)
browser.runtime.sendMessage({msg: "toggle-search-mode"});
}
});