-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
71 lines (61 loc) · 2.26 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
62
63
64
65
66
67
68
69
70
71
/**
* Omnidrive
* Quickly create new Google Drive documents
*/
chrome.storage.sync.get('appDomain', cb );
function cb (response) {
let appDomain;
if (response.appDomain != null && response.appDomain.length > 0) {
appDomain = response.appDomain;
} else {
appDomain = '';
}
chrome.omnibox.onInputChanged.addListener (
(text, suggest) => {
const suggestions = [
{ content: 'doc', description: 'Create New Google Document' },
{ content: 'sheet', description: 'Create New Google Spreadsheet' },
{ content: 'presentation', description: 'Create New Google Presentation' },
{ content: 'drawing', description: 'Create New Google Drawing' }
];
suggest(suggestions);
}
);
chrome.omnibox.onInputEntered.addListener (
(text) => {
let url = '';
switch (text) {
case 'sheet':
if (appDomain.length > 0) {
url = `https://docs.google.com/a/${appDomain}/spreadsheet/ccc?new`;
} else {
url = 'https://sheets.google.com/create';
}
break;
case 'presentation':
if (appDomain.length > 0) {
url = `https://docs.google.com/a/${appDomain}/presentation/create`;
} else {
url = 'https://slides.google.com/create';
}
break;
case 'drawing':
if (appDomain.length > 0) {
url = `https://drawings.google.com/a/${appDomain}/create`;
} else {
url = 'https://drawings.google.com/create';
}
break;
case 'doc':
default:
if (appDomain.length > 0) {
url = `https://docs.google.com/a/${appDomain}/document/create`;
} else {
url = 'https://docs.google.com/document/create';
}
break;
}
chrome.tabs.create ({ 'url': url });
}
);
}