-
Notifications
You must be signed in to change notification settings - Fork 854
Expand file tree
/
Copy pathPopup.jsx
More file actions
125 lines (115 loc) · 3.88 KB
/
Popup.jsx
File metadata and controls
125 lines (115 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import '@picocss/pico'
import { useEffect, useState } from 'react'
import {
defaultConfig,
getPreferredLanguageKey,
getUserConfig,
setUserConfig,
} from '../config/index.mjs'
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs'
import 'react-tabs/style/react-tabs.css'
import './styles.scss'
import { MarkGithubIcon } from '@primer/octicons-react'
import Browser from 'webextension-polyfill'
import { useWindowTheme } from '../hooks/use-window-theme.mjs'
import { isMobile } from '../utils/index.mjs'
import { useTranslation } from 'react-i18next'
import { GeneralPart } from './sections/GeneralPart'
import { FeaturePages } from './sections/FeaturePages'
import { AdvancedPart } from './sections/AdvancedPart'
import { ModulesPart } from './sections/ModulesPart'
// eslint-disable-next-line react/prop-types
function Footer({ currentVersion, latestVersion }) {
const { t } = useTranslation()
return (
<div className="footer">
<div>
{`${t('Current Version')}: ${currentVersion} `}
{currentVersion === latestVersion ? (
`(${t('Latest')})`
) : (
<>
({`${t('Latest')}: `}
<a
href={'https://github.com/josStorer/chatGPTBox/releases/tag/v' + latestVersion}
target="_blank"
rel="nofollow noopener noreferrer"
>
{latestVersion}
</a>
)
</>
)}
</div>
<div>
<a
href="https://github.com/josStorer/chatGPTBox"
target="_blank"
rel="nofollow noopener noreferrer"
>
<span>{t('Help | Changelog ')}</span>
<MarkGithubIcon />
</a>
</div>
</div>
)
}
function Popup() {
const { t, i18n } = useTranslation()
const [config, setConfig] = useState(defaultConfig)
const [currentVersion, setCurrentVersion] = useState('')
const [latestVersion, setLatestVersion] = useState('')
const theme = useWindowTheme()
const updateConfig = (value) => {
setConfig({ ...config, ...value })
setUserConfig(value)
}
useEffect(() => {
getPreferredLanguageKey().then((lang) => {
i18n.changeLanguage(lang)
})
getUserConfig().then((config) => {
setConfig(config)
setCurrentVersion(Browser.runtime.getManifest().version.replace('v', ''))
fetch('https://api.github.com/repos/josstorer/chatGPTBox/releases/latest').then((response) =>
response.json().then((data) => {
setLatestVersion(data.tag_name.replace('v', ''))
}),
)
})
}, [])
useEffect(() => {
document.documentElement.dataset.theme = config.themeMode === 'auto' ? theme : config.themeMode
}, [config.themeMode, theme])
const search = new URLSearchParams(window.location.search)
const popup = !isMobile() && search.get('popup') // manifest v2
return (
<div className={popup === 'true' ? 'container-popup-mode' : 'container-page-mode'}>
<form style="width:100%;">
<Tabs selectedTabClassName="popup-tab--selected">
<TabList>
<Tab className="popup-tab">{t('General')}</Tab>
<Tab className="popup-tab">{t('Modules')}</Tab>
<Tab className="popup-tab">{t('Advanced')}</Tab>
<Tab className="popup-tab">{t('Feature Pages')}</Tab>
</TabList>
<TabPanel>
<GeneralPart config={config} updateConfig={updateConfig} />
</TabPanel>
<TabPanel>
<FeaturePages config={config} updateConfig={updateConfig} />
</TabPanel>
<TabPanel>
<ModulesPart config={config} updateConfig={updateConfig} />
</TabPanel>
<TabPanel>
<AdvancedPart config={config} updateConfig={updateConfig} />
</TabPanel>
</Tabs>
</form>
<br />
<Footer currentVersion={currentVersion} latestVersion={latestVersion} />
</div>
)
}
export default Popup