-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
61 lines (54 loc) · 1.53 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
61
let currentTabId;
let calendarTabId;
let previousTab;
function onError(e) {
console.log("*** Error: " + e);
};
function setButtonIcon(imageURL) {
try {
browser.browserAction.setIcon({path: imageURL});
} catch (e) {
onError(e);
}
};
function createPinnedTab() {
browser.tabs.create({
url: "https://inbox.google.com",
pinned: true,
active: true
}
)
};
function handleSearch(calendarTabs) {
//console.log("currentTabId: " + currentTabId);
if (calendarTabs.length > 0) {
//console.log("there is a calendar tab");
calendarTabId = calendarTabs[0].id;
if (calendarTabId === currentTabId) {
//console.log("I'm in the calendar tab");
browser.tabs.update(previousTab, {active: true,});
} else {
//console.log("I'm NOT in the calendar tab");
previousTab = currentTabId;
browser.tabs.update(calendarTabId, {active: true,});
}
setButtonIcon(calendarTabs[0].favIconUrl);
} else {
//console.log("there is NO calendar tab");
previousTab = currentTabId;
createPinnedTab();
}
};
function handleClick(tab) {
currentTabId = tab.id;
var querying = browser.tabs.query({url: "*://inbox.google.com/*", currentWindow: true});
querying.then(handleSearch, onError);
};
function update(details) {
if (details.reason === "install" || details.reason === "update") {
var opening = browser.runtime.openOptionsPage();
opening.then(onOpened, onError);
}
};
browser.browserAction.onClicked.addListener(handleClick);
browser.runtime.onInstalled.addListener(update);