-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
48 lines (42 loc) · 1.24 KB
/
background.js
File metadata and controls
48 lines (42 loc) · 1.24 KB
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
var LA_CONTEXT_MENU_CONTENTS = {
forSelection: [
'Save as flashcard on LearnAwesome.org'
]
};
function la_setUpContextMenus() {
LA_CONTEXT_MENU_CONTENTS.forSelection.forEach(function (commandId) {
browser.contextMenus.create({
type: "normal",
title: commandId,
id: 'flashCard',
contexts: ['selection'],
onclick: function (info, tab) {
var params = {
url: info.pageUrl,
answer: info.selectionText
};
browser.tabs.executeScript({
code: 'var la_params = ' + JSON.stringify(params)
});
browser.tabs.executeScript({file: "browser-polyfill.js"});
browser.tabs.executeScript({ file: 'content-script.js' });
}
});
});
}
function onTabCreated(tab) {
console.log(`Created new tab: ${tab.id}`)
}
function onTabError(error) {
console.log(`Error: ${error}`);
}
function receiveMessage(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
console.log(request);
var creating = browser.tabs.create({url: request.url});
creating.then(onTabCreated, onTabError);
}
la_setUpContextMenus();
browser.runtime.onMessage.addListener(receiveMessage);