From f9c36d47048e3de2449debdfdbf68702f607c6cf Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 16 Oct 2011 17:51:19 +0200 Subject: [PATCH] Scroll the reply to the bottom of the window; scroll only if the last reply is mostly visible, not when we're at the bottom; fix previousElementSibling, apparently it doesn't work on every boards. --- 4chan_x.user.js | 6 +++--- script.coffee | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 7e4533af9..66dd42b2b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1994,12 +1994,12 @@ return; } replies = $$('.reply', body); - id = Number(((_ref2 = $('td[id]', updater.br.previousSibling)) != null ? _ref2.id : void 0) || 0); + id = Number(((_ref2 = $('td[id]', updater.br.previousElementSibling)) != null ? _ref2.id : void 0) || 0); arr = []; while ((reply = replies.pop()) && (reply.id > id)) { arr.push(reply.parentNode.parentNode.parentNode); } - scroll = conf['Scrolling'] && updater.scrollBG() && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20); + scroll = conf['Scrolling'] && updater.scrollBG() && arr.length && updater.br.previousElementSibling.getBoundingClientRect().bottom - d.body.clientHeight < 25; if (conf['Verbose']) { updater.count.textContent = '+' + arr.length; if (arr.length === 0) { @@ -2012,7 +2012,7 @@ $.before(updater.br, reply); } if (scroll) { - return updater.br.previousSibling.scrollIntoView(); + return updater.br.previousSibling.scrollIntoView(false); } } }, diff --git a/script.coffee b/script.coffee index ab985319c..d5253c3bd 100644 --- a/script.coffee +++ b/script.coffee @@ -1516,12 +1516,13 @@ updater = return replies = $$ '.reply', body - id = Number $('td[id]', updater.br.previousSibling)?.id or 0 + id = Number $('td[id]', updater.br.previousElementSibling)?.id or 0 arr = [] while (reply = replies.pop()) and (reply.id > id) arr.push reply.parentNode.parentNode.parentNode #table - scroll = conf['Scrolling'] && updater.scrollBG() && arr.length && (d.body.scrollHeight - d.body.clientHeight - window.scrollY < 20) + scroll = conf['Scrolling'] && updater.scrollBG() && arr.length && + updater.br.previousElementSibling.getBoundingClientRect().bottom - d.body.clientHeight < 25 if conf['Verbose'] updater.count.textContent = '+' + arr.length if arr.length is 0 @@ -1533,7 +1534,7 @@ updater = while reply = arr.pop() $.before updater.br, reply if scroll - updater.br.previousSibling.scrollIntoView() + updater.br.previousSibling.scrollIntoView(false) timeout: -> updater.timeoutID = setTimeout updater.timeout, 1000