-
Notifications
You must be signed in to change notification settings - Fork 24
/
background.js
44 lines (40 loc) · 1.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
var omni = new Omni(localStorage.setup === 'true');
chrome.runtime.onMessage.addListener(function (message) {
switch (message) {
case 'authorize':
omni.authorize();
break;
case 'decorate':
chrome.extension.sendMessage(localStorage);
break;
case 'reset':
omni.reset();
alert('Cache has been cleared');
break;
case 'login':
omni.authorize(function(){
alert('Logged in');
});
break;
case 'logout':
omni.unauthorize();
alert('Logged out');
break;
}
});
chrome.omnibox.onInputChanged.addListener(omni.suggest.bind(omni));
chrome.omnibox.onInputStarted.addListener(function () {
if (_.isUndefined(localStorage.setup)) {
if (confirm('Would you like to Authorize Github-Omnibox for personalized suggestions?')) {
omni.authorize();
localStorage.setup = true;
alert('You can unauthorize at any time by doing "gh my unauth"');
} else {
omni.unauthorize();
localStorage.setup = false;
}
}
});
chrome.omnibox.onInputEntered.addListener(function (text) {
if (text) omni.decide(text);
});