detect lang remote

This commit is contained in:
Gabe Yuan
2023-10-11 09:48:52 +08:00
parent 5cd6977a6e
commit dd99fddc07
2 changed files with 11 additions and 5 deletions

View File

@@ -103,6 +103,7 @@ const userscriptWebpack = (config, env) => {
// @connect kiss-translator.rayjar.com
// @connect ghproxy.com
// @connect dav.jianguoyun.com
// @connect fanyi.baidu.com
// @connect localhost:3000
// @run-at document-end
// ==/UserScript==

View File

@@ -21,16 +21,21 @@ export const tryClearCaches = async () => {
export const tryDetectLang = async (q, useRemote = false) => {
let lang = "";
try {
if (useRemote) {
try {
lang = await apiBaiduLangdetect(q);
} catch (err) {
console.log("[detect lang remote]", err.message);
}
}
if (!lang) {
try {
const res = await browser?.i18n?.detectLanguage(q);
lang = res?.languages?.[0]?.language;
}
} catch (err) {
console.log("[detect lang]", err.message);
console.log("[detect lang local]", err.message);
}
}
return lang;