mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +08:00
feat: integrate custom CSS support in SelectionAssistant
This commit is contained in:
parent
431e2aaa13
commit
b24de23219
@ -15,7 +15,7 @@ import ActionGeneral from './components/ActionGeneral'
|
|||||||
import ActionTranslate from './components/ActionTranslate'
|
import ActionTranslate from './components/ActionTranslate'
|
||||||
|
|
||||||
const SelectionActionApp: FC = () => {
|
const SelectionActionApp: FC = () => {
|
||||||
const { language } = useSettings()
|
const { language, customCss } = useSettings()
|
||||||
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
@ -61,6 +61,20 @@ const SelectionActionApp: FC = () => {
|
|||||||
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
||||||
}, [language])
|
}, [language])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let customCssElement = document.getElementById('user-defined-custom-css') as HTMLStyleElement
|
||||||
|
if (customCssElement) {
|
||||||
|
customCssElement.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customCss) {
|
||||||
|
customCssElement = document.createElement('style')
|
||||||
|
customCssElement.id = 'user-defined-custom-css'
|
||||||
|
customCssElement.textContent = customCss
|
||||||
|
document.head.appendChild(customCssElement)
|
||||||
|
}
|
||||||
|
}, [customCss])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const contentEl = contentElementRef.current
|
const contentEl = contentElementRef.current
|
||||||
if (contentEl) {
|
if (contentEl) {
|
||||||
|
|||||||
@ -95,7 +95,7 @@ const ActionIcons: FC<{
|
|||||||
* demo is used in the settings page
|
* demo is used in the settings page
|
||||||
*/
|
*/
|
||||||
const SelectionToolbar: FC<{ demo?: boolean }> = ({ demo = false }) => {
|
const SelectionToolbar: FC<{ demo?: boolean }> = ({ demo = false }) => {
|
||||||
const { language } = useSettings()
|
const { language, customCss } = useSettings()
|
||||||
const { isCompact, actionItems } = useSelectionAssistant()
|
const { isCompact, actionItems } = useSelectionAssistant()
|
||||||
const [animateKey, setAnimateKey] = useState(0)
|
const [animateKey, setAnimateKey] = useState(0)
|
||||||
const [copyIconStatus, setCopyIconStatus] = useState<'normal' | 'success' | 'fail'>('normal')
|
const [copyIconStatus, setCopyIconStatus] = useState<'normal' | 'success' | 'fail'>('normal')
|
||||||
@ -150,6 +150,20 @@ const SelectionToolbar: FC<{ demo?: boolean }> = ({ demo = false }) => {
|
|||||||
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
||||||
}, [language])
|
}, [language])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let customCssElement = document.getElementById('user-defined-custom-css') as HTMLStyleElement
|
||||||
|
if (customCssElement) {
|
||||||
|
customCssElement.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customCss) {
|
||||||
|
customCssElement = document.createElement('style')
|
||||||
|
customCssElement.id = 'user-defined-custom-css'
|
||||||
|
customCssElement.textContent = customCss
|
||||||
|
document.head.appendChild(customCssElement)
|
||||||
|
}
|
||||||
|
}, [customCss])
|
||||||
|
|
||||||
const onHideCleanUp = () => {
|
const onHideCleanUp = () => {
|
||||||
setCopyIconStatus('normal')
|
setCopyIconStatus('normal')
|
||||||
setCopyIconAnimation('none')
|
setCopyIconAnimation('none')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user