From 43fde4b709f25c47e576c8ae14e73f3fe13aac35 Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 12 Apr 2023 22:30:37 +0800 Subject: [PATCH] feat: add option to always pin the floating window (#199) --- src/_locales/en/main.json | 3 ++- src/_locales/zh-hans/main.json | 3 ++- src/_locales/zh-hant/main.json | 3 ++- src/components/FloatingToolbar/index.jsx | 12 ++++++++---- src/config/index.mjs | 1 + src/content-script/index.jsx | 4 +--- src/popup/Popup.jsx | 11 +++++++++++ 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 8097bdc..bf09062 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -99,5 +99,6 @@ "Open Conversation Window": "Open Conversation Window", "Store to Independent Conversation Page": "Store to Independent Conversation Page", "Keep Conversation Window in Background": "Keep conversation window in background, so that you can use shortcut keys to call it up in any program", - "Max Response Token Length": "Max Response Token Length" + "Max Response Token Length": "Max Response Token Length", + "Always pin the floating window": "Always pin the floating window" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index 7281966..da04ac6 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -99,5 +99,6 @@ "Open Conversation Window": "打开独立对话窗口", "Store to Independent Conversation Page": "收纳到独立对话页", "Keep Conversation Window in Background": "保持对话窗口在后台, 以便在任何程序中使用快捷键呼出", - "Max Response Token Length": "响应的最大token长度" + "Max Response Token Length": "响应的最大token长度", + "Always pin the floating window": "总是固定浮动窗口" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index 1dc39fc..6aea05f 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -99,5 +99,6 @@ "Open Conversation Window": "開啟獨立對話視窗", "Store to Independent Conversation Page": "收納到獨立對話頁", "Keep Conversation Window in Background": "保持對話窗口在後臺, 以便在任何程序中使用快捷鍵呼出", - "Max Response Token Length": "響應的最大token長度" + "Max Response Token Length": "響應的最大token長度", + "Always pin the floating window": "總是固定浮動視窗" } diff --git a/src/components/FloatingToolbar/index.jsx b/src/components/FloatingToolbar/index.jsx index 45d1541..cecc77f 100644 --- a/src/components/FloatingToolbar/index.jsx +++ b/src/components/FloatingToolbar/index.jsx @@ -61,6 +61,13 @@ function FloatingToolbar(props) { updatePosition() // avoid jitter } + const onDock = () => { + props.container.className = 'chatgptbox-toolbar-container-not-queryable' + setCloseable(true) + } + + if (config.alwaysPinWindow) onDock() + return (
{ - props.container.className = 'chatgptbox-toolbar-container-not-queryable' - setCloseable(true) - }} + onDock={onDock} onUpdate={() => { updatePosition() }} diff --git a/src/config/index.mjs b/src/config/index.mjs index adb172e..6953f8e 100644 --- a/src/config/index.mjs +++ b/src/config/index.mjs @@ -67,6 +67,7 @@ export const defaultConfig = { insertAtTop: isMobile(), lockWhenAnswer: false, autoRegenAfterSwitchModel: false, + alwaysPinWindow: false, apiKey: '', // openai ApiKey diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index dd62369..c20580c 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -268,6 +268,7 @@ async function prepareForRightClickMenu() { } async function prepareForStaticCard() { + const userConfig = await getUserConfig() let siteRegex if (userConfig.useSiteRegexOnly) siteRegex = userConfig.siteRegex else @@ -296,10 +297,7 @@ async function prepareForStaticCard() { } } -let userConfig - async function run() { - userConfig = await getUserConfig() await getPreferredLanguageKey().then((lang) => { changeLanguage(lang) }) diff --git a/src/popup/Popup.jsx b/src/popup/Popup.jsx index 170fbb5..d96d7c6 100644 --- a/src/popup/Popup.jsx +++ b/src/popup/Popup.jsx @@ -297,6 +297,17 @@ function GeneralPart({ config, updateConfig }) { /> {t('Regenerate the answer after switching model')} +
)