diff --git a/src/background/index.mjs b/src/background/index.mjs index 6cd4ac4..758ee23 100644 --- a/src/background/index.mjs +++ b/src/background/index.mjs @@ -126,6 +126,19 @@ Browser.runtime.onMessage.addListener(async (message) => { } }) +Browser.commands.onCommand.addListener(async (command) => { + const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0] + const message = { + itemId: command, + selectionText: '', + useMenuPosition: false, + } + Browser.tabs.sendMessage(currentTab.id, { + type: 'CREATE_CHAT', + data: message, + }) +}) + function refreshMenu() { Browser.contextMenus.removeAll().then(() => { const menuId = 'ChatGPTBox-Menu' @@ -164,10 +177,11 @@ function refreshMenu() { const message = { itemId: info.menuItemId.replace(menuId, ''), selectionText: info.selectionText, + useMenuPosition: true, } console.debug('menu clicked', message) Browser.tabs.sendMessage(tab.id, { - type: 'CREATE_MENU', + type: 'CREATE_CHAT', data: message, }) }) diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index 96054de..b440b1f 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -218,7 +218,7 @@ async function prepareForRightClickMenu() { }) Browser.runtime.onMessage.addListener(async (message) => { - if (message.type === 'CREATE_MENU') { + if (message.type === 'CREATE_CHAT') { const data = message.data let prompt = '' if (data.itemId in toolsConfig) { @@ -228,7 +228,9 @@ async function prepareForRightClickMenu() { if (prompt) prompt = cropText(`Reply in ${await getPreferredLanguage()}.\n` + prompt) } - const position = { x: menuX, y: menuY } + const position = data.useMenuPosition + ? { x: menuX, y: menuY } + : { x: window.innerWidth / 2 - 300, y: window.innerHeight / 2 - 200 } const container = createElementAtPosition(position.x, position.y) container.className = 'chatgptbox-toolbar-container-not-queryable' render( diff --git a/src/manifest.json b/src/manifest.json index 9cbe040..44e73ad 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -14,6 +14,7 @@ "https://*.bing.com/" ], "permissions": [ + "commands", "cookies", "storage", "contextMenus" @@ -47,5 +48,21 @@ "" ] } - ] + ], + "commands": { + "newChat": { + "suggested_key": { + "default": "Ctrl+B", + "mac": "MacCtrl+B" + }, + "description": "Create a new chat" + }, + "summarizePage": { + "suggested_key": { + "default": "Alt+B", + "mac": "Alt+B" + }, + "description": "Summarize this page" + } + } } \ No newline at end of file diff --git a/src/manifest.v2.json b/src/manifest.v2.json index c0cf39d..98f217e 100644 --- a/src/manifest.v2.json +++ b/src/manifest.v2.json @@ -10,6 +10,7 @@ "128": "logo.png" }, "permissions": [ + "commands", "cookies", "storage", "contextMenus", @@ -40,5 +41,21 @@ ], "web_accessible_resources": [ "*.png" - ] + ], + "commands": { + "newChat": { + "suggested_key": { + "default": "Ctrl+B", + "mac": "MacCtrl+B" + }, + "description": "Create a new chat" + }, + "summarizePage": { + "suggested_key": { + "default": "Alt+B", + "mac": "Alt+B" + }, + "description": "Summarize this page" + } + } } \ No newline at end of file