diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 50efb10d3..707f493b1 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6283,7 +6283,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, x, y; + var headRect, next, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6292,7 +6292,14 @@ } ImageExpand.contract(post); root = post.nodes.root; - rect = (Conf['Advance on contract'] ? $.x("following::div[contains(@class,'postContainer')][1]", root) || root : root).getBoundingClientRect(); + if (Conf['Advance on contract']) { + while (next = $.x("following::div[contains(@class,'postContainer')][1]", root)) { + if (!($('.stub', next) || next.offsetHeight === 0)) { + break; + } + } + } + rect = (next || root).getBoundingClientRect(); if (rect.top < 0) { y = rect.top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { diff --git a/builds/crx/script.js b/builds/crx/script.js index bcdd59bae..8aee581ea 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6263,7 +6263,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, x, y; + var headRect, next, rect, root, thumb, x, y; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6272,7 +6272,14 @@ } ImageExpand.contract(post); root = post.nodes.root; - rect = (Conf['Advance on contract'] ? $.x("following::div[contains(@class,'postContainer')][1]", root) || root : root).getBoundingClientRect(); + if (Conf['Advance on contract']) { + while (next = $.x("following::div[contains(@class,'postContainer')][1]", root)) { + if (!($('.stub', next) || next.offsetHeight === 0)) { + break; + } + } + } + rect = (next || root).getBoundingClientRect(); if (rect.top < 0) { y = rect.top; if (Conf['Fixed Header'] && !Conf['Bottom Header']) { diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 25105dd72..53d11f035 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -62,11 +62,11 @@ ImageExpand = # Scroll back to the thumbnail when contracting the image # to avoid being left miles away from the relevant post. {root} = post.nodes - rect = (if Conf['Advance on contract'] - $.x("following::div[contains(@class,'postContainer')][1]", root) or root - else - root - ).getBoundingClientRect() + if Conf['Advance on contract'] + while next = $.x "following::div[contains(@class,'postContainer')][1]", root + break unless $('.stub', next) or next.offsetHeight is 0 + + rect = (next or root).getBoundingClientRect() if rect.top < 0 y = rect.top