Skip to content

Commit

Permalink
allow hiding context menu (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Mar 23, 2024
1 parent 1ec752c commit 381cea3
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 46 deletions.
3 changes: 2 additions & 1 deletion src/_locales/de/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/en/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/es/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/fr/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/in/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/it/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/ja/main.json
Expand Up @@ -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": "この拡張機能のコンテキストメニューを非表示"
}
3 changes: 2 additions & 1 deletion src/_locales/ko/main.json
Expand Up @@ -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": "이 확장 프로그램의 컨텍스트 메뉴 숨기기"
}
3 changes: 2 additions & 1 deletion src/_locales/pt/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/ru/main.json
Expand Up @@ -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": "Скрыть контекстное меню этого расширения"
}
3 changes: 2 additions & 1 deletion src/_locales/tr/main.json
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/_locales/zh-hans/main.json
Expand Up @@ -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": "隐藏此扩展的右键菜单"
}
3 changes: 2 additions & 1 deletion src/_locales/zh-hant/main.json
Expand Up @@ -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": "隱藏此擴充功能的右鍵選單"
}
67 changes: 36 additions & 31 deletions 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',
Expand Down Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions src/config/index.mjs
Expand Up @@ -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: '',
Expand Down
4 changes: 2 additions & 2 deletions src/popup/Popup.jsx
Expand Up @@ -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(() => {
Expand Down
15 changes: 15 additions & 0 deletions src/popup/sections/AdvancedPart.jsx
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
)}
</label>
<label>
<input
type="checkbox"
checked={config.hideContextMenu}
onChange={async (e) => {
const checked = e.target.checked
await updateConfig({ hideContextMenu: checked })
Browser.runtime.sendMessage({
type: 'REFRESH_MENU',
})
}}
/>
{t('Hide context menu of this extension')}
</label>
<br />
<label>
{t('Custom Site Regex')}
Expand Down

0 comments on commit 381cea3

Please sign in to comment.