From 89bf369b5feef3284ce9c60d9d3ea594cad15efc Mon Sep 17 00:00:00 2001 From: example Date: Mon, 21 Jan 2019 18:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E5=BF=AB=E7=9A=84UI=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translate/translate-dictionary.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/translate/translate-dictionary.js b/translate/translate-dictionary.js index 6258ccd..f311193 100644 --- a/translate/translate-dictionary.js +++ b/translate/translate-dictionary.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 划词翻译:多词典查询 // @namespace http://tampermonkey.net/ -// @version 1.7 +// @version 1.8 // @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、沪江小D、谷歌翻译” // @author https://github.com/barrer // @match http://*/* @@ -109,9 +109,12 @@ tr-content { display: block; - max-width: 400px; + max-width: 300px; max-height: 200px; - overflow: auto; + width: 300px; + height: 200px; + overflow-x: auto; + overflow-y: scroll; background: white; padding: 2px 8px; margin-top: 5px; @@ -416,7 +419,7 @@ obj[ids.BING] = '《Bing 词典》'; obj[ids.BING_LOWER_CASE] = ''; obj[ids.HJENGLISH] = '《沪江小D》'; - obj[ids.GOOGLE] = ''; + obj[ids.GOOGLE] = '《谷歌翻译》'; return obj; })() } @@ -519,6 +522,8 @@ if (!isDrag()) { // 没有拖动鼠标抬起的时候触发点击事件 if (engineId == obj.id) return; // 已经是当前翻译引擎 + else + cleanContent(); // 清空之前翻译结果 engineId = obj.id; // 翻译引擎 ID engineActivateShow(); // 显示翻译引擎指示器 audioEngines = []; // 清空发音引擎 @@ -780,12 +785,12 @@ /**显示内容面板*/ function showContent(idsType) { log('showContent:', idsType, engineResult); - if (!isAllDone(idsType)) { - log('showContent return'); - return; + if (isAllDone(idsType)) { + log('showContent allDone'); } log('showContent rendering'); // 发音 + audioEngines = []; // 清空防止多次渲染 audioEngines.push({ name: '♪US', url: 'http://dict.youdao.com/dictvoice?audio=' + selected + '&type=2' @@ -810,7 +815,7 @@ } } idsType.forEach(function (id) { - if (!(id in needDel)) { + if (engineResult[id] && !(id in needDel)) { if (idsExtension.names[id]) { var title = document.createElement('div'); title.innerHTML = idsExtension.names[id]; @@ -823,6 +828,9 @@ if (engineId != 'icon-google') { // 谷歌翻译不显示发音图标 content.insertBefore(audio, content.childNodes[0]); } + var largeHeight = document.createElement('div'); // 防止滚动条闪来闪去 + largeHeight.style.height = '10000px'; + content.appendChild(largeHeight); content.style.display = 'block'; content.scrollTop = 0; content.scrollLeft = 0; @@ -848,6 +856,13 @@ engineActivateHide(); forceStopDrag(); } + /**清空翻译面板*/ + function cleanContent() { + content.innerHTML = ''; + var largeHeight = document.createElement('div'); // 防止滚动条闪来闪去 + largeHeight.style.height = '10000px'; + content.appendChild(largeHeight); + } /**发音*/ function play(obj) { if (isDrag()) { // 拖动时候不触发发音