MCPcopy Create free account
hub / github.com/ChinaGodMan/UserScripts / startTrans

Function startTrans

smart-translator-tool/smart-translator-tool.user.js:1043–1073  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1041var isLockTrans = false
1042// 开始执行翻译请求
1043const startTrans = () => {
1044 if (isLockTrans) {
1045 showMessage({ message: '操作频繁,请稍后~', type: 'warning', time: 1000 })
1046 return
1047 }
1048 isLockTrans = true
1049 let textAll = window.getSelection().toString()
1050 let arrFroms = formatTrans(textAll)
1051 if (arrFroms && arrFroms.length) {
1052 fromTransTextArray = arrFroms
1053 }
1054 // 判断是否有选中翻译的文本
1055 isContainer = true // 更改容器状态
1056 transContainerDOM.style.display = 'flex'
1057 $('#fy_loading').show()
1058 fyContentDOM.textContent = ''
1059 computedContainer() // 计算容器位置
1060
1061 const methodMap = {
1062 Baidu: (texts) => {
1063 texts.filter(text => text).forEach(text => {
1064 baiduTranslate(text)
1065 })
1066 },
1067 Google: googleTranslate
1068 }
1069 methodMap[currFromApi](fromTransTextArray)
1070 setTimeout(() => {
1071 isLockTrans = false
1072 }, 500)
1073}
1074
1075// 切换翻译语言
1076const bindHandleSelectLang = () => {

Callers 3

bingTransKeysFunction · 0.85
bindHandleSelectLangFunction · 0.85
bindHandleSelectApiFunction · 0.85

Calls 4

formatTransFunction · 0.85
computedContainerFunction · 0.85
baiduTranslateFunction · 0.85
showMessageFunction · 0.70

Tested by

no test coverage detected