From ac11758301b8a583b01b0dfaaec1e7ca8f19e14c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 29 Aug 2025 19:04:55 +0000 Subject: [PATCH 1/7] Initial plan From 06179d97467ddb2661e8835b1f023148dfbd17e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 29 Aug 2025 19:11:09 +0000 Subject: [PATCH 2/7] Add custom Selection Tools support to right-click context menu Co-authored-by: PeterDaveHello <3691490+PeterDaveHello@users.noreply.github.com> --- src/background/menus.mjs | 38 +++++++++++++++++++++++++++++------- src/content-script/index.jsx | 12 +++++++++++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/background/menus.mjs b/src/background/menus.mjs index a92bd7ba..7145e01a 100644 --- a/src/background/menus.mjs +++ b/src/background/menus.mjs @@ -19,6 +19,12 @@ const onClickMenu = (info, tab) => { type: 'CREATE_CHAT', data: message, }) + } else if (message.itemId.startsWith('custom_')) { + // Handle custom selection tools + 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(true, tab) @@ -37,7 +43,8 @@ export function refreshMenu() { if (Browser.contextMenus.onClicked.hasListener(onClickMenu)) Browser.contextMenus.onClicked.removeListener(onClickMenu) Browser.contextMenus.removeAll().then(async () => { - if ((await getUserConfig()).hideContextMenu) return + const userConfig = await getUserConfig() + if (userConfig.hideContextMenu) return await getPreferredLanguageKey().then((lang) => { changeLanguage(lang) @@ -62,15 +69,32 @@ export function refreshMenu() { contexts: ['selection'], type: 'separator', }) + + // Add default selection tools that are active for (const index in defaultConfig.selectionTools) { const key = defaultConfig.selectionTools[index] const desc = defaultConfig.selectionToolsDesc[index] - Browser.contextMenus.create({ - id: menuId + key, - parentId: menuId, - title: t(desc), - contexts: ['selection'], - }) + if (userConfig.activeSelectionTools.includes(key)) { + Browser.contextMenus.create({ + id: menuId + key, + parentId: menuId, + title: t(desc), + contexts: ['selection'], + }) + } + } + + // Add custom selection tools that are active + for (let i = 0; i < userConfig.customSelectionTools.length; i++) { + const tool = userConfig.customSelectionTools[i] + if (tool.active && tool.name) { + Browser.contextMenus.create({ + id: menuId + 'custom_' + i, + parentId: menuId, + title: tool.name, + contexts: ['selection'], + }) + } } Browser.contextMenus.onClicked.addListener(onClickMenu) diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index 01b0b3aa..9e26bf1b 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -284,8 +284,19 @@ async function prepareForRightClickMenu() { if (message.type === 'CREATE_CHAT') { const data = message.data let prompt = '' + const userConfig = await getUserConfig() + if (data.itemId in toolsConfig) { prompt = await toolsConfig[data.itemId].genPrompt(data.selectionText) + } else if (data.itemId.startsWith('custom_')) { + // Handle custom selection tools from context menu + const customIndex = parseInt(data.itemId.replace('custom_', '')) + if (customIndex >= 0 && customIndex < userConfig.customSelectionTools.length) { + const customTool = userConfig.customSelectionTools[customIndex] + if (customTool.active && customTool.name) { + prompt = customTool.prompt.replace('{{selection}}', data.selectionText) + } + } } else if (data.itemId in menuConfig) { const menuItem = menuConfig[data.itemId] if (!menuItem.genPrompt) return @@ -298,7 +309,6 @@ async function prepareForRightClickMenu() { : { x: window.innerWidth / 2 - 300, y: window.innerHeight / 2 - 200 } const container = createElementAtPosition(position.x, position.y) container.className = 'chatgptbox-toolbar-container-not-queryable' - const userConfig = await getUserConfig() render( Date: Fri, 29 Aug 2025 19:14:28 +0000 Subject: [PATCH 3/7] Add menu refresh functionality to Selection Tools settings Co-authored-by: PeterDaveHello <3691490+PeterDaveHello@users.noreply.github.com> --- src/popup/sections/SelectionTools.jsx | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/popup/sections/SelectionTools.jsx b/src/popup/sections/SelectionTools.jsx index a166246e..ad777936 100644 --- a/src/popup/sections/SelectionTools.jsx +++ b/src/popup/sections/SelectionTools.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types' import { useState } from 'react' import { defaultConfig } from '../../config/index.mjs' import { PencilIcon, TrashIcon } from '@primer/octicons-react' +import Browser from 'webextension-polyfill' SelectionTools.propTypes = { config: PropTypes.object.isRequired, @@ -36,7 +37,7 @@ export function SelectionTools({ config, updateConfig }) { {t('Cancel')}