From c199ac20df15004378de07da28a964d437042cd2 Mon Sep 17 00:00:00 2001 From: josc146 Date: Tue, 11 Apr 2023 21:38:02 +0800 Subject: [PATCH] chore --- src/background/index.mjs | 44 ++++++++++++++++++++++++++---------- src/content-script/index.jsx | 1 - 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/background/index.mjs b/src/background/index.mjs index af77eac..4b76526 100644 --- a/src/background/index.mjs +++ b/src/background/index.mjs @@ -152,18 +152,26 @@ 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, } console.debug('command triggered', message) - if (command in menuConfig && menuConfig[command].action) menuConfig[command].action() - Browser.tabs.sendMessage(currentTab.id, { - type: 'CREATE_CHAT', - data: message, - }) + + if (command in menuConfig) { + if (menuConfig[command].action) { + menuConfig[command].action() + } + + if (menuConfig[command].genPrompt) { + const currentTab = (await Browser.tabs.query({ active: true, currentWindow: true }))[0] + Browser.tabs.sendMessage(currentTab.id, { + type: 'CREATE_CHAT', + data: message, + }) + } + } }) function refreshMenu() { @@ -212,12 +220,24 @@ function refreshMenu() { useMenuPosition: tab.id === currentTab.id, } console.debug('menu clicked', message) - if (message.itemId in menuConfig && menuConfig[message.itemId].action) - menuConfig[message.itemId].action() - Browser.tabs.sendMessage(currentTab.id, { - type: 'CREATE_CHAT', - data: message, - }) + + if (defaultConfig.selectionTools.includes(message.itemId)) { + Browser.tabs.sendMessage(currentTab.id, { + type: 'CREATE_CHAT', + data: message, + }) + } else if (message.itemId in menuConfig) { + if (menuConfig[message.itemId].action) { + menuConfig[message.itemId].action() + } + + if (menuConfig[message.itemId].genPrompt) { + Browser.tabs.sendMessage(currentTab.id, { + type: 'CREATE_CHAT', + data: message, + }) + } + } }) }) }) diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index b9b13a8..dd62369 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -304,7 +304,6 @@ async function run() { changeLanguage(lang) }) Browser.runtime.onMessage.addListener(async (message) => { - console.log(message) if (message.type === 'CHANGE_LANG') { const data = message.data changeLanguage(data.lang)