-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
55 lines (48 loc) · 1.68 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
let allKnownBoxes = [];
const sendMessageToContentScript = responseDetails => {
chrome.tabs.sendMessage(responseDetails.tabId, { operation: "checkStatus" });
};
chrome.webRequest.onCompleted.addListener(sendMessageToContentScript, {
urls: ["https://*/xui/update/configuration/alert/statusmenu/coloradvisory*"]
});
chrome.pageAction.onClicked.addListener(tab => {
chrome.tabs.sendMessage(tab.id, { operation: "stopUpdating" });
chrome.pageAction.hide(tab.id);
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.operation === "activateButton") {
chrome.pageAction.show(sender.tab.id);
} else if (request.operation === "deactivateButton") {
chrome.pageAction.hide(sender.tab.id);
}
});
chrome.omnibox.onInputStarted.addListener(() => {
chrome.storage.local.get(null, items => {
allKnownBoxes = items;
});
});
chrome.omnibox.onInputChanged.addListener((text, suggest) => {
let suggestions = [];
for (let [name, status] of Object.entries(allKnownBoxes)) {
if (name.startsWith(text)) {
suggestions.push({
content: name,
description: `${name} (${status})`
});
}
}
suggest(suggestions);
});
chrome.omnibox.onInputEntered.addListener(hostname => {
// When using chrome.tabs.update() the focus stays
// at the omnibox, which is annoying when using a
// pasword manager to fill out the login details
// and such. So we remove the active tab and create
// a new one. This will lose the tab history, but
// it's the better of two evils.
chrome.tabs.query({ active: true }, (tab) => {
chrome.tabs.remove(tab[0].id, () => {
chrome.tabs.create({ url: `https://${hostname}` });
});
});
});