diff --git a/CHANGELOG.md b/CHANGELOG.md index d9825f7ea..a3e89c4e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- Fix bug where a thread would freeze on load. + ### 3.2.1 - *2013-04-26* - Minor fixes. diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 8d1695cfb..00231e253 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -15,26 +15,34 @@ Unread = node: -> Unread.thread = @ Unread.title = d.title - posts = [] - for ID, post of @posts - posts.push post if post.isReply Unread.lastReadPost = Unread.db.get boardID: @board.ID threadID: @ID defaultValue: 0 - Unread.addPosts posts + $.on d, '4chanXInitFinished', Unread.ready $.on d, 'ThreadUpdate', Unread.onUpdate $.on d, 'scroll visibilitychange', Unread.read $.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] $.on window, 'load', Unread.scroll if Conf['Scroll to Last Read Post'] + ready: -> + $.off d, '4chanXInitFinished', Unread.ready + posts = [] + for ID, post of Unread.thread.posts + posts.push post if post.isReply + Unread.addPosts posts + scroll: -> # Let the header's onload callback handle it. return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts if Unread.posts.length # Scroll to before the first unread post. + prevID = 0 while root = $.x 'preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root - break unless (Get.postFromRoot root).isHidden + post = Get.postFromRoot root + break if prevID is post.ID + prevID = post.ID + break unless post.isHidden root.scrollIntoView false return # Scroll to the last read post.