2021-08-30 07:54:35 +03:00
|
|
|
import openDevToolsWindow, { DevToolsPosition } from './openWindow';
|
2020-10-26 15:18:23 +03:00
|
|
|
|
|
|
|
export function createMenu() {
|
|
|
|
const menus = [
|
|
|
|
{ id: 'devtools-left', title: 'To left' },
|
|
|
|
{ id: 'devtools-right', title: 'To right' },
|
|
|
|
{ id: 'devtools-bottom', title: 'To bottom' },
|
|
|
|
{
|
|
|
|
id: 'devtools-panel',
|
|
|
|
title: 'Open in a panel (enable in browser settings)',
|
|
|
|
},
|
|
|
|
{ id: 'devtools-remote', title: 'Open Remote DevTools' },
|
|
|
|
];
|
|
|
|
|
2021-08-25 07:22:54 +03:00
|
|
|
let shortcuts: { [commandName: string]: string | undefined } = {};
|
2020-10-26 15:18:23 +03:00
|
|
|
chrome.commands.getAll((commands) => {
|
|
|
|
commands.forEach(({ name, shortcut }) => {
|
2021-08-25 07:22:54 +03:00
|
|
|
shortcuts[name!] = shortcut;
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
menus.forEach(({ id, title }) => {
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
id: id,
|
|
|
|
title: title + (shortcuts[id] ? ' (' + shortcuts[id] + ')' : ''),
|
|
|
|
contexts: ['all'],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function removeMenu() {
|
|
|
|
chrome.contextMenus.removeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
|
2021-08-30 07:54:35 +03:00
|
|
|
openDevToolsWindow(menuItemId as DevToolsPosition);
|
2020-10-26 15:18:23 +03:00
|
|
|
});
|