diff --git a/src/config/i18n.js b/src/config/i18n.js index 81613a3..c981a5f 100644 --- a/src/config/i18n.js +++ b/src/config/i18n.js @@ -64,6 +64,10 @@ export const I18N = { zh: `文字样式`, en: `Text Style`, }, + bg_color: { + zh: `样式颜色`, + en: `Style Color`, + }, google_api: { zh: `谷歌翻译接口`, en: `Google Translate API`, diff --git a/src/config/index.js b/src/config/index.js index 2cc85eb..fa80b31 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -127,6 +127,8 @@ export const DEFAULT_FETCH_INTERVAL = 100; // 默认任务间隔时间 export const PROMPT_PLACE_FROM = "{{from}}"; // 占位符 export const PROMPT_PLACE_TO = "{{to}}"; // 占位符 +export const DEFAULT_COLOR = "#209CEE"; // 默认高亮背景色/线条颜色 + // 全局规则 export const GLOBLA_RULE = { pattern: "*", @@ -136,6 +138,7 @@ export const GLOBLA_RULE = { toLang: "zh-CN", textStyle: OPT_STYLE_DASHLINE, transOpen: "false", + bgColor: "", }; // 默认规则 @@ -147,6 +150,7 @@ export const DEFAULT_RULE = { toLang: GLOBAL_KEY, textStyle: GLOBAL_KEY, transOpen: GLOBAL_KEY, + bgColor: "", }; export const DEFAULT_SETTING = { diff --git a/src/hooks/Rules.js b/src/hooks/Rules.js index 480a12f..e1ad5a9 100644 --- a/src/hooks/Rules.js +++ b/src/hooks/Rules.js @@ -78,9 +78,11 @@ export function useRules() { toLang, textStyle, transOpen, + bgColor, }) => ({ pattern, selector: typeof selector === "string" ? selector : "", + bgColor: typeof bgColor === "string" ? bgColor : "", translator: matchValue([GLOBAL_KEY, ...OPT_TRANS_ALL], translator), fromLang: matchValue([GLOBAL_KEY, ...fromLangs], fromLang), toLang: matchValue([GLOBAL_KEY, ...toLangs], toLang), diff --git a/src/hooks/Translate.js b/src/hooks/Translate.js index eea2ebb..6668a71 100644 --- a/src/hooks/Translate.js +++ b/src/hooks/Translate.js @@ -17,7 +17,7 @@ export function useTranslate(q, initRule) { const [sameLang, setSamelang] = useState(false); const [rule, setRule] = useState(initRule); - const { translator, fromLang, toLang, textStyle } = rule; + const { translator, fromLang, toLang, textStyle, bgColor } = rule; const handleMessage = ({ action, args }) => { if (action === MSG_TRANS_PUTRULE) { @@ -34,7 +34,7 @@ export function useTranslate(q, initRule) { setRule((pre) => ({ ...pre, ...args })); break; default: - // console.log(`[popup] kissEvent action skip: ${action}`); + // console.log(`[popup] kissEvent action skip: ${action}`); } }; @@ -79,5 +79,5 @@ export function useTranslate(q, initRule) { })(); }, [q, translator, fromLang, toLang]); - return { text, sameLang, loading, textStyle }; + return { text, sameLang, loading, textStyle, bgColor }; } diff --git a/src/libs/index.js b/src/libs/index.js index a6a5cd9..3f259a9 100644 --- a/src/libs/index.js +++ b/src/libs/index.js @@ -54,6 +54,8 @@ export const matchRule = (rules, href) => { rule.selector = GLOBLA_RULE.selector; } + rule.bgColor = rule?.bgColor?.trim() || GLOBLA_RULE?.bgColor?.trim(); + ["translator", "fromLang", "toLang", "textStyle", "transOpen"].forEach( (key) => { if (rule[key] === GLOBAL_KEY) { diff --git a/src/views/Content/LoadingIcon.js b/src/views/Content/LoadingIcon.js index 411c35d..eef84f7 100644 --- a/src/views/Content/LoadingIcon.js +++ b/src/views/Content/LoadingIcon.js @@ -1,3 +1,5 @@ +import { DEFAULT_COLOR } from "../../config"; + export default function LoadingIcon() { return ( - + - + - + { setHover(true); @@ -23,29 +24,30 @@ export default function Content({ q, rule }) { }; const style = useMemo(() => { + const lineColor = bgColor || ""; switch (textStyle) { case OPT_STYLE_LINE: // 下划线 return { opacity: hover ? 1 : 0.6, - textDecoration: "underline 2px", + textDecoration: `underline 2px ${lineColor}`, textUnderlineOffset: "0.3em", }; case OPT_STYLE_DOTLINE: // 点状线 return { opacity: hover ? 1 : 0.6, - textDecoration: "dotted underline 2px", + textDecoration: `dotted underline 2px ${lineColor}`, textUnderlineOffset: "0.3em", }; case OPT_STYLE_DASHLINE: // 虚线 return { opacity: hover ? 1 : 0.6, - textDecoration: "dashed underline 2px", + textDecoration: `dashed underline 2px ${lineColor}`, textUnderlineOffset: "0.3em", }; case OPT_STYLE_WAVYLINE: // 波浪线 return { opacity: hover ? 1 : 0.6, - textDecoration: "wavy underline 2px", + textDecoration: `wavy underline 2px ${lineColor}`, textUnderlineOffset: "0.3em", }; case OPT_STYLE_FUZZY: // 模糊 @@ -56,12 +58,12 @@ export default function Content({ q, rule }) { case OPT_STYLE_HIGHTLIGHT: // 高亮 return { color: "#FFF", - backgroundColor: "#209CEE", + backgroundColor: bgColor || DEFAULT_COLOR, }; default: return {}; } - }, [textStyle, hover]); + }, [textStyle, hover, bgColor]); if (loading) { return ( diff --git a/src/views/Options/Rules.js b/src/views/Options/Rules.js index 299d8db..ac1630a 100644 --- a/src/views/Options/Rules.js +++ b/src/views/Options/Rules.js @@ -39,6 +39,7 @@ function RuleFields({ rule, rules, setShow }) { toLang, textStyle, transOpen, + bgColor, } = formValues; const hasSamePattern = (str) => { @@ -138,8 +139,8 @@ function RuleFields({ rule, rules, setShow }) { /> - - + + {i18n("default_disabled")} - + - + - + - + + + +