增加划词翻译功能

This commit is contained in:
fofolee 2020-03-20 00:42:07 +08:00
parent 02b6fa9cce
commit e87ceca367
3 changed files with 35 additions and 1 deletions

View File

@ -16,6 +16,14 @@
## 更新
### v1.0.2
- 增加划词翻译的功能调用有道的英译中的接口。手册界面选中文本后按“T”键即可翻译翻译结果暂时通过系统弹窗显示偷懒由于弹窗大小限制如果翻译内容太长可能会显示不全
### v1.0.1
- 一些bug修复、、
### v1.0.0
- 上架 uTools 插件商店,算是正式版了,去除了内置的插件更新提示

View File

@ -364,5 +364,31 @@ $(document).keydown(e => {
}
}
break;
// 划词翻译
case 84:
if ($('#mainlist').is(':hidden') && $("#manual").is(":visible")) {
let text = window.getSelection().toString();
if (text) {
if (/[\u4e00-\u9fa5]/.test(text)){
utools.showNotification('中文你还看不懂嘛!', clickFeatureCode = null, silent = true)
} else {
let enText = encodeURIComponent(text)
$.get("http://fanyi.youdao.com/translate?&doctype=json&type=EN2ZH_CN&i=" + enText, data => {
let result = data.translateResult;
let cnText = '';
// 每段
for (var r of result) {
// 每句
for (var a of r) {
cnText += a.tgt;
}
cnText += '\r';
}
let msg = '翻译结果:\n' + cnText;
utools.showNotification(msg, clickFeatureCode = null, silent = true)
})
}
}
}
}
});

View File

@ -4,7 +4,7 @@
"main": "index.html",
"homepage": "https://github.com/fofolee/uTools-Manuals",
"publishPage": "https://yuanliao.info/d/356",
"version": "1.0.0",
"version": "1.0.2",
"author": "云之轩",
"logo": "logo.png",
"platform": [ "win32", "darwin", "linux" ],