fix: youdao dict
This commit is contained in:
@@ -148,20 +148,20 @@ export const apiMicrosoftDict = async (text) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const aus = [];
|
const aus = [];
|
||||||
const $audioUS = doc.querySelector("#bigaud_us");
|
|
||||||
const $audioUK = doc.querySelector("#bigaud_uk");
|
const $audioUK = doc.querySelector("#bigaud_uk");
|
||||||
if ($audioUS) {
|
const $audioUS = doc.querySelector("#bigaud_us");
|
||||||
const audioUS = host + $audioUS?.dataset?.mp3link;
|
|
||||||
const $phoneticUS = $audioUS.parentElement?.previousElementSibling;
|
|
||||||
const phoneticUS = $phoneticUS?.textContent?.trim();
|
|
||||||
aus.push({ key: "US", audio: audioUS, phonetic: phoneticUS });
|
|
||||||
}
|
|
||||||
if ($audioUK) {
|
if ($audioUK) {
|
||||||
const audioUK = host + $audioUK?.dataset?.mp3link;
|
const audioUK = host + $audioUK?.dataset?.mp3link;
|
||||||
const $phoneticUK = $audioUK.parentElement?.previousElementSibling;
|
const $phoneticUK = $audioUK.parentElement?.previousElementSibling;
|
||||||
const phoneticUK = $phoneticUK?.textContent?.trim();
|
const phoneticUK = $phoneticUK?.textContent?.trim();
|
||||||
aus.push({ key: "UK", audio: audioUK, phonetic: phoneticUK });
|
aus.push({ key: "UK", audio: audioUK, phonetic: phoneticUK });
|
||||||
}
|
}
|
||||||
|
if ($audioUS) {
|
||||||
|
const audioUS = host + $audioUS?.dataset?.mp3link;
|
||||||
|
const $phoneticUS = $audioUS.parentElement?.previousElementSibling;
|
||||||
|
const phoneticUS = $phoneticUS?.textContent?.trim();
|
||||||
|
aus.push({ key: "US", audio: audioUS, phonetic: phoneticUS });
|
||||||
|
}
|
||||||
|
|
||||||
const res = { word, trs, aus };
|
const res = { word, trs, aus };
|
||||||
putHttpCachePolyfill(cacheInput, null, res);
|
putHttpCachePolyfill(cacheInput, null, res);
|
||||||
@@ -266,7 +266,7 @@ export const apiYoudaoDict = async (text) => {
|
|||||||
};
|
};
|
||||||
const input = `https://dict.youdao.com/jsonapi_s?${queryString.stringify(params)}`;
|
const input = `https://dict.youdao.com/jsonapi_s?${queryString.stringify(params)}`;
|
||||||
const body = queryString.stringify({
|
const body = queryString.stringify({
|
||||||
q: "search",
|
q: text,
|
||||||
le: "en",
|
le: "en",
|
||||||
t: 3,
|
t: 3,
|
||||||
client: "web",
|
client: "web",
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ async function updateCspRules({ csplist, orilist }) {
|
|||||||
id: ORI_RULE_START_ID + index,
|
id: ORI_RULE_START_ID + index,
|
||||||
action: {
|
action: {
|
||||||
type: "modifyHeaders",
|
type: "modifyHeaders",
|
||||||
requestHeaders: [{ header: "Origin", operation: "remove" }],
|
requestHeaders: [{ header: "Origin", operation: "set", value: url }],
|
||||||
},
|
},
|
||||||
condition: {
|
condition: {
|
||||||
urlFilter: url,
|
urlFilter: url,
|
||||||
|
|||||||
@@ -530,9 +530,9 @@ export const I18N = {
|
|||||||
zh_TW: `1.其中 BuiltinAI 為瀏覽器內建AI翻譯,目前僅 Chrome 138 以上版本支援。`,
|
zh_TW: `1.其中 BuiltinAI 為瀏覽器內建AI翻譯,目前僅 Chrome 138 以上版本支援。`,
|
||||||
},
|
},
|
||||||
about_api_2: {
|
about_api_2: {
|
||||||
zh: `2、暂未列出的接口,理论上都可以通过自定义接口的形式支持。`,
|
zh: `2、暂未列出的接口,理论上都可以通过自定义接口 (Custom) 的形式支持。`,
|
||||||
en: `2. Interfaces that have not yet been launched can theoretically be supported through custom interfaces.`,
|
en: `2. Interfaces that have not yet been launched can theoretically be supported through custom interfaces.`,
|
||||||
zh_TW: `2、暫未列出的介面,理論上都可透過自訂介面的形式支援。`,
|
zh_TW: `2、暫未列出的介面,理論上都可透過自訂介面 (Custom) 的形式支援。`,
|
||||||
},
|
},
|
||||||
about_api_proxy: {
|
about_api_proxy: {
|
||||||
zh: `查看自建一个翻译接口代理`,
|
zh: `查看自建一个翻译接口代理`,
|
||||||
|
|||||||
@@ -87,11 +87,12 @@ export default function FavWords() {
|
|||||||
for (const word of wordList) {
|
for (const word of wordList) {
|
||||||
try {
|
try {
|
||||||
const data = await dict.apiFn(word);
|
const data = await dict.apiFn(word);
|
||||||
|
const title = `## ${dict.reWord(data) || word}`;
|
||||||
const tran = dict
|
const tran = dict
|
||||||
.toText(data)
|
.toText(data)
|
||||||
.map((line) => `- ${line}`)
|
.map((line) => `- ${line}`)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
tranList.push([`## ${word}`, tran].join("\n"));
|
tranList.push([title, tran].join("\n"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
kissLog("export translation", err);
|
kissLog("export translation", err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import CopyBtn from "./CopyBtn";
|
|||||||
import { useAsyncNow } from "../../hooks/Fetch";
|
import { useAsyncNow } from "../../hooks/Fetch";
|
||||||
import { dictHandlers } from "./DictHandler";
|
import { dictHandlers } from "./DictHandler";
|
||||||
|
|
||||||
function DictBody({ text, setCopyText, dict }) {
|
function DictBody({ text, setCopyText, setRealWord, dict }) {
|
||||||
const { loading, error, data } = useAsyncNow(dict.apiFn, text);
|
const { loading, error, data } = useAsyncNow(dict.apiFn, text);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -17,9 +17,11 @@ function DictBody({ text, setCopyText, dict }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const copyText = [text, dict.toText(data).join("\n")].join("\n");
|
const realWord = dict.reWord(data) || text;
|
||||||
|
const copyText = [realWord, dict.toText(data).join("\n")].join("\n");
|
||||||
|
setRealWord(realWord);
|
||||||
setCopyText(copyText);
|
setCopyText(copyText);
|
||||||
}, [data, text, dict, setCopyText]);
|
}, [data, text, dict, setCopyText, setRealWord]);
|
||||||
|
|
||||||
const uiAudio = useMemo(() => dict.uiAudio(data), [data, dict]);
|
const uiAudio = useMemo(() => dict.uiAudio(data), [data, dict]);
|
||||||
const uiTrans = useMemo(() => dict.uiTrans(data), [data, dict]);
|
const uiTrans = useMemo(() => dict.uiTrans(data), [data, dict]);
|
||||||
@@ -46,6 +48,7 @@ function DictBody({ text, setCopyText, dict }) {
|
|||||||
|
|
||||||
export default function DictCont({ text, enDict }) {
|
export default function DictCont({ text, enDict }) {
|
||||||
const [copyText, setCopyText] = useState(text);
|
const [copyText, setCopyText] = useState(text);
|
||||||
|
const [realWord, setRealWord] = useState(text);
|
||||||
const dict = dictHandlers[enDict];
|
const dict = dictHandlers[enDict];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -53,18 +56,25 @@ export default function DictCont({ text, enDict }) {
|
|||||||
{text && (
|
{text && (
|
||||||
<Stack direction="row" justifyContent="space-between">
|
<Stack direction="row" justifyContent="space-between">
|
||||||
<Typography variant="subtitle1" style={{ fontWeight: "bold" }}>
|
<Typography variant="subtitle1" style={{ fontWeight: "bold" }}>
|
||||||
{text}
|
{realWord}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Stack direction="row" justifyContent="space-between">
|
<Stack direction="row" justifyContent="space-between">
|
||||||
<CopyBtn text={copyText} />
|
<CopyBtn text={copyText} />
|
||||||
<FavBtn word={text} />
|
<FavBtn word={realWord} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
{dict && <DictBody text={text} setCopyText={setCopyText} dict={dict} />}
|
{dict && (
|
||||||
|
<DictBody
|
||||||
|
text={text}
|
||||||
|
setCopyText={setCopyText}
|
||||||
|
setRealWord={setRealWord}
|
||||||
|
dict={dict}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,16 @@ import { apiMicrosoftDict, apiYoudaoDict } from "../../apis";
|
|||||||
export const dictHandlers = {
|
export const dictHandlers = {
|
||||||
[OPT_DICT_BING]: {
|
[OPT_DICT_BING]: {
|
||||||
apiFn: apiMicrosoftDict,
|
apiFn: apiMicrosoftDict,
|
||||||
|
reWord: (data) => data?.word,
|
||||||
toText: (data) =>
|
toText: (data) =>
|
||||||
data.trs?.map(({ pos, def }) => `${pos ? `[${pos}] ` : ""}${def}`) || [],
|
data?.trs?.map(({ pos, def }) => `${pos ? `[${pos}] ` : ""}${def}`) || [],
|
||||||
uiAudio: (data) => (
|
uiAudio: (data) => (
|
||||||
<Typography component="div">
|
<Typography component="div">
|
||||||
{data?.aus.map(({ key, audio, phonetic }) => (
|
{data?.aus?.map(({ key, audio, phonetic }) => (
|
||||||
<Typography
|
<Typography
|
||||||
component="div"
|
component="div"
|
||||||
key={key}
|
key={key}
|
||||||
style={{ display: "inline-block" }}
|
style={{ display: "inline-block", paddingRight: "1em" }}
|
||||||
>
|
>
|
||||||
<Typography component="span">{phonetic}</Typography>
|
<Typography component="span">{phonetic}</Typography>
|
||||||
<AudioBtn src={audio} />
|
<AudioBtn src={audio} />
|
||||||
@@ -35,11 +36,27 @@ export const dictHandlers = {
|
|||||||
},
|
},
|
||||||
[OPT_DICT_YOUDAO]: {
|
[OPT_DICT_YOUDAO]: {
|
||||||
apiFn: apiYoudaoDict,
|
apiFn: apiYoudaoDict,
|
||||||
|
reWord: (data) => data?.ec?.word?.["return-phrase"],
|
||||||
toText: (data) =>
|
toText: (data) =>
|
||||||
data?.ec?.word?.trs?.map(
|
data?.ec?.word?.trs?.map(
|
||||||
({ pos, tran }) => `${pos ? `[${pos}] ` : ""}${tran}`
|
({ pos, tran }) => `${pos ? `[${pos}] ` : ""}${tran}`
|
||||||
) || [],
|
) || [],
|
||||||
uiAudio: () => null,
|
uiAudio: (data) => (
|
||||||
|
<Typography component="div">
|
||||||
|
<Typography
|
||||||
|
component="div"
|
||||||
|
style={{ display: "inline-block", paddingRight: "1em" }}
|
||||||
|
>
|
||||||
|
<Typography component="span">{`UK [${data?.ec?.word?.ukphone}]`}</Typography>
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
component="div"
|
||||||
|
style={{ display: "inline-block", paddingRight: "1em" }}
|
||||||
|
>
|
||||||
|
<Typography component="span">{`US [${data?.ec?.word?.usphone}]`}</Typography>
|
||||||
|
</Typography>
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
uiTrans: (data) => (
|
uiTrans: (data) => (
|
||||||
<Typography component="ul">
|
<Typography component="ul">
|
||||||
{data?.ec?.word?.trs?.map(({ pos, tran }, idx) => (
|
{data?.ec?.word?.trs?.map(({ pos, tran }, idx) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user