Skip to content

Commit e95372d

Browse files
committed
feat: improve web mode notification (#309)
1 parent b487c03 commit e95372d

File tree

12 files changed

+106
-48
lines changed

12 files changed

+106
-48
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"react-i18next": "^12.2.0",
4444
"react-markdown": "^8.0.7",
4545
"react-tabs": "^4.2.1",
46+
"react-toastify": "^9.1.2",
4647
"rehype-highlight": "^6.0.0",
4748
"rehype-katex": "^6.0.2",
4849
"rehype-raw": "^6.1.1",

src/_locales/en/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"Always Create New Conversation Window": "Always Create New Conversation Window",
108108
"Please keep this tab open. You can now use the web mode of ChatGPTBox": "Please keep this tab open. You can now use the web mode of ChatGPTBox",
109109
"Go Back": "Go Back",
110+
"Pin Tab": "Pin Tab",
110111
"Modules": "Modules",
111112
"API Params": "API Params",
112113
"API Url": "API Url",

src/_locales/zh-hans/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"Always Create New Conversation Window": "总是创建新的对话窗口",
108108
"Please keep this tab open. You can now use the web mode of ChatGPTBox": "请保持这个页面打开, 现在你可以使用ChatGPTBox的网页版模式",
109109
"Go Back": "返回",
110+
"Pin Tab": "固定页面",
110111
"Modules": "模块",
111112
"API Params": "API参数",
112113
"API Url": "API地址",

src/_locales/zh-hant/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"Always Create New Conversation Window": "總是建立新的對話視窗",
108108
"Please keep this tab open. You can now use the web mode of ChatGPTBox": "請保持這個頁面開啟, 現在妳可以使用ChatGPTBox的網頁版模式",
109109
"Go Back": "返回",
110+
"Pin Tab": "固定頁面",
110111
"Modules": "模組",
111112
"API Params": "API參數",
112113
"API Url": "API網址",

src/background/index.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ Browser.runtime.onMessage.addListener(async (message, sender) => {
143143
}
144144
break
145145
}
146+
case 'SET_CHATGPT_TAB': {
147+
await setUserConfig({
148+
chatgptTabId: sender.tab.id,
149+
})
150+
break
151+
}
146152
case 'ACTIVATE_URL':
147153
await Browser.tabs.update(message.data.tabId, { active: true })
148154
break

src/components/MarkdownRender/Hyperlink.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function Hyperlink({ href, children }) {
1616
type: 'NEW_URL',
1717
data: {
1818
url: href,
19-
pinned: true,
19+
pinned: false,
2020
saveAsChatgptConfig: true,
2121
},
2222
})

src/components/NotificationForChatGPTWeb/index.jsx

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,84 @@
11
import { useTranslation } from 'react-i18next'
22
import PropTypes from 'prop-types'
33
import Browser from 'webextension-polyfill'
4-
import { useConfig } from '../../hooks/use-config.mjs'
4+
import { toast, ToastContainer } from 'react-toastify'
5+
import { useEffect } from 'react'
6+
import 'react-toastify/dist/ReactToastify.css'
7+
import { useTheme } from '../../hooks/use-theme.mjs'
58

6-
const NotificationForChatGPTWeb = (props) => {
9+
const NotificationForChatGPTWeb = () => {
710
const { t } = useTranslation()
8-
const config = useConfig()
11+
const [theme, config] = useTheme()
12+
913
const buttonStyle = {
1014
padding: '0 8px',
1115
border: '1px solid',
1216
borderRadius: '4px',
17+
whiteSpace: 'nowrap',
1318
cursor: 'pointer',
1419
}
1520

16-
return (
17-
<div className="chatgptbox-notification">
18-
<div>{t('Please keep this tab open. You can now use the web mode of ChatGPTBox')}</div>
19-
<button
20-
style={buttonStyle}
21-
onClick={() => {
22-
Browser.runtime.sendMessage({
23-
type: 'ACTIVATE_URL',
24-
data: {
25-
tabId: config.chatgptJumpBackTabId,
26-
},
27-
})
28-
}}
29-
>
30-
{t('Go Back')}
31-
</button>
32-
<button
33-
style={buttonStyle}
34-
onClick={() => {
35-
props.container.remove()
21+
useEffect(() => {
22+
toast(
23+
<div
24+
style={{
25+
display: 'flex',
26+
flexDirection: 'row',
27+
alignItems: 'center',
28+
gap: '4px',
3629
}}
3730
>
38-
X
39-
</button>
40-
</div>
31+
<div>{t('Please keep this tab open. You can now use the web mode of ChatGPTBox')}</div>
32+
<div style={{ display: 'flex', flexDirection: 'column', gap: '4px' }}>
33+
<button
34+
style={buttonStyle}
35+
onClick={() => {
36+
Browser.runtime.sendMessage({
37+
type: 'PIN_TAB',
38+
data: {
39+
saveAsChatgptConfig: true,
40+
},
41+
})
42+
}}
43+
>
44+
{t('Pin Tab')}
45+
</button>
46+
<button
47+
style={buttonStyle}
48+
onClick={() => {
49+
Browser.runtime.sendMessage({
50+
type: 'ACTIVATE_URL',
51+
data: {
52+
tabId: config.chatgptJumpBackTabId,
53+
},
54+
})
55+
}}
56+
>
57+
{t('Go Back')}
58+
</button>
59+
</div>
60+
</div>,
61+
{
62+
toastId: 0,
63+
updateId: 0,
64+
},
65+
)
66+
}, [config.themeMode, config.preferredLanguage])
67+
68+
return (
69+
<ToastContainer
70+
style={{
71+
width: '440px',
72+
}}
73+
position="top-right"
74+
autoClose={7000}
75+
newestOnTop={false}
76+
closeOnClick={false}
77+
rtl={false}
78+
pauseOnFocusLoss={true}
79+
draggable={false}
80+
theme={theme}
81+
/>
4182
)
4283
}
4384

src/content-script/index.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async function overwriteAccessToken() {
302302
}
303303

304304
async function prepareForForegroundRequests() {
305-
if (location.hostname !== 'chat.openai.com') return
305+
if (location.hostname !== 'chat.openai.com' || location.pathname === '/auth/login') return
306306

307307
const userConfig = await getUserConfig()
308308

@@ -313,10 +313,8 @@ async function prepareForForegroundRequests() {
313313
render(<NotificationForChatGPTWeb container={div} />, div)
314314

315315
await Browser.runtime.sendMessage({
316-
type: 'PIN_TAB',
317-
data: {
318-
saveAsChatgptConfig: true,
319-
},
316+
type: 'SET_CHATGPT_TAB',
317+
data: {},
320318
})
321319

322320
registerPortListener(async (session, port) => {

src/content-script/styles.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,3 @@
315315
background-color: var(--theme-color);
316316
box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.2);
317317
}
318-
319-
.chatgptbox-notification {
320-
display: flex;
321-
flex-direction: row;
322-
align-items: center;
323-
gap: 6px;
324-
position: fixed;
325-
top: 25px;
326-
right: 25px;
327-
z-index: 2147483647;
328-
padding: 4px 10px;
329-
border: 1px solid;
330-
border-radius: 4px;
331-
}

0 commit comments

Comments
 (0)