diff --git a/builds/4chan-X.js b/builds/4chan-X.js index aa71af24a..d0686d325 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -6585,29 +6585,27 @@ if (Conf['Unread Line']) { $.on(d, 'visibilitychange', Unread.setLine); } - if (!Conf['Scroll to Last Read Post']) { + if (Conf['Scroll to Last Read Post']) { + return $.on(window, 'load', Unread.scroll); + } + }, + scroll: function() { + var hash, posts, root; + + if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) { return; } - return $.on(window, 'load', function() { - var hash, root; - - if ((hash = location.hash.match(/\d+/)) && hash[0] in this.posts) { - return; - } - if (Unread.posts.length) { - while (root = $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root)) { - if (!(Get.postFromRoot(root)).isHidden) { - break; - } + if (Unread.posts.length) { + while (root = $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root)) { + if (!(Get.postFromRoot(root)).isHidden) { + break; } - if (!root) { - return; - } - return root.scrollIntoView(false); - } else if (posts.length) { - return Header.scrollToPost(posts[posts.length - 1].nodes.root); } - }); + root.scrollIntoView(false); + return; + } + posts = Object.keys(Unread.thread.posts); + return Header.scrollToPost(Unread.thread.posts[posts[posts.length - 1]].nodes.root); }, sync: function() { var lastReadPost; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index d6bc2502d..126303aaf 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -6576,29 +6576,27 @@ if (Conf['Unread Line']) { $.on(d, 'visibilitychange', Unread.setLine); } - if (!Conf['Scroll to Last Read Post']) { + if (Conf['Scroll to Last Read Post']) { + return $.on(window, 'load', Unread.scroll); + } + }, + scroll: function() { + var hash, posts, root; + + if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) { return; } - return $.on(window, 'load', function() { - var hash, root; - - if ((hash = location.hash.match(/\d+/)) && hash[0] in this.posts) { - return; - } - if (Unread.posts.length) { - while (root = $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root)) { - if (!(Get.postFromRoot(root)).isHidden) { - break; - } + if (Unread.posts.length) { + while (root = $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root)) { + if (!(Get.postFromRoot(root)).isHidden) { + break; } - if (!root) { - return; - } - return root.scrollIntoView(false); - } else if (posts.length) { - return Header.scrollToPost(posts[posts.length - 1].nodes.root); } - }); + root.scrollIntoView(false); + return; + } + posts = Object.keys(Unread.thread.posts); + return Header.scrollToPost(Unread.thread.posts[posts[posts.length - 1]].nodes.root); }, sync: function() { var lastReadPost; diff --git a/builds/crx/script.js b/builds/crx/script.js index 59910ecc5..9820a2cc9 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -6440,29 +6440,27 @@ if (Conf['Unread Line']) { $.on(d, 'visibilitychange', Unread.setLine); } - if (!Conf['Scroll to Last Read Post']) { + if (Conf['Scroll to Last Read Post']) { + return $.on(window, 'load', Unread.scroll); + } + }, + scroll: function() { + var hash, posts, root; + + if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) { return; } - return $.on(window, 'load', function() { - var hash, root; - - if ((hash = location.hash.match(/\d+/)) && hash[0] in this.posts) { - return; - } - if (Unread.posts.length) { - while (root = $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root)) { - if (!(Get.postFromRoot(root)).isHidden) { - break; - } + if (Unread.posts.length) { + while (root = $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root)) { + if (!(Get.postFromRoot(root)).isHidden) { + break; } - if (!root) { - return; - } - return root.scrollIntoView(false); - } else if (posts.length) { - return Header.scrollToPost(posts[posts.length - 1].nodes.root); } - }); + root.scrollIntoView(false); + return; + } + posts = Object.keys(Unread.thread.posts); + return Header.scrollToPost(Unread.thread.posts[posts[posts.length - 1]].nodes.root); }, sync: function() { var lastReadPost; diff --git a/src/features/monitoring/unread.coffee b/src/features/monitoring/unread.coffee index 8ff735c2a..738742ab8 100644 --- a/src/features/monitoring/unread.coffee +++ b/src/features/monitoring/unread.coffee @@ -26,21 +26,20 @@ Unread = $.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'] - return unless Conf['Scroll to Last Read Post'] - - $.on window, 'load', -> - # 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 - return unless root - root.scrollIntoView false - else if posts.length - # Scroll to the last read post. - Header.scrollToPost (posts[posts.length - 1]).nodes.root + 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. + while root = $.x 'preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root + break unless (Get.postFromRoot root).isHidden + root.scrollIntoView false + return + # Scroll to the last read post. + posts = Object.keys Unread.thread.posts + Header.scrollToPost Unread.thread.posts[posts[posts.length - 1]].nodes.root sync: -> lastReadPost = Unread.db.get