MCPcopy Index your code
hub / github.com/Bistutu/FluentRead / baiduDetectLang

Function baiduDetectLang

userscripts.js:1495–1519  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

1493
1494// 检测语言类型
1495function baiduDetectLang(text) {
1496 return new Promise((resolve, reject) => {
1497 // 数据参数
1498 const data = new URLSearchParams();
1499 data.append('query', text);
1500 const url = 'https://fanyi.baidu.com/langdetect?' + data.toString();
1501 // 发起请求
1502 GM_xmlhttpRequest({
1503 method: POST,
1504 url: url,
1505 onload: resp => {
1506 const jsn = JSON.parse(resp.responseText);
1507 if (resp.status === 200 && jsn && jsn.lan) {
1508 resolve(langManager.parseLanguage(jsn.lan));
1509 } else {
1510 console.log(resp)
1511 reject(new Error('Server responded with status ' + resp));
1512 }
1513 },
1514 onerror: error => {
1515 reject(new Error('baiduDetectLang GM_xmlhttpRequest failed'));
1516 }
1517 });
1518 })
1519}
1520
1521// 延迟删除缓存
1522function delayRemoveCache(key, time = 250) {

Callers 1

translateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected