Skip to content

Commit

Permalink
opti code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bistutu committed Mar 2, 2024
1 parent fdb8f16 commit d38a729
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions FluentRead.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,30 +1331,22 @@ function DetectLang(text) {
return new Promise((resolve, reject) => {
// 数据参数
const data = new URLSearchParams();
console.log(text)
data.append('text', text); // 确保这与后端期望的参数名一致
const url = 'https://fr.unmeta.cn/detect'; // 您的后端服务URL

data.append('text', text);
// 发起请求
GM_xmlhttpRequest({
method: 'POST',
url: url,
url: 'https://fr.unmeta.cn/detect',
data: data.toString(),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
headers: {"Content-Type": "application/x-www-form-urlencoded"},
onload: function (response) {
if (response.status === 200) {
const jsn = JSON.parse(response.responseText);
console.log(jsn.language)
if (jsn && jsn.language) resolve(jsn.language);
} else {
reject(new Error('Server responded with status ' + response.status));
}
},
onerror: function () {
reject(new Error('GM_xmlhttpRequest failed'));
}
onerror: () => reject(new Error('GM_xmlhttpRequest failed'))
});
});
}
Expand Down

0 comments on commit d38a729

Please sign in to comment.