diff --git a/CHANGELOG.md b/CHANGELOG.md index a58503966..34a3272c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- `Scroll to Last Read Post` is now optional, enabled by default. - The QR won't auto-hide when auto-hide is enabled and one of its input is focused. Doesn't work on Firefox. - Fix QR remembering the file spoiler state when it shouldn't. - Fix QR cooldown in Opera. diff --git a/src/config.coffee b/src/config.coffee index f5b799b59..d03d801e4 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -39,6 +39,7 @@ Config = 'Unread Count': [true, 'Show the unread posts count in the tab title.'] 'Unread Tab Icon': [true, 'Show a different favicon when there are unread posts.'] 'Unread Line': [true, 'Show a line to distinguish read posts from unread ones.'] + 'Scroll to Last Read Post': [true, 'Scroll back to the last read post when reopening a thread.'] 'Thread Excerpt': [true, 'Show an excerpt of the thread in the tab title.'] 'Thread Stats': [true, 'Display reply and image count.'] 'Thread Watcher': [true, 'Bookmark threads.'] diff --git a/src/features.coffee b/src/features.coffee index bc847fea0..e90adbabf 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -160,6 +160,7 @@ Header = (if hide then $.addClass else $.rmClass) Header.bar, 'autohide' hashScroll: -> return unless post = $.id @location.hash[1..] + return if (Get.postFromRoot post).isHidden Header.scrollToPost post scrollToPost: (post) -> {top} = post.getBoundingClientRect() @@ -3709,18 +3710,22 @@ Unread = threadID: @ID defaultValue: 0 Unread.addPosts posts - if (hash = location.hash.match /\d+/) and post = @posts[hash[0]] - Header.scrollToPost post.nodes.root - else if Unread.posts.length - # Scroll to before the first unread post. - $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root).scrollIntoView false - else if posts.length - # Scroll to the last read post. - Header.scrollToPost posts[posts.length - 1].nodes.root $.on d, 'ThreadUpdate', Unread.onUpdate $.on d, 'scroll visibilitychange', Unread.read $.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] + return unless Conf['Scroll to Last Read Post'] + # Let the header's onload callback handle it. + return if (hash = location.hash.match /\d+/) and hash[0] of @posts + if Unread.posts.length + # Scroll to before the first unread post. + while root = $.x 'preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root + break unless (Get.postFromRoot root).isHidden + root.scrollIntoView false + else if posts.length + # Scroll to the last read post. + Header.scrollToPost posts[posts.length - 1].nodes.root + sync: -> lastReadPost = Unread.db.get boardID: Unread.thread.board.ID