1.
@张小强,一个木函、Fusion App 啥的可以么?(没咋用过,但记得有这个功能)
2.
@张小强,封装成小程序我试过,APP应该也是可以
一加8Pro
9. <script>
const jsonArr = [];
const textSet = new Set();
function traverse(node) {
if (
node.nodeType === Node.ELEMENT_NODE &&
(node.tagName.toLowerCase() === 'head' ||
node.tagName.toLowerCase() === 'pre' ||
node.tagName.toLowerCase() === 'script' ||
node.tagName.toLowerCase() === 'textarea')
) {
return; // 排除 <head>, <pre>, <script>, <textarea> 标签
}
if (node.nodeType === Node.TEXT_NODE) {
const text = node.textContent.trim();
if (text !== '' && !textSet.has(text)) {
textSet.add(text); // 将文本内容添加到 Set 中
jsonArr.push({ "Text": text }); // 添加文本内容到 JSON 数组中
}
}
for (const child of node.childNodes) {
traverse(child); // 递归遍历子节点
}
}
traverse(document.body); // 从 <body> 元素开始遍历 DOM 树
fetch('
https://edge.microsoft.com/translate/auth', {
method: 'GET',
headers: {
'authority': 'edge.microsoft.com',
'accept': '*/*',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'origin': window.location.origin,
'referer': window.location.origin,
'sec-ch-ua': '"Microsoft Edge";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'sec-mesh-client-arch': 'x86_64',
'sec-mesh-client-edge-channel': 'stable',
'sec-mesh-client-edge-version': '111.0.1661.51',
'sec-mesh-client-os': 'Windows',
'sec-mesh-client-os-version': '10.0.18362',
'sec-mesh-client-webview': '0',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51'
}
})
.then(response => response.text())
.then(response => {
sessionStorage.setItem("translateauth", response);
return response;
})
.then(translateauth => {
return fetch('
https://api.cognitive.microsofttranslator.com/translate?from=zh-CHS&to=en&api-version=3.0&includeSentenceLength=true', {
method: 'POST',
headers: {
'authority': 'api.cognitive.microsofttranslator.com',
'accept': '*/*',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'authorization': 'Bearer ' + translateauth,
'content-type': 'application/json',
'origin': window.location.origin,
'referer': window.location.origin,
'sec-ch-ua': '"Microsoft Edge";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'cross-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51'
},
body: JSON.stringify(jsonArr),
redirect: 'follow'
}).then(response => response.json())
}).then(response => {
console.log(response);
})
</script>