rollback to innerText
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
MSG_TRANS_TOGGLE,
|
||||
MSG_TRANS_GETRULE,
|
||||
MSG_TRANS_PUTRULE,
|
||||
OPT_TRANS_OPENAI,
|
||||
TRANS_MIN_LENGTH,
|
||||
TRANS_MAX_LENGTH,
|
||||
} from "./config";
|
||||
@@ -104,10 +103,7 @@ class Translator {
|
||||
}
|
||||
|
||||
// 除openai外,保留code和a标签
|
||||
const q =
|
||||
this._rule.translator === OPT_TRANS_OPENAI
|
||||
? el.innerText.trim()
|
||||
: el.innerHTML.replace(/<(?!\/?(code|a))[^>]+>/gi, "").trim();
|
||||
const q = this._rule.translator === el.innerText.trim();
|
||||
if (!q || q.length < TRANS_MIN_LENGTH || q.length > TRANS_MAX_LENGTH) {
|
||||
// 太长或太短不翻译
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
OPT_STYLE_WAVYLINE,
|
||||
OPT_STYLE_FUZZY,
|
||||
OPT_STYLE_HIGHTLIGHT,
|
||||
OPT_TRANS_OPENAI,
|
||||
} from "../../config";
|
||||
import { useTranslate } from "../../hooks/Translate";
|
||||
|
||||
@@ -77,30 +76,13 @@ export default function Content({ q, rule }) {
|
||||
return (
|
||||
<>
|
||||
{q.length > 40 ? <br /> : " "}
|
||||
{rule.translator === OPT_TRANS_OPENAI ? (
|
||||
<span
|
||||
style={style}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
) : (
|
||||
<span
|
||||
style={style}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: text.replace(
|
||||
/<code>(.*?)<\/code>/gi,
|
||||
(_match, p1) =>
|
||||
`<code>${p1
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")}</code>`
|
||||
),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<span
|
||||
style={style}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user