-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsuite.js
53 lines (46 loc) · 1.22 KB
/
gsuite.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
"use strict";
/* globals browser */
const OpenTab = (tabs, url) => {
if ( tabs.length === 0 ) {
// console.log('Create new tab');
browser.tabs.create({ url:url });
} else {
let tab = tabs[0]
let tabId = tab.id
// console.log(`Go to tab: ${url} (${tabId})`);
browser.tabs.update(tabId, {active: true });
}
}
const onError = (error) => {
console.log(`Error: ${error}`);
}
const QueryTabs = (url) => {
// console.log(`Click: ${url}`);
let domain = (new URL(url));
let querying = browser.tabs.query({url:`${domain.protocol}//${domain.hostname}/*`});
querying.then((tabs) => {
OpenTab(tabs, url)
}, onError);
}
window.addEventListener("click", LoadClick)
function LoadClick(e) {
switch ( e.target.id ) {
case 'calendar':
QueryTabs('https://calendar.google.com/');
break;
case 'tasks':
QueryTabs('https://tasks.google.com/embed/?origin=https://mail.google.com&fullWidth=1&lfhs=2&pli=1');
break;
case 'contacts':
QueryTabs('https://contacts.google.com/');
break;
case 'keep':
QueryTabs('https://keep.google.com/');
break;
case 'drive':
QueryTabs('https://drive.google.com/');
break;
default:
return;
}
}