diff --git a/tieba page.js b/tieba page.js index e244ee2..0a1bec7 100644 --- a/tieba page.js +++ b/tieba page.js @@ -1,7 +1,7 @@ // ==UserScript== // @name tieba page // @namespace https://github.com/fthvgb1/tampermonkey-script -// @version 0.984 +// @version 0.985 // @author fthvgb1 // @match https://tieba.baidu.com/* // @match https://tiebac.baidu.com/* @@ -213,6 +213,28 @@ }) } + function lo(reference, target) { + //因为我们会将目标元素的边框纳入递归公式中,这里先减去对应的值 + let result = { + left: -target.clientLeft, + top: -target.clientTop + }; + let node = target; + while (node !== reference && node !== document) { + result.left = result.left + node.offsetLeft + node.clientLeft; + result.top = result.top + node.offsetTop + node.clientTop; + node = node.parentNode; + } + if (isNaN(reference.scrollLeft)) { + result.right = document.documentElement.scrollWidth - result.left; + result.bottom = document.documentElement.scrollHeight - result.top; + } else { + result.right = reference.scrollWidth - result.left; + result.bottom = reference.scrollHeight - result.top; + } + return result; + } + function t() { lz(); gp(); @@ -286,7 +308,8 @@ let url = `/mo/q//flr?fpn=${page}&kz=${kz}&pid=${tid}&is_ajax=1&has_url_param=0&template=lzl`; $.get(url, res => { replayPage(res, el); - el.scrollIntoView({block: "end", inline: "nearest", behavior: "smooth"}); + let l = lo(document, el); + window.scrollTo({top: l.top - 20, left: 0, behavior: "smooth"}); }) }); }