forked from Khan/KhanAcademyDots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
36 lines (33 loc) · 1.02 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
/*global chrome*/
// The following is needed to open option page automatically
// if the locale is not set
// https://stackoverflow.com/questions/49192636/how-can-i-open-my-options-html-currently-i-get-cannot-read-property-create-of
//
// This Js file is run in the background, see:
// https://developer.chrome.com/extensions/background_pages
chrome.runtime.onMessage.addListener(function(message) {
switch (message.action) {
case 'openOptionsPage':
openOptionsPage();
break;
default:
break;
}
});
chrome.commands.onCommand.addListener(function(command) {
if (command === 'translate-math') {
//Send keyboard shortcut click to the current tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {'action': 'translate-math'});
});
}
});
/**
* Auxiliary function to open Options page
* using Chrome API
*
* @returns {undefined}
*/
function openOptionsPage() {
chrome.runtime.openOptionsPage();
}