diff --git a/src/_locales/de/main.json b/src/_locales/de/main.json index 8be632d3..8c4a833a 100644 --- a/src/_locales/de/main.json +++ b/src/_locales/de/main.json @@ -133,5 +133,14 @@ "Generating...": "Generieren...", "moonshot token required, please login at https://kimi.moonshot.cn first": "Moonshot-Token erforderlich, bitte zuerst bei https://kimi.moonshot.cn anmelden", "Hide context menu of this extension": "Kontextmenü dieser Erweiterung ausblenden", - "Custom Claude API Url": "Benutzerdefinierte Claude-API-URL" + "Custom Claude API Url": "Benutzerdefinierte Claude-API-URL", + "Cancel": "Abbrechen", + "Name is required": "Name ist erforderlich", + "Prompt template should include {{selection}}": "Die Vorlage sollte {{selection}} enthalten", + "Save": "Speichern", + "Name": "Name", + "Icon": "Symbol", + "Prompt Template": "Vorlagen-Template", + "Explain this: {{selection}}": "Erkläre das: {{selection}}", + "New": "Neu" } diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 32a3f696..e95837d6 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -133,5 +133,14 @@ "Generating...": "Generating...", "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshot token required, please login at https://kimi.moonshot.cn first", "Hide context menu of this extension": "Hide context menu of this extension", - "Custom Claude API Url": "Custom Claude API Url" + "Custom Claude API Url": "Custom Claude API Url", + "Cancel": "Cancel", + "Name is required": "Name is required", + "Prompt template should include {{selection}}": "Prompt template should include {{selection}}", + "Save": "Save", + "Name": "Name", + "Icon": "Icon", + "Prompt Template": "Prompt Template", + "Explain this: {{selection}}": "Explain this: {{selection}}", + "New": "New" } diff --git a/src/_locales/es/main.json b/src/_locales/es/main.json index c319c5b1..905c448f 100644 --- a/src/_locales/es/main.json +++ b/src/_locales/es/main.json @@ -133,5 +133,14 @@ "Generating...": "Generando...", "moonshot token required, please login at https://kimi.moonshot.cn first": "se requiere un token de moonshot, por favor inicie sesión en https://kimi.moonshot.cn primero", "Hide context menu of this extension": "Ocultar menú contextual de esta extensión", - "Custom Claude API Url": "URL personalizada de la API de Claude" + "Custom Claude API Url": "URL personalizada de la API de Claude", + "Cancel": "Cancelar", + "Name is required": "Se requiere un nombre", + "Prompt template should include {{selection}}": "La plantilla de sugerencias debe incluir {{selection}}", + "Save": "Guardar", + "Name": "Nombre", + "Icon": "Icono", + "Prompt Template": "Plantilla de sugerencias", + "Explain this: {{selection}}": "Explicar esto: {{selection}}", + "New": "Nuevo" } diff --git a/src/_locales/fr/main.json b/src/_locales/fr/main.json index 964cea58..1fa9fa02 100644 --- a/src/_locales/fr/main.json +++ b/src/_locales/fr/main.json @@ -133,5 +133,14 @@ "Generating...": "Génération...", "moonshot token required, please login at https://kimi.moonshot.cn first": "jeton moonshot requis, veuillez vous connecter d'abord sur https://kimi.moonshot.cn", "Hide context menu of this extension": "Masquer le menu contextuel de cette extension", - "Custom Claude API Url": "URL API Claude personnalisée" + "Custom Claude API Url": "URL API Claude personnalisée", + "Cancel": "Annuler", + "Name is required": "Le nom est requis", + "Prompt template should include {{selection}}": "Le modèle de suggestion doit inclure {{selection}}", + "Save": "Enregistrer", + "Name": "Nom", + "Icon": "Icône", + "Prompt Template": "Modèle de suggestion", + "Explain this: {{selection}}": "Expliquer ceci : {{selection}}", + "New": "Nouveau" } diff --git a/src/_locales/in/main.json b/src/_locales/in/main.json index bffb3341..28a9d207 100644 --- a/src/_locales/in/main.json +++ b/src/_locales/in/main.json @@ -133,5 +133,14 @@ "Generating...": "Menghasilkan...", "moonshot token required, please login at https://kimi.moonshot.cn first": "diperlukan token moonshot, silakan masuk di https://kimi.moonshot.cn terlebih dahulu", "Hide context menu of this extension": "Sembunyikan menu konteks ekstensi ini", - "Custom Claude API Url": "URL API Claude Kustom" + "Custom Claude API Url": "URL API Claude Kustom", + "Cancel": "Batal", + "Name is required": "Nama diperlukan", + "Prompt template should include {{selection}}": "Template prompt harus mencakup {{selection}}", + "Save": "Simpan", + "Name": "Nama", + "Icon": "Ikon", + "Prompt Template": "Template Prompt", + "Explain this: {{selection}}": "Jelaskan ini: {{selection}}", + "New": "Baru" } diff --git a/src/_locales/it/main.json b/src/_locales/it/main.json index 43e4a009..c095e4ad 100644 --- a/src/_locales/it/main.json +++ b/src/_locales/it/main.json @@ -133,5 +133,14 @@ "Generating...": "Generazione...", "moonshot token required, please login at https://kimi.moonshot.cn first": "richiesto token moonshot, effettua il login su https://kimi.moonshot.cn prima", "Hide context menu of this extension": "Nascondi il menu contestuale di questa estensione", - "Custom Claude API Url": "URL API Claude personalizzato" + "Custom Claude API Url": "URL API Claude personalizzato", + "Cancel": "Annulla", + "Name is required": "Il nome è obbligatorio", + "Prompt template should include {{selection}}": "Il modello di prompt dovrebbe includere {{selection}}", + "Save": "Salva", + "Name": "Nome", + "Icon": "Icona", + "Prompt Template": "Modello di prompt", + "Explain this: {{selection}}": "Spiega questo: {{selection}}", + "New": "Nuovo" } diff --git a/src/_locales/ja/main.json b/src/_locales/ja/main.json index cadc75ac..99f20e33 100644 --- a/src/_locales/ja/main.json +++ b/src/_locales/ja/main.json @@ -133,5 +133,14 @@ "Generating...": "生成中...", "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshotトークンが必要です。最初に https://kimi.moonshot.cn にログインしてください", "Hide context menu of this extension": "この拡張機能のコンテキストメニューを非表示", - "Custom Claude API Url": "カスタムClaude APIのURL" + "Custom Claude API Url": "カスタムClaude APIのURL", + "Cancel": "キャンセル", + "Name is required": "名前は必須です", + "Prompt template should include {{selection}}": "プロンプトテンプレートには {{selection}} を含める必要があります", + "Save": "保存", + "Name": "名前", + "Icon": "アイコン", + "Prompt Template": "プロンプトテンプレート", + "Explain this: {{selection}}": "これを説明する: {{selection}}", + "New": "新規" } diff --git a/src/_locales/ko/main.json b/src/_locales/ko/main.json index 29882f4d..d5e0c002 100644 --- a/src/_locales/ko/main.json +++ b/src/_locales/ko/main.json @@ -133,5 +133,14 @@ "Generating...": "생성 중...", "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshot 토큰이 필요합니다. https://kimi.moonshot.cn 에서 로그인하세요.", "Hide context menu of this extension": "이 확장 프로그램의 컨텍스트 메뉴 숨기기", - "Custom Claude API Url": "사용자 정의 Claude API URL" + "Custom Claude API Url": "사용자 정의 Claude API URL", + "Cancel": "취소", + "Name is required": "이름은 필수입니다", + "Prompt template should include {{selection}}": "프롬프트 템플릿에는 {{selection}} 이 포함되어야 합니다", + "Save": "저장", + "Name": "이름", + "Icon": "아이콘", + "Prompt Template": "프롬프트 템플릿", + "Explain this: {{selection}}": "이것을 설명하세요: {{selection}}", + "New": "새로 만들기" } diff --git a/src/_locales/pt/main.json b/src/_locales/pt/main.json index 553a387b..f220e714 100644 --- a/src/_locales/pt/main.json +++ b/src/_locales/pt/main.json @@ -133,5 +133,14 @@ "Generating...": "Gerando...", "moonshot token required, please login at https://kimi.moonshot.cn first": "token moonshot necessário, por favor faça login em https://kimi.moonshot.cn primeiro", "Hide context menu of this extension": "Ocultar menu de contexto desta extensão", - "Custom Claude API Url": "URL da API Personalizada do Claude" + "Custom Claude API Url": "URL da API Personalizada do Claude", + "Cancel": "Cancelar", + "Name is required": "Nome é obrigatório", + "Prompt template should include {{selection}}": "O modelo de prompt deve incluir {{selection}}", + "Save": "Salvar", + "Name": "Nome", + "Icon": "Ícone", + "Prompt Template": "Modelo de Prompt", + "Explain this: {{selection}}": "Explique isso: {{selection}}", + "New": "Novo" } diff --git a/src/_locales/ru/main.json b/src/_locales/ru/main.json index 0774b65e..4923d3a2 100644 --- a/src/_locales/ru/main.json +++ b/src/_locales/ru/main.json @@ -133,5 +133,14 @@ "Generating...": "Генерация...", "moonshot token required, please login at https://kimi.moonshot.cn first": "требуется токен moonshot, пожалуйста, сначала войдите на https://kimi.moonshot.cn", "Hide context menu of this extension": "Скрыть контекстное меню этого расширения", - "Custom Claude API Url": "Пользовательский URL API Claude" + "Custom Claude API Url": "Пользовательский URL API Claude", + "Cancel": "Отмена", + "Name is required": "Имя обязательно", + "Prompt template should include {{selection}}": "Шаблон запроса должен включать {{selection}}", + "Save": "Сохранить", + "Name": "Имя", + "Icon": "Иконка", + "Prompt Template": "Шаблон запроса", + "Explain this: {{selection}}": "Объяснить это: {{selection}}", + "New": "Новый" } diff --git a/src/_locales/tr/main.json b/src/_locales/tr/main.json index 3b413f53..66825495 100644 --- a/src/_locales/tr/main.json +++ b/src/_locales/tr/main.json @@ -133,5 +133,14 @@ "Generating...": "Üretiliyor...", "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshot jetonu gerekiyor, lütfen önce https://kimi.moonshot.cn adresinde oturum açın", "Hide context menu of this extension": "Bu uzantının bağlam menüsünü gizle", - "Custom Claude API Url": "Özel Claude API Url'si" + "Custom Claude API Url": "Özel Claude API Url'si", + "Cancel": "İptal", + "Name is required": "İsim gereklidir", + "Prompt template should include {{selection}}": "Prompt şablonu {{selection}} içermelidir", + "Save": "Kaydet", + "Name": "İsim", + "Icon": "Simge", + "Prompt Template": "Prompt Şablonu", + "Explain this: {{selection}}": "Bunu açıkla: {{selection}}", + "New": "Yeni" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index 0e8139f2..47faf197 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -133,5 +133,14 @@ "Generating...": "正在生成...", "moonshot token required, please login at https://kimi.moonshot.cn first": "需要moonshot token, 请先登录 https://kimi.moonshot.cn", "Hide context menu of this extension": "隐藏此扩展的右键菜单", - "Custom Claude API Url": "自定义的Claude API地址" + "Custom Claude API Url": "自定义的Claude API地址", + "Cancel": "取消", + "Name is required": "名称是必须的", + "Prompt template should include {{selection}}": "提示模板应该包含 {{selection}}", + "Save": "保存", + "Name": "名称", + "Icon": "图标", + "Prompt Template": "提示模板", + "Explain this: {{selection}}": "解释这个: {{selection}}", + "New": "新建" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index c86f53f0..54d8266b 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -133,5 +133,14 @@ "Generating...": "產生中...", "moonshot token required, please login at https://kimi.moonshot.cn first": "需要 moonshot token,請先在 https://kimi.moonshot.cn 登入", "Hide context menu of this extension": "隱藏此擴充功能的右鍵選單", - "Custom Claude API Url": "自訂 Claude API 網址" + "Custom Claude API Url": "自訂 Claude API 網址", + "Cancel": "取消", + "Name is required": "名稱是必填的", + "Prompt template should include {{selection}}": "提示模板應該包含 {{selection}}", + "Save": "儲存", + "Name": "名稱", + "Icon": "圖示", + "Prompt Template": "提示模板", + "Explain this: {{selection}}": "解釋這個: {{selection}}", + "New": "新增" } diff --git a/src/components/FloatingToolbar/index.jsx b/src/components/FloatingToolbar/index.jsx index 01efc1e0..e0705bda 100644 --- a/src/components/FloatingToolbar/index.jsx +++ b/src/components/FloatingToolbar/index.jsx @@ -113,27 +113,41 @@ function FloatingToolbar(props) { ) } else { - if (config.activeSelectionTools.length === 0) return
+ if ( + config.activeSelectionTools.length === 0 && + config.customSelectionTools.reduce((count, tool) => count + (tool.active ? 1 : 0), 0) === 0 + ) + return
const tools = [] + const pushTool = (iconKey, name, genPrompt) => { + tools.push( + cloneElement(toolsConfig[iconKey].icon, { + size: 24, + className: 'chatgptbox-selection-toolbar-button', + title: name, + onClick: async () => { + const p = getClientPosition(props.container) + props.container.style.position = 'fixed' + setPosition(p) + setPrompt(await genPrompt(selection)) + setTriggered(true) + }, + }), + ) + } for (const key in toolsConfig) { if (config.activeSelectionTools.includes(key)) { const toolConfig = toolsConfig[key] - tools.push( - cloneElement(toolConfig.icon, { - size: 24, - className: 'chatgptbox-selection-toolbar-button', - title: t(toolConfig.label), - onClick: async () => { - const p = getClientPosition(props.container) - props.container.style.position = 'fixed' - setPosition(p) - setPrompt(await toolConfig.genPrompt(selection)) - setTriggered(true) - }, - }), - ) + pushTool(key, t(toolConfig.label), toolConfig.genPrompt) + } + } + for (const tool of config.customSelectionTools) { + if (tool.active) { + pushTool(tool.iconKey, tool.name, async (selection) => { + return tool.prompt.replace('{{selection}}', selection) + }) } } diff --git a/src/config/index.mjs b/src/config/index.mjs index 8e915a03..7e664b05 100644 --- a/src/config/index.mjs +++ b/src/config/index.mjs @@ -267,6 +267,14 @@ export const defaultConfig = { 'azureOpenAi', ], activeSelectionTools: ['translate', 'addtests', 'codereview', 'code', 'ask'], + customSelectionTools: [ + { + name: '', + iconKey: 'explain', + prompt: 'sample prompt: {{selection}}', + active: false, + }, + ], activeSiteAdapters: [ 'bilibili', 'github', diff --git a/src/popup/sections/SelectionTools.jsx b/src/popup/sections/SelectionTools.jsx index 589c2a2e..cecec178 100644 --- a/src/popup/sections/SelectionTools.jsx +++ b/src/popup/sections/SelectionTools.jsx @@ -1,14 +1,99 @@ import { useTranslation } from 'react-i18next' import { config as toolsConfig } from '../../content-script/selection-tools/index.mjs' import PropTypes from 'prop-types' +import { useState } from 'react' +import { defaultConfig } from '../../config/index.mjs' +import { PencilIcon, TrashIcon } from '@primer/octicons-react' SelectionTools.propTypes = { config: PropTypes.object.isRequired, updateConfig: PropTypes.func.isRequired, } +const defaultTool = { + name: '', + iconKey: 'explain', + prompt: 'Explain this: {{selection}}', + active: true, +} + export function SelectionTools({ config, updateConfig }) { const { t } = useTranslation() + const [editing, setEditing] = useState(false) + const [errorMessage, setErrorMessage] = useState('') + const [editingTool, setEditingTool] = useState(defaultTool) + const [editingIndex, setEditingIndex] = useState(-1) + + const editingComponent = ( +
+
+ + +
+ {errorMessage &&
{errorMessage}
} +
+ {t('Name')} + setEditingTool({ ...editingTool, name: e.target.value })} + /> + {t('Icon')} + +
+ {t('Prompt Template')} +