diff --git a/src/_locales/de/main.json b/src/_locales/de/main.json index 3f3bbb39..03c60b1d 100644 --- a/src/_locales/de/main.json +++ b/src/_locales/de/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Bitte halten Sie https://chat.openai.com geöffnet und versuchen Sie es erneut. Wenn es immer noch nicht funktioniert, geben Sie einige Zeichen in das Eingabefeld der ChatGPT-Webseite ein und versuchen Sie es erneut.", "Open Side Panel": "Seitenleiste öffnen", "Generating...": "Generieren...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "Moonshot-Token erforderlich, bitte zuerst bei https://kimi.moonshot.cn anmelden" + "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" } diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 637b4ad8..e5396b01 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.", "Open Side Panel": "Open Side Panel", "Generating...": "Generating...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshot token required, please login at https://kimi.moonshot.cn first" + "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" } diff --git a/src/_locales/es/main.json b/src/_locales/es/main.json index 966e6a33..5a1ac6ad 100644 --- a/src/_locales/es/main.json +++ b/src/_locales/es/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Por favor, mantenga https://chat.openai.com abierto e inténtelo de nuevo. Si aún no funciona, escriba algunos caracteres en el cuadro de entrada de la página web de chatgpt e inténtelo de nuevo.", "Open Side Panel": "Abrir panel lateral", "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" + "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" } diff --git a/src/_locales/fr/main.json b/src/_locales/fr/main.json index 948cfe3e..b25fadb1 100644 --- a/src/_locales/fr/main.json +++ b/src/_locales/fr/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Veuillez garder https://chat.openai.com ouvert et réessayer. Si cela ne fonctionne toujours pas, tapez quelques caractères dans la boîte de saisie de la page web chatgpt et réessayez.", "Open Side Panel": "Ouvrir le panneau latéral", "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" + "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" } diff --git a/src/_locales/in/main.json b/src/_locales/in/main.json index ff6e04d3..b1a87043 100644 --- a/src/_locales/in/main.json +++ b/src/_locales/in/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Harap tetap buka https://chat.openai.com dan coba lagi. Jika masih tidak berhasil, ketik beberapa karakter di kotak masukan halaman web chatgpt dan coba lagi.", "Open Side Panel": "Buka Panel Samping", "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" + "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" } diff --git a/src/_locales/it/main.json b/src/_locales/it/main.json index 3670735e..70478654 100644 --- a/src/_locales/it/main.json +++ b/src/_locales/it/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Per favore, mantieni aperto https://chat.openai.com e riprova. Se ancora non funziona, digita alcuni caratteri nella casella di input della pagina web di chatgpt e riprova.", "Open Side Panel": "Apri il pannello laterale", "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" + "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" } diff --git a/src/_locales/ja/main.json b/src/_locales/ja/main.json index 424d6c39..e7cd0ae5 100644 --- a/src/_locales/ja/main.json +++ b/src/_locales/ja/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "https://chat.openai.com を開いたままにして、もう一度試してください。それでもうまくいかない場合は、chatgpt webページの入力ボックスにいくつかの文字を入力してからもう一度試してください。", "Open Side Panel": "サイドパネルを開く", "Generating...": "生成中...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshotトークンが必要です。最初にhttps://kimi.moonshot.cnにログインしてください" + "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshotトークンが必要です。最初にhttps://kimi.moonshot.cnにログインしてください", + "Hide context menu of this extension": "この拡張機能のコンテキストメニューを非表示" } diff --git a/src/_locales/ko/main.json b/src/_locales/ko/main.json index 5c446535..84201f64 100644 --- a/src/_locales/ko/main.json +++ b/src/_locales/ko/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "https://chat.openai.com 을 열어두고 다시 시도하세요. 여전히 작동하지 않으면 chatgpt 웹 페이지의 입력 상자에 몇 가지 문자를 입력한 다음 다시 시도하세요.", "Open Side Panel": "사이드 패널 열기", "Generating...": "생성 중...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshot 토큰이 필요합니다. https://kimi.moonshot.cn 에서 로그인하세요." + "moonshot token required, please login at https://kimi.moonshot.cn first": "moonshot 토큰이 필요합니다. https://kimi.moonshot.cn 에서 로그인하세요.", + "Hide context menu of this extension": "이 확장 프로그램의 컨텍스트 메뉴 숨기기" } diff --git a/src/_locales/pt/main.json b/src/_locales/pt/main.json index 5d704713..e87ac9bc 100644 --- a/src/_locales/pt/main.json +++ b/src/_locales/pt/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Por favor, mantenha https://chat.openai.com aberto e tente novamente. Se ainda não funcionar, digite alguns caracteres na caixa de entrada da página da web do chatgpt e tente novamente.", "Open Side Panel": "Abrir Painel Lateral", "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" + "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" } diff --git a/src/_locales/ru/main.json b/src/_locales/ru/main.json index 1b42392a..917cd79f 100644 --- a/src/_locales/ru/main.json +++ b/src/_locales/ru/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Пожалуйста, оставьте открытым https://chat.openai.com и попробуйте еще раз. Если это все еще не работает, введите несколько символов в поле ввода веб-страницы chatgpt и попробуйте еще раз.", "Open Side Panel": "Открыть боковую панель", "Generating...": "Генерация...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "требуется токен moonshot, пожалуйста, сначала войдите на https://kimi.moonshot.cn" + "moonshot token required, please login at https://kimi.moonshot.cn first": "требуется токен moonshot, пожалуйста, сначала войдите на https://kimi.moonshot.cn", + "Hide context menu of this extension": "Скрыть контекстное меню этого расширения" } diff --git a/src/_locales/tr/main.json b/src/_locales/tr/main.json index 88fc7b0e..190f8f2c 100644 --- a/src/_locales/tr/main.json +++ b/src/_locales/tr/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "Lütfen https://chat.openai.com adresini açık tutun ve tekrar deneyin. Hala çalışmazsa, chatgpt web sayfasının girdi kutusuna bazı karakterler yazın ve tekrar deneyin.", "Open Side Panel": "Yan Paneli Aç", "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" + "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" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index b1c76fc0..d69712c7 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "请保持 https://chat.openai.com 打开并重试. 如果仍然不起作用, 请在chatgpt网页的输入框中输入一些字符, 然后再试一次.", "Open Side Panel": "打开侧边栏", "Generating...": "正在生成...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "需要moonshot token, 请先登录 https://kimi.moonshot.cn" + "moonshot token required, please login at https://kimi.moonshot.cn first": "需要moonshot token, 请先登录 https://kimi.moonshot.cn", + "Hide context menu of this extension": "隐藏此扩展的右键菜单" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index 08afc334..68c065fa 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -131,5 +131,6 @@ "Please keep https://chat.openai.com open and try again. If it still doesn't work, type some characters in the input box of chatgpt web page and try again.": "請保持 https://chat.openai.com 開啟並重試,如果還是無法通過驗證,請在 ChatGPT 網頁版輸入框輸入一些文字後再重試", "Open Side Panel": "開啟側邊面板", "Generating...": "產生中...", - "moonshot token required, please login at https://kimi.moonshot.cn first": "需要 moonshot token,請先在 https://kimi.moonshot.cn 登入" + "moonshot token required, please login at https://kimi.moonshot.cn first": "需要 moonshot token,請先在 https://kimi.moonshot.cn 登入", + "Hide context menu of this extension": "隱藏此擴充功能的右鍵選單" } diff --git a/src/background/menus.mjs b/src/background/menus.mjs index f53ffe14..a92bd7ba 100644 --- a/src/background/menus.mjs +++ b/src/background/menus.mjs @@ -1,14 +1,47 @@ import Browser from 'webextension-polyfill' -import { defaultConfig, getPreferredLanguageKey } from '../config/index.mjs' +import { defaultConfig, getPreferredLanguageKey, getUserConfig } from '../config/index.mjs' import { changeLanguage, t } from 'i18next' import { config as menuConfig } from '../content-script/menu-tools/index.mjs' +const menuId = 'ChatGPTBox-Menu' +const onClickMenu = (info, tab) => { + Browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { + const currentTab = tabs[0] + const message = { + itemId: info.menuItemId.replace(menuId, ''), + selectionText: info.selectionText, + useMenuPosition: tab.id === currentTab.id, + } + console.debug('menu clicked', 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(true, tab) + } + + if (menuConfig[message.itemId].genPrompt) { + Browser.tabs.sendMessage(currentTab.id, { + type: 'CREATE_CHAT', + data: message, + }) + } + } + }) +} export function refreshMenu() { + if (Browser.contextMenus.onClicked.hasListener(onClickMenu)) + Browser.contextMenus.onClicked.removeListener(onClickMenu) Browser.contextMenus.removeAll().then(async () => { + if ((await getUserConfig()).hideContextMenu) return + await getPreferredLanguageKey().then((lang) => { changeLanguage(lang) }) - const menuId = 'ChatGPTBox-Menu' Browser.contextMenus.create({ id: menuId, title: 'ChatGPTBox', @@ -40,34 +73,6 @@ export function refreshMenu() { }) } - Browser.contextMenus.onClicked.addListener((info, tab) => { - Browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { - const currentTab = tabs[0] - const message = { - itemId: info.menuItemId.replace(menuId, ''), - selectionText: info.selectionText, - useMenuPosition: tab.id === currentTab.id, - } - console.debug('menu clicked', 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(true, tab) - } - - if (menuConfig[message.itemId].genPrompt) { - Browser.tabs.sendMessage(currentTab.id, { - type: 'CREATE_CHAT', - data: message, - }) - } - } - }) - }) + Browser.contextMenus.onClicked.addListener(onClickMenu) }) } diff --git a/src/config/index.mjs b/src/config/index.mjs index 18a71285..269721d2 100644 --- a/src/config/index.mjs +++ b/src/config/index.mjs @@ -217,6 +217,7 @@ export const defaultConfig = { customChatGptWebApiPath: '/backend-api/conversation', customOpenAiApiUrl: 'https://api.openai.com', disableWebModeHistory: true, + hideContextMenu: false, siteRegex: 'match nothing', useSiteRegexOnly: false, inputQuery: '', diff --git a/src/popup/Popup.jsx b/src/popup/Popup.jsx index 3d35b806..e4d78bf0 100644 --- a/src/popup/Popup.jsx +++ b/src/popup/Popup.jsx @@ -64,9 +64,9 @@ function Popup() { const [latestVersion, setLatestVersion] = useState('') const theme = useWindowTheme() - const updateConfig = (value) => { + const updateConfig = async (value) => { setConfig({ ...config, ...value }) - setUserConfig(value) + await setUserConfig(value) } useEffect(() => { diff --git a/src/popup/sections/AdvancedPart.jsx b/src/popup/sections/AdvancedPart.jsx index ad568c12..4535395e 100644 --- a/src/popup/sections/AdvancedPart.jsx +++ b/src/popup/sections/AdvancedPart.jsx @@ -2,6 +2,7 @@ import { useTranslation } from 'react-i18next' import { parseFloatWithClamp, parseIntWithClamp } from '../../utils/index.mjs' import PropTypes from 'prop-types' import { Tab, TabList, TabPanel, Tabs } from 'react-tabs' +import Browser from 'webextension-polyfill' ApiParams.propTypes = { config: PropTypes.object.isRequired, @@ -129,6 +130,20 @@ function Others({ config, updateConfig }) { 'Disable web mode history for better privacy protection, but it will result in unavailable conversations after a period of time', )} +