diff --git a/README.md b/README.md index e9d844cb..e94b19de 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,14 @@ ## 更新 +### v1.0.2 + +- 增加划词翻译的功能,调用有道的英译中的接口。手册界面选中文本后按“T”键即可翻译,翻译结果暂时通过系统弹窗显示(偷懒),由于弹窗大小限制,如果翻译内容太长可能会显示不全 + +### v1.0.1 + +- 一些bug修复、、 + ### v1.0.0 - 上架 uTools 插件商店,算是正式版了,去除了内置的插件更新提示 diff --git a/assets/index.js b/assets/index.js index be511b4b..1f0a4fb6 100644 --- a/assets/index.js +++ b/assets/index.js @@ -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) + }) + } + } + } } }); \ No newline at end of file diff --git a/plugin.json b/plugin.json index 4d2948a7..21e394f7 100644 --- a/plugin.json +++ b/plugin.json @@ -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" ],