From c52e5a277455ad685f7ac1a9949526575423eda3 Mon Sep 17 00:00:00 2001 From: example Date: Mon, 7 Jan 2019 11:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=B7=E5=BC=8F=E8=A2=AB?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translate/translate-dictionary.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/translate/translate-dictionary.js b/translate/translate-dictionary.js index 3eca26b..7c7596b 100644 --- a/translate/translate-dictionary.js +++ b/translate/translate-dictionary.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 划词翻译:有道词典,金山词霸 // @namespace http://tampermonkey.net/ -// @version 0.6 +// @version 0.7 // @description 划词翻译调用“有道词典(有道翻译)、金山词霸” // @author https://github.com/barrer // @match http://*/* @@ -113,6 +113,7 @@ 'text-align:left!important;' + 'border:0!important;' + 'background:transparent!important;' + + 'color:black!important;' + 'z-index:2147483647!important;' + ''); content.setAttribute('style', '' + @@ -127,7 +128,12 @@ 'line-height:18px!important;' + ''); // 添加翻译图标到 DOM - document.documentElement.appendChild(icon); + var root = document.createElement('div'); + document.documentElement.appendChild(root); + var shadow = root.attachShadow({ + mode: 'open' + }); + shadow.appendChild(icon); // 鼠标事件:防止选中的文本消失 document.addEventListener('mousedown', function (e) { if (e.target == icon || (e.target.parentNode && e.target.parentNode == icon)) { // 点击了翻译图标