Skip to content

Commit ae28ca6

Browse files
committed
feat: enabled API Modes option (#264)
1 parent 4ba1a8d commit ae28ca6

File tree

9 files changed

+66
-5
lines changed

9 files changed

+66
-5
lines changed

src/_locales/en/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@
110110
"Modules": "Modules",
111111
"API Params": "API Params",
112112
"API Url": "API Url",
113-
"Others": "Others"
113+
"Others": "Others",
114+
"API Modes": "API Modes"
114115
}

src/_locales/zh-hans/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@
110110
"Modules": "模块",
111111
"API Params": "API参数",
112112
"API Url": "API地址",
113-
"Others": "其他"
113+
"Others": "其他",
114+
"API Modes": "API模式"
114115
}

src/_locales/zh-hant/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@
110110
"Modules": "模組",
111111
"API Params": "API參數",
112112
"API Url": "API網址",
113-
"Others": "其他"
113+
"Others": "其他",
114+
"API Modes": "API模式"
114115
}

src/components/ConversationCard/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ function ConversationCard(props) {
233233
else setSession(newSession)
234234
}}
235235
>
236-
{Object.entries(Models).map(([key, model]) => {
236+
{config.activeApiModes.map((key) => {
237+
const model = Models[key]
237238
return (
238239
<option value={key} key={key} selected={key === session.modelName}>
239240
{t(model.desc)}

src/config/index.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ export const defaultConfig = {
118118
// others
119119

120120
alwaysCreateNewConversationWindow: false,
121+
activeApiModes: [
122+
'chatgptFree35',
123+
'chatgptPlus4',
124+
'chatgptApi35',
125+
'bingFree4',
126+
'bingFreeSydney',
127+
'poeAiWebSage',
128+
'poeAiWebGPT4',
129+
'poeAiWebClaudePlus',
130+
'chatgptApi4_8k',
131+
'customModel',
132+
'azureOpenAi',
133+
'poeAiWebCustom',
134+
],
121135
activeSelectionTools: ['translate', 'summary', 'polish', 'code', 'ask'],
122136
activeSiteAdapters: [
123137
'bilibili',
@@ -139,6 +153,7 @@ export const defaultConfig = {
139153
// unchangeable
140154

141155
userLanguage: getNavigatorLanguage(),
156+
apiModes: Object.keys(Models),
142157
selectionTools: [
143158
'translate',
144159
'translateToEn',

src/content-script/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ async function overwriteAccessToken() {
304304
async function prepareForForegroundRequests() {
305305
if (location.hostname !== 'chat.openai.com') return
306306

307+
const userConfig = await getUserConfig()
308+
309+
if (!chatgptWebModelKeys.some((model) => userConfig.activeApiModes.includes(model))) return
310+
307311
const div = document.createElement('div')
308312
document.body.append(div)
309313
render(<NotificationForChatGPTWeb container={div} />, div)

src/popup/sections/ApiModes.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useTranslation } from 'react-i18next'
2+
import PropTypes from 'prop-types'
3+
import { Models } from '../../config/index.mjs'
4+
5+
ApiModes.propTypes = {
6+
config: PropTypes.object.isRequired,
7+
updateConfig: PropTypes.func.isRequired,
8+
}
9+
10+
export function ApiModes({ config, updateConfig }) {
11+
const { t } = useTranslation()
12+
13+
return (
14+
<>
15+
{config.apiModes.map((key) => (
16+
<label key={key}>
17+
<input
18+
type="checkbox"
19+
checked={config.activeApiModes.includes(key)}
20+
onChange={(e) => {
21+
const checked = e.target.checked
22+
const activeApiModes = config.activeApiModes.filter((i) => i !== key)
23+
if (checked) activeApiModes.push(key)
24+
updateConfig({ activeApiModes })
25+
}}
26+
/>
27+
{t(Models[key].desc)}
28+
</label>
29+
))}
30+
</>
31+
)
32+
}

src/popup/sections/GeneralPart.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function GeneralPart({ config, updateConfig }) {
9494
updateConfig({ modelName: modelName })
9595
}}
9696
>
97-
{Object.entries(Models).map(([key, model]) => {
97+
{config.activeApiModes.map((key) => {
98+
const model = Models[key]
9899
return (
99100
<option value={key} key={key} selected={key === config.modelName}>
100101
{t(model.desc)}

src/popup/sections/ModulesPart.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useTranslation } from 'react-i18next'
22
import PropTypes from 'prop-types'
33
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs'
4+
import { ApiModes } from './ApiModes'
45
import { SelectionTools } from './SelectionTools'
56
import { SiteAdapters } from './SiteAdapters'
67

@@ -16,10 +17,14 @@ export function ModulesPart({ config, updateConfig }) {
1617
<>
1718
<Tabs selectedTabClassName="popup-tab--selected">
1819
<TabList>
20+
<Tab className="popup-tab">{t('API Modes')}</Tab>
1921
<Tab className="popup-tab">{t('Selection Tools')}</Tab>
2022
<Tab className="popup-tab">{t('Sites')}</Tab>
2123
</TabList>
2224

25+
<TabPanel>
26+
<ApiModes config={config} updateConfig={updateConfig} />
27+
</TabPanel>
2328
<TabPanel>
2429
<SelectionTools config={config} updateConfig={updateConfig} />
2530
</TabPanel>

0 commit comments

Comments
 (0)