-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
55 lines (49 loc) · 1.67 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
import { config } from './config.js'
const defaultPreferences = {
name: ''
};
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({ preferences: defaultPreferences, todos: {} }, function() {
console.log('Default preferences syced.');
});
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.update({ url: "https://zamandalee.github.io/Snippet/"} );
window.close();
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch( request.type ) {
case 'getVocabWord':
// ajax request to oxford dictionary for vocabSnippet
$.ajax({
url: `https://od-api.oxforddictionaries.com:443/api/v2/entries/en-us/${request.word}`,
method: 'GET',
headers: {
'app_id': config.OXFORD_DICT_APP_ID,
'app_key': config.OXFORD_DICT_APP_KEY
},
}).done( result => {
sendResponse({result: result.results[0]});
});
}
return true; //necessary for sendResponse() to be valid
});
// chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// debugger;
// switch( request.type ) {
// case 'getVocabWord':
// // ajax request to oxford dictionary for vocabSnippet
// debugger;
// $.ajax({
// url: `https://od-api.oxforddictionaries.com:443/api/v2/entries/en-us/${request.word}`,
// method: 'GET',
// headers: {
// 'app_id': "4d02697c",
// 'app_key': "bb507e921eece6a19bba40e6f321026a"
// },
// }).done( result => {
// sendResponse({result: result.results[0]});
// });
// }
// return true; //necessary for sendResponse() to be valid
// });