diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 496ecbc..39cd9a1 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -82,5 +82,7 @@ "Model Name": "Model Name", "Custom Model API Url": "Custom Model API Url", "Loading...": "Loading...", - "Feedback": "Feedback" + "Feedback": "Feedback", + "Confirm": "Confirm", + "Clear Conversation": "Clear Conversation" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index a212879..b82acb0 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -82,5 +82,7 @@ "Model Name": "模型名", "Custom Model API Url": "自定义模型的API地址", "Loading...": "正在读取...", - "Feedback": "反馈" + "Feedback": "反馈", + "Confirm": "确认", + "Clear Conversation": "清理对话" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index 1a111f8..49aea85 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -82,5 +82,7 @@ "Model Name": "模型名", "Custom Model API Url": "自定義模型的API地址", "Loading...": "正在讀取...", - "Feedback": "反饋" + "Feedback": "反饋", + "Confirm": "確認", + "Clear Conversation": "清理對話" } diff --git a/src/background/apis/chatgpt-web.mjs b/src/background/apis/chatgpt-web.mjs index 7225a0e..8dd8631 100644 --- a/src/background/apis/chatgpt-web.mjs +++ b/src/background/apis/chatgpt-web.mjs @@ -27,6 +27,10 @@ export async function setConversationProperty(token, conversationId, propertyObj await request(token, 'PATCH', `/conversation/${conversationId}`, propertyObject) } +export async function deleteConversation(token, conversationId) { + if (conversationId) await setConversationProperty(token, conversationId, { is_visible: false }) +} + export async function sendModerations(token, question, conversationId, messageId) { await request(token, 'POST', `/moderations`, { conversation_id: conversationId, @@ -48,10 +52,6 @@ export async function getModels(token) { * @param {string} accessToken */ export async function generateAnswersWithChatgptWebApi(port, question, session, accessToken) { - const deleteConversation = () => { - setConversationProperty(accessToken, session.conversationId, { is_visible: false }) - } - const controller = new AbortController() const stopListener = (msg) => { if (msg.stop) { @@ -65,7 +65,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session, port.onDisconnect.addListener(() => { console.debug('port disconnected') controller.abort() - deleteConversation() + deleteConversation(accessToken, session.conversationId) }) const models = await getModels(accessToken).catch(() => { diff --git a/src/background/index.mjs b/src/background/index.mjs index e3812df..f7e0418 100644 --- a/src/background/index.mjs +++ b/src/background/index.mjs @@ -1,6 +1,10 @@ import Browser from 'webextension-polyfill' import ExpiryMap from 'expiry-map' -import { generateAnswersWithChatgptWebApi, sendMessageFeedback } from './apis/chatgpt-web' +import { + deleteConversation, + generateAnswersWithChatgptWebApi, + sendMessageFeedback, +} from './apis/chatgpt-web' import { generateAnswersWithBingWebApi } from './apis/bing-web.mjs' import { generateAnswersWithChatgptApi, @@ -126,6 +130,10 @@ Browser.runtime.onMessage.addListener(async (message) => { if (message.type === 'FEEDBACK') { const token = await getChatGptAccessToken() await sendMessageFeedback(token, message.data) + } else if (message.type === 'DELETE_CONVERSATION') { + const token = await getChatGptAccessToken() + const data = message.data + await deleteConversation(token, data.conversationId) } }) diff --git a/src/components/ConversationCard/index.jsx b/src/components/ConversationCard/index.jsx index c5c71f8..566678a 100644 --- a/src/components/ConversationCard/index.jsx +++ b/src/components/ConversationCard/index.jsx @@ -12,6 +12,7 @@ import FloatingToolbar from '../FloatingToolbar' import { useClampWindowSize } from '../../hooks/use-clamp-window-size' import { defaultConfig, getUserConfig } from '../../config/index.mjs' import { useTranslation } from 'react-i18next' +import DeleteButton from '../DeleteButton' const logo = Browser.runtime.getURL('logo.png') @@ -221,22 +222,37 @@ function ConversationCard(props) { }} /> )} - { - let output = '' - session.conversationRecords.forEach((data) => { - output += `${t('Question')}:\n\n${data.question}\n\n${t('Answer')}:\n\n${ - data.answer - }\n\n
\n\n` - }) - const blob = new Blob([output], { type: 'text/plain;charset=utf-8' }) - FileSaver.saveAs(blob, 'conversation.md') - }} - > - + + { + port.postMessage({ stop: true }) + Browser.runtime.sendMessage({ + type: 'DELETE_CONVERSATION', + data: { + conversationId: session.conversationId, + }, + }) + setConversationItemData([]) + setSession(initSession()) + }} + /> + { + let output = '' + session.conversationRecords.forEach((data) => { + output += `${t('Question')}:\n\n${data.question}\n\n${t('Answer')}:\n\n${ + data.answer + }\n\n
\n\n` + }) + const blob = new Blob([output], { type: 'text/plain;charset=utf-8' }) + FileSaver.saveAs(blob, 'conversation.md') + }} + > + +

diff --git a/src/components/ConversationItem/index.jsx b/src/components/ConversationItem/index.jsx index d5011ee..fbb9d00 100644 --- a/src/components/ConversationItem/index.jsx +++ b/src/components/ConversationItem/index.jsx @@ -16,7 +16,7 @@ export function ConversationItem({ type, content, session, done, port }) {

{t('You')}:

-
+
content} size={14} /> {!collapsed ? ( {session && session.aiName ? `${t(session.aiName)}:` : t('Loading...')}

-
+
{!done && ( + { + setWaitConfirm(true) + }} + > + + + + ) +} + +export default DeleteButton diff --git a/src/content-script/styles.scss b/src/content-script/styles.scss index 6b036d5..2e7aaf8 100644 --- a/src/content-script/styles.scss +++ b/src/content-script/styles.scss @@ -169,6 +169,12 @@ color: #f08080; } + .gpt-util-group { + display: flex; + gap: 15px; + align-items: center; + } + .gpt-util-icon { display: flex; cursor: pointer;