diff --git a/src/_locales/de/main.json b/src/_locales/de/main.json index 800d662..e0a3aa1 100644 --- a/src/_locales/de/main.json +++ b/src/_locales/de/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "Tastenkombinationen", "Open Conversation Page": "Konversationsseite öffnen", "Open Conversation Window": "Konversationsfenster öffnen", - "Store to Independent Conversation Page": "Auf unabhängiger Konversationsseite speichern" + "Store to Independent Conversation Page": "Auf unabhängiger Konversationsseite speichern", + "Close All Chats In This Page": "Schließe alle Chats auf dieser Seite" } diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 817f127..51698a3 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -114,5 +114,6 @@ "Others": "Others", "API Modes": "API Modes", "Disable web mode history for better privacy protection, but it will result in unavailable conversations after a period of time": "Disable web mode history for better privacy protection, but it will result in unavailable conversations after a period of time", - "Display selection tools next to input box to avoid blocking": "Display selection tools next to input box to avoid blocking" + "Display selection tools next to input box to avoid blocking": "Display selection tools next to input box to avoid blocking", + "Close All Chats In This Page": "Close All Chats In This Page" } diff --git a/src/_locales/es/main.json b/src/_locales/es/main.json index 6192b55..17bc828 100644 --- a/src/_locales/es/main.json +++ b/src/_locales/es/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "Atajos de teclado", "Open Conversation Page": "Abrir página de conversación independiente", "Open Conversation Window": "Abrir la ventana de conversación independiente", - "Store to Independent Conversation Page": "Guardar en página de conversación independiente" + "Store to Independent Conversation Page": "Guardar en página de conversación independiente", + "Close All Chats In This Page": "Cerrar todos los chats en esta página" } diff --git a/src/_locales/fr/main.json b/src/_locales/fr/main.json index 76c8933..206c171 100644 --- a/src/_locales/fr/main.json +++ b/src/_locales/fr/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "Raccourcis clavier", "Open Conversation Page": "Ouvrir la page de conversation", "Open Conversation Window": "Ouvrir la fenêtre de conversation", - "Store to Independent Conversation Page": "Enregistrer sur une page de conversation indépendante" + "Store to Independent Conversation Page": "Enregistrer sur une page de conversation indépendante", + "Close All Chats In This Page": "Fermez tous les chats sur cette page" } diff --git a/src/_locales/in/main.json b/src/_locales/in/main.json index 3892afd..76aaa32 100644 --- a/src/_locales/in/main.json +++ b/src/_locales/in/main.json @@ -111,5 +111,6 @@ "API Params": "Parameter API", "API Url": "URL API", "Others": "Lain-lain", - "API Modes": "Mode API" + "API Modes": "Mode API", + "Close All Chats In This Page": "Tutup Semua Obrolan di Halaman Ini" } diff --git a/src/_locales/it/main.json b/src/_locales/it/main.json index c20cc7c..4ef0a83 100644 --- a/src/_locales/it/main.json +++ b/src/_locales/it/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "Scorciatoie da tastiera", "Open Conversation Page": "Apri la pagina della conversazione", "Open Conversation Window": "Apri la finestra di conversazione", - "Store to Independent Conversation Page": "Salva alla pagina della conversazione indipendente" + "Store to Independent Conversation Page": "Salva alla pagina della conversazione indipendente", + "Close All Chats In This Page": "Chiudi tutte le chat in questa pagina." } diff --git a/src/_locales/ja/main.json b/src/_locales/ja/main.json index 98b3422..c319044 100644 --- a/src/_locales/ja/main.json +++ b/src/_locales/ja/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "キーボードショートカット", "Open Conversation Page": "会話ページを開く", "Open Conversation Window": "会話ウィンドウを開く", - "Store to Independent Conversation Page": "独立した会話ページに保存" + "Store to Independent Conversation Page": "独立した会話ページに保存", + "Close All Chats In This Page": "このページのすべてのチャットを閉じる" } diff --git a/src/_locales/ko/main.json b/src/_locales/ko/main.json index e657849..3e6ff7b 100644 --- a/src/_locales/ko/main.json +++ b/src/_locales/ko/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "키보드 단축키 설정", "Open Conversation Page": "대화 페이지 열기", "Open Conversation Window": "대화 창 열기", - "Store to Independent Conversation Page": "독립적인 대화 페이지에 저장" + "Store to Independent Conversation Page": "독립적인 대화 페이지에 저장", + "Close All Chats In This Page": "이 페이지의 모든 채팅 종료하기" } diff --git a/src/_locales/pt/main.json b/src/_locales/pt/main.json index 4966491..a95fae8 100644 --- a/src/_locales/pt/main.json +++ b/src/_locales/pt/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "Atalhos de Teclado", "Open Conversation Page": "Abrir Página de Conversa", "Open Conversation Window": "Abrir Janela de Conversa", - "Store to Independent Conversation Page": "Armazenar em Página de Conversa Independente" + "Store to Independent Conversation Page": "Armazenar em Página de Conversa Independente", + "Close All Chats In This Page": "Закрыть все чаты на этой странице" } diff --git a/src/_locales/ru/main.json b/src/_locales/ru/main.json index 3dc7353..3dae087 100644 --- a/src/_locales/ru/main.json +++ b/src/_locales/ru/main.json @@ -97,5 +97,6 @@ "Keyboard Shortcuts": "Горячие клавиши", "Open Conversation Page": "Открыть страницу бесед", "Open Conversation Window": "Открыть окно бесед", - "Store to Independent Conversation Page": "Хранить на странице независимых разговоров" + "Store to Independent Conversation Page": "Хранить на странице независимых разговоров", + "Close All Chats In This Page": "Close All Chats In This Page" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index b256654..bb9694b 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -114,5 +114,6 @@ "Others": "其他", "API Modes": "API模式", "Disable web mode history for better privacy protection, but it will result in unavailable conversations after a period of time": "禁用网页版模式历史记录以获得更好的隐私保护, 但会导致对话在一段时间后不可用", - "Display selection tools next to input box to avoid blocking": "将选择浮动工具显示在输入框旁边以避免遮挡" + "Display selection tools next to input box to avoid blocking": "将选择浮动工具显示在输入框旁边以避免遮挡", + "Close All Chats In This Page": "关闭本页所有聊天" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index cf571cb..db9b2fa 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -114,5 +114,6 @@ "Others": "其他", "API Modes": "API 模式", "Disable web mode history for better privacy protection, but it will result in unavailable conversations after a period of time": "停用網頁版模式歷史記錄以提升隱私保護,但會導致對話記錄在一段時間後無法使用", - "Display selection tools next to input box to avoid blocking": "將選擇浮動工具顯示在輸入框旁邊以避免遮擋" + "Display selection tools next to input box to avoid blocking": "將選擇浮動工具顯示在輸入框旁邊以避免遮擋", + "Close All Chats In This Page": "關閉本頁所有對話" } diff --git a/src/components/ConversationCard/index.jsx b/src/components/ConversationCard/index.jsx index e2b4cad..12622ee 100644 --- a/src/components/ConversationCard/index.jsx +++ b/src/components/ConversationCard/index.jsx @@ -68,14 +68,6 @@ function ConversationCard(props) { ) const config = useConfig() - document.addEventListener('keydown', function (event) { - if (event.key === 'Escape' || event.keyCode === 27) { - // 关闭窗口代码 - port.disconnect() - if (props.onClose) props.onClose() - } - }) - useEffect(() => { if (props.onUpdate) props.onUpdate(port, session, conversationItemData) }, [session, conversationItemData]) @@ -118,13 +110,23 @@ function ConversationCard(props) { } useEffect(() => { - const listener = () => { + const portListener = () => { setPort(Browser.runtime.connect()) setIsReady(true) } - port.onDisconnect.addListener(listener) + + const closeChatsListener = (message) => { + if (message.type === 'CLOSE_CHATS') { + port.disconnect() + if (props.onClose) props.onClose() + } + } + + if (props.closeable) Browser.runtime.onMessage.addListener(closeChatsListener) + port.onDisconnect.addListener(portListener) return () => { - port.onDisconnect.removeListener(listener) + if (props.closeable) Browser.runtime.onMessage.removeListener(closeChatsListener) + port.onDisconnect.removeListener(portListener) } }, [port]) useEffect(() => { diff --git a/src/content-script/menu-tools/index.mjs b/src/content-script/menu-tools/index.mjs index 4bd9be0..18b994a 100644 --- a/src/content-script/menu-tools/index.mjs +++ b/src/content-script/menu-tools/index.mjs @@ -39,4 +39,15 @@ export const config = { }) }, }, + closeAllChats: { + label: 'Close All Chats In This Page', + action: async () => { + Browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { + Browser.tabs.sendMessage(tabs[0].id, { + type: 'CLOSE_CHATS', + data: {}, + }) + }) + }, + }, } diff --git a/src/manifest.json b/src/manifest.json index b813ba2..686632d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -85,6 +85,9 @@ }, "openConversationWindow": { "description": "Open the independent conversation window" + }, + "closeAllChats": { + "description": "Close all chats in this page" } } } \ No newline at end of file diff --git a/src/manifest.v2.json b/src/manifest.v2.json index c56824e..6d331e6 100644 --- a/src/manifest.v2.json +++ b/src/manifest.v2.json @@ -79,6 +79,9 @@ }, "openConversationWindow": { "description": "Open the independent conversation window" + }, + "closeAllChats": { + "description": "Close all chats in this page" } } } \ No newline at end of file