forked from jhen0409/react-chrome-extension-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contextMenus.js
41 lines (37 loc) · 809 Bytes
/
contextMenus.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
let windowId = 0;
const CONTEXT_MENU_ID = 'example_context_menu';
function closeIfExist() {
if (windowId > 0) {
chrome.windows.remove(windowId);
windowId = chrome.windows.WINDOW_ID_NONE;
}
}
function popWindow(type) {
closeIfExist();
const options = {
type: 'popup',
left: 100,
top: 100,
width: 800,
height: 475,
};
if (type === 'open') {
options.url = 'window.html';
chrome.windows.create(options, (win) => {
windowId = win.id;
});
}
}
chrome.contextMenus.create({
id: CONTEXT_MENU_ID,
title: 'React Chrome Extension Example',
contexts: ['all'],
documentUrlPatterns: [
'https://github.com/*'
]
});
chrome.contextMenus.onClicked.addListener((event) => {
if (event.menuItemId === CONTEXT_MENU_ID) {
popWindow('open');
}
});