From a268dca2cb902fd2bc89560e84a61213ab997091 Mon Sep 17 00:00:00 2001 From: example Date: Sat, 23 Mar 2019 09:56:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=9B=BE=E6=A0=87=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E5=A4=84=E7=90=86=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translate/translate.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/translate/translate.js b/translate/translate.js index 49b59bc..686d324 100644 --- a/translate/translate.js +++ b/translate/translate.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Translate // @namespace http://tampermonkey.net/ -// @version 5.1 +// @version 5.2 // @description 划词翻译调用“金山词霸、有道词典(有道翻译)、Google Translate(谷歌翻译)、沪江小D、搜狗翻译、必应词典(必应翻译)、Microsoft Translator(必应在线翻译)、海词词典、百度翻译、Oxford Learner's Dictionaries、Oxford Dictionaries、Merriam-Webster、汉典、PDF 划词翻译、Google Search、Bing Search(必应搜索)、百度搜索、Wikipedia Search(维基百科搜索)”网页翻译 // @author https://github.com/barrer // @match http://*/* @@ -420,8 +420,7 @@ document.addEventListener("selectionchange", function () { log('selectionchange:' + window.getSelection().toString()); if (!window.getSelection().toString().trim()) { - icon.style.display = 'none'; - forceStopDrag(); + hideIcon(); } }); // 鼠标事件:防止选中的文本消失;显示、隐藏翻译图标 @@ -444,11 +443,7 @@ icon.style.zIndex = '2147473647'; } else if (!text) { log('hide icon'); - icon.style.display = 'none'; - icon.querySelectorAll('img[is-more]').forEach(function (ele) { - ele.style.display = 'none'; - }); - forceStopDrag(); + hideIcon(); } }); /**日志输出*/ @@ -596,6 +591,14 @@ iconDrag.unsetMouseMove(); } } + /**隐藏 icon*/ + function hideIcon() { + icon.style.display = 'none'; + icon.querySelectorAll('img[is-more]').forEach(function (ele) { + ele.style.display = 'none'; + }); + forceStopDrag(); + } /**设置*/ function settings() { var hideConfig = gm.get(gm.HIDE, {});