From f8bfcba317b06f109e8f86a18661585139b92798 Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Wed, 22 Nov 2023 10:23:14 +0800 Subject: [PATCH] fix html fontsize --- src/hooks/Theme.js | 14 ++++++++++++++ src/libs/webfix.js | 2 +- src/views/Options/Header.js | 5 +++-- src/views/Popup/Header.js | 7 +++++-- src/views/Selection/DictCont.js | 15 ++++++++------- src/views/Selection/TranBox.js | 1 + src/views/Selection/TranCont.js | 1 + 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/hooks/Theme.js b/src/hooks/Theme.js index 7349c3f..4346243 100644 --- a/src/hooks/Theme.js +++ b/src/hooks/Theme.js @@ -12,10 +12,24 @@ import { THEME_DARK, THEME_LIGHT } from "../config"; export default function Theme({ children, options }) { const { darkMode } = useDarkMode(); const theme = useMemo(() => { + let htmlFontSize = 16; + try { + const s = window.getComputedStyle(document.body.parentNode).fontSize; + const fontSize = parseInt(s.replace("px", "")); + if (fontSize > 0 && fontSize < 1000) { + htmlFontSize = fontSize; + } + } catch (err) { + // + } + return createTheme({ palette: { mode: darkMode ? THEME_DARK : THEME_LIGHT, }, + typography: { + htmlFontSize, + }, ...options, }); }, [darkMode, options]); diff --git a/src/libs/webfix.js b/src/libs/webfix.js index fff1d21..a82d64b 100644 --- a/src/libs/webfix.js +++ b/src/libs/webfix.js @@ -15,7 +15,7 @@ export const FIXER_ALL = [ FIXER_BN, FIXER_BR_DIV, FIXER_BN_DIV, - FIXER_FONTSIZE, + // FIXER_FONTSIZE, ]; /** diff --git a/src/views/Options/Header.js b/src/views/Options/Header.js index ee67c03..43d57ac 100644 --- a/src/views/Options/Header.js +++ b/src/views/Options/Header.js @@ -6,6 +6,7 @@ import Box from "@mui/material/Box"; import Link from "@mui/material/Link"; import { useI18n } from "../../hooks/I18n"; import DarkModeButton from "./DarkModeButton"; +import Typography from "@mui/material/Typography"; function Header(props) { const i18n = useI18n(); @@ -30,14 +31,14 @@ function Header(props) { - + {`${i18n("app_name")} v${process.env.REACT_APP_VERSION}`} - + diff --git a/src/views/Popup/Header.js b/src/views/Popup/Header.js index ed2af91..304e1bc 100644 --- a/src/views/Popup/Header.js +++ b/src/views/Popup/Header.js @@ -4,6 +4,7 @@ import CloseIcon from "@mui/icons-material/Close"; import HomeIcon from "@mui/icons-material/Home"; import Stack from "@mui/material/Stack"; import DarkModeButton from "../Options/DarkModeButton"; +import Typography from "@mui/material/Typography"; export default function Header({ setShowPopup }) { const handleHomepage = () => { @@ -21,14 +22,16 @@ export default function Header({ setShowPopup }) { - {`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`} - + {setShowPopup ? ( diff --git a/src/views/Selection/DictCont.js b/src/views/Selection/DictCont.js index ea11217..67ff005 100644 --- a/src/views/Selection/DictCont.js +++ b/src/views/Selection/DictCont.js @@ -2,6 +2,7 @@ import Box from "@mui/material/Box"; import Chip from "@mui/material/Chip"; import Stack from "@mui/material/Stack"; import FavBtn from "./FavBtn"; +import Typography from "@mui/material/Typography"; const exchangeMap = { word_third: "第三人称单数", @@ -24,16 +25,16 @@ export default function DictCont({ dictResult }) { justifyContent="space-between" alignItems="flex-start" > -
+ {dictResult.simple_means?.word_name} -
+ {dictResult.simple_means?.symbols?.map(({ ph_en, ph_am, parts }, idx) => ( -
+ {(ph_en || ph_am) && ( -
{`英 /${ph_en || ""}/ 美 /${ph_am || ""}/`}
+ {`英 /${ph_en || ""}/ 美 /${ph_am || ""}/`} )}
    {parts.map(({ part, means }, idx) => ( @@ -42,14 +43,14 @@ export default function DictCont({ dictResult }) { ))}
-
+ ))} -
+ {Object.entries(dictResult.simple_means?.exchange || {}) .map(([key, val]) => `${exchangeMap[key] || key}: ${val.join(", ")}`) .join("; ")} -
+ {Object.values(dictResult.simple_means?.tags || {}) diff --git a/src/views/Selection/TranBox.js b/src/views/Selection/TranBox.js index 1a7b0e7..d58522a 100644 --- a/src/views/Selection/TranBox.js +++ b/src/views/Selection/TranBox.js @@ -95,6 +95,7 @@ function TranForm({ text, setText, tranboxSetting, transApis }) {