Skip to content

Commit 9517772

Browse files
committed
feat: lockWhenAnswer config (#5)
1 parent fd7388d commit 9517772

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src/components/ConversationCard/index.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import FileSaver from 'file-saver'
1010
import { render } from 'preact'
1111
import FloatingToolbar from '../FloatingToolbar'
1212
import { useClampWindowSize } from '../../hooks/use-clamp-window-size'
13+
import { defaultConfig, getUserConfig } from '../../config'
1314

1415
const logo = Browser.runtime.getURL('logo.png')
1516

@@ -63,6 +64,11 @@ function ConversationCard(props) {
6364
}
6465
})(),
6566
)
67+
const [config, setConfig] = useState(defaultConfig)
68+
69+
useEffect(() => {
70+
getUserConfig().then(setConfig)
71+
}, [])
6672

6773
useEffect(() => {
6874
if (props.onUpdate) props.onUpdate()
@@ -72,6 +78,10 @@ function ConversationCard(props) {
7278
bodyRef.current.scrollTop = bodyRef.current.scrollHeight
7379
}, [session])
7480

81+
useEffect(() => {
82+
if (config.lockWhenAnswer) bodyRef.current.scrollTop = bodyRef.current.scrollHeight
83+
}, [conversationItemData])
84+
7585
useEffect(() => {
7686
// when the page is responsive, session may accumulate redundant data and needs to be cleared after remounting and before making a new request
7787
if (props.question) {

src/config.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,43 @@ export const maxResponseTokenLength = 1000
4242
* @typedef {typeof defaultConfig} UserConfig
4343
*/
4444
export const defaultConfig = {
45+
// general
46+
4547
/** @type {keyof TriggerMode}*/
4648
triggerMode: 'manually',
4749
/** @type {keyof ThemeMode}*/
4850
themeMode: 'auto',
4951
/** @type {keyof Models}*/
5052
modelName: 'chatgptFree',
5153
apiKey: '',
54+
preferredLanguage: navigator.language.substring(0, 2),
5255
insertAtTop: isMobile(),
56+
lockWhenAnswer: false,
57+
58+
// advanced
59+
60+
customChatGptWebApiUrl: 'https://chat.openai.com',
61+
customChatGptWebApiPath: '/backend-api/conversation',
62+
customOpenAiApiUrl: 'https://api.openai.com',
5363
siteRegex: 'match nothing',
5464
userSiteRegexOnly: false,
5565
inputQuery: '',
5666
appendQuery: '',
5767
prependQuery: '',
68+
69+
// others
70+
71+
activeSelectionTools: Object.keys(toolsConfig),
72+
activeSiteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'],
5873
accessToken: '',
5974
tokenSavedOn: 0,
60-
preferredLanguage: navigator.language.substring(0, 2),
61-
userLanguage: navigator.language.substring(0, 2), // unchangeable
62-
customChatGptWebApiUrl: 'https://chat.openai.com',
63-
customChatGptWebApiPath: '/backend-api/conversation',
64-
customOpenAiApiUrl: 'https://api.openai.com',
75+
76+
// unchangeable
77+
78+
userLanguage: navigator.language.substring(0, 2),
6579
selectionTools: Object.keys(toolsConfig),
66-
activeSelectionTools: Object.keys(toolsConfig),
6780
// importing configuration will result in gpt-3-encoder being packaged into the output file
6881
siteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'],
69-
activeSiteAdapters: ['bilibili', 'github', 'gitlab', 'quora', 'reddit', 'youtube', 'zhihu'],
7082
}
7183

7284
export async function getUserLanguage() {

src/popup/Popup.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ function GeneralPart({ config, updateConfig }) {
152152
/>
153153
Insert chatGPT at the top of search results
154154
</label>
155+
<label>
156+
<input
157+
type="checkbox"
158+
checked={config.lockWhenAnswer}
159+
onChange={(e) => {
160+
const checked = e.target.checked
161+
updateConfig({ lockWhenAnswer: checked })
162+
}}
163+
/>
164+
Lock Scrollbar while Answering
165+
</label>
166+
<br />
155167
</>
156168
)
157169
}

0 commit comments

Comments
 (0)