-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
62 lines (55 loc) · 1.3 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
/*
Called when the item has been created, or when creation failed due to an error.
We'll just log success/failure here.
*/
function onCreated() {
if (browser.runtime.lastError) {
console.log(`Error: ${browser.runtime.lastError}`);
} else {
console.log("Item created successfully");
}
}
/*
Called when the item has been removed.
We'll just log success here.
*/
function onRemoved() {
console.log("Item removed successfully");
}
/*
Called when there was an error.
We'll just log the error here.
*/
function onError(error) {
console.log(`Error: ${error}`);
}
/*
Create context menu.
*/
browser.menus.create({
id: "open_tmdb",
title: "Search this in TMDB",
contexts: ["selection"],
icons: {
"48": "icons/green_48.png",
"32": "icons/green_32.png",
"16": "icons/green_16.png"
}
}, onCreated);
function searchTMDB(txt) {
browser.tabs.create({
url: 'https://www.themoviedb.org/search?query='+txt
});
}
/*
The click event listener, where we perform the appropriate action given the
ID of the menu item that was clicked.
*/
browser.menus.onClicked.addListener((info, tab) => {
switch (info.menuItemId) {
case "open_tmdb":
console.log(info.selectionText);
searchTMDB(info.selectionText);
break;
}
});