From 082a8dd9096e1d65d774cabf0e2ea8fcdca67eed Mon Sep 17 00:00:00 2001 From: example Date: Thu, 14 Mar 2019 18:44:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E5=85=B3=E9=97=AD=E5=A4=96?= =?UTF-8?q?=E9=83=A8JS=E8=AE=BF=E9=97=AE=E6=9D=83=E9=99=90=EF=BC=8C?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E9=9D=A2=E6=9D=BF=E8=AE=A1=E7=AE=97=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translate/translate-dictionary.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/translate/translate-dictionary.js b/translate/translate-dictionary.js index fbce4ad..ef696f3 100644 --- a/translate/translate-dictionary.js +++ b/translate/translate-dictionary.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 划词翻译:多词典查询 // @namespace http://tampermonkey.net/ -// @version 3.3 +// @version 3.4 // @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、剑桥高阶、沪江小D、谷歌翻译” // @author https://github.com/barrer // @match http://*/* @@ -340,7 +340,7 @@ var root = document.createElement('div'); document.documentElement.appendChild(root); var shadow = root.attachShadow({ - mode: 'open' + mode: 'closed' }); // iframe 工具库加入 Shadow shadow.appendChild(iframe); @@ -625,19 +625,21 @@ 'document.body.clientWidth', document.body.clientWidth, 'icon.style.left', icon.style.left ); - if (parseInt(icon.style.top) < document.documentElement.scrollTop) { + var scrollTop = Math.max(parseInt(document.documentElement.scrollTop), parseInt(document.body.scrollTop)); + var scrollLeft = Math.max(parseInt(document.documentElement.scrollLeft), parseInt(document.body.scrollLeft)); + if (parseInt(icon.style.top) < scrollTop) { log('Y adjust top'); - icon.style.top = parseInt(document.documentElement.scrollTop) + 'px'; - } else if (parseInt(icon.style.top) + panelHeight > document.documentElement.scrollTop + document.documentElement.clientHeight) { + icon.style.top = scrollTop + 'px'; + } else if (parseInt(icon.style.top) + panelHeight > scrollTop + document.documentElement.clientHeight) { log('Y adjust bottom'); - icon.style.top = parseInt(document.documentElement.scrollTop + document.documentElement.clientHeight - panelHeight) + 'px'; + icon.style.top = parseInt(scrollTop + document.documentElement.clientHeight - panelHeight) + 'px'; } - if (parseInt(icon.style.left) < document.documentElement.scrollLeft) { + if (parseInt(icon.style.left) < scrollLeft) { log('X adjust left'); - icon.style.left = parseInt(document.documentElement.scrollLeft) + 'px'; - } else if (parseInt(icon.style.left) + panelWidth > document.documentElement.scrollLeft + document.documentElement.clientWidth) { + icon.style.left = scrollLeft + 'px'; + } else if (parseInt(icon.style.left) + panelWidth > scrollLeft + document.documentElement.clientWidth) { log('X adjust right'); - icon.style.left = parseInt(document.documentElement.scrollLeft + document.documentElement.clientWidth - panelWidth) + 'px'; + icon.style.left = parseInt(scrollLeft + document.documentElement.clientWidth - panelWidth) + 'px'; } content.style.display = 'block'; }