-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
39 lines (34 loc) · 859 Bytes
/
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
let urls = {};
let menu = {
search: () => {
let q = prompt();
q &&
chrome.tabs.create({
url: "http://www.imdb.com/find?s=all&q=" + encodeURIComponent(q)
});
},
history: () => {
chrome.tabs.create({ url: "chrome://history/#q=imdb.com/title/tt" });
}
};
Object.keys(menu).forEach(item => {
chrome.contextMenus.create({
id: item,
title: chrome.i18n.getMessage("menu_" + item),
contexts: ["page_action"]
});
});
chrome.contextMenus.onClicked.addListener(info => {
menu[info.menuItemId]();
});
chrome.runtime.onMessage.addListener((req, sender) => {
urls[sender.tab.id] = req.url;
chrome.pageAction[req.url ? "show" : "hide"](sender.tab.id);
});
chrome.pageAction.onClicked.addListener(tab => {
chrome.windows.create({
url: urls[tab.id],
type: "popup",
state: "fullscreen"
});
});