From 2860471bd6250c17f3337f8b7999d78f003e7259 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 13 Mar 2013 17:16:01 +0100 Subject: [PATCH] Make the Unread Line optional. --- 4chan_x.user.js | 15 ++++++++++----- CHANGELOG.md | 2 +- src/config.coffee | 1 + src/features.coffee | 14 ++++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 2466a03d1..bb31838eb 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -92,6 +92,7 @@ 'Thread Updater': [true, 'Fetch and insert new replies. Has more options in its own dialog.'], '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.'], '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.'], @@ -5243,14 +5244,16 @@ } } Unread.addPosts(posts); - if (Unread.hr.parentNode) { - Unread.hr.scrollIntoView(false); - } else if (posts.length && !Unread.posts.length) { + if (Unread.posts.length) { + $.x('preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root).scrollIntoView(false); + } else if (posts.length) { posts[posts.length - 1].nodes.root.scrollIntoView(); } $.on(d, 'ThreadUpdate', Unread.onUpdate); $.on(d, 'scroll visibilitychange', Unread.read); - return $.on(d, 'visibilitychange', Unread.setLine); + if (Conf['Unread Line']) { + return $.on(d, 'visibilitychange', Unread.setLine); + } }, addPosts: function(newPosts) { var ID, post, youInThisThread, yourPosts, _i, _len, _ref; @@ -5269,7 +5272,9 @@ Unread.addPostQuotingYou(post, yourPosts); } } - Unread.setLine((_ref = Unread.posts[0], __indexOf.call(newPosts, _ref) >= 0)); + if (Conf['Unread Line']) { + Unread.setLine((_ref = Unread.posts[0], __indexOf.call(newPosts, _ref) >= 0)); + } Unread.read(); return Unread.update(); }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 1efc0e27e..1db3b199e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ Thread Updater changes: - Added a setting to always auto-scroll to the bottom instead of the first new post. Unread posts changes: - - Added a line to distinguish read post from unread ones. + - Added a line to distinguish read posts from unread ones. - Read posts won't be marked as unread after reloading a thread. - The page will scroll to the last read post after reloading a thread. - Visible posts will not be taken into account towards the unread count. diff --git a/src/config.coffee b/src/config.coffee index 6a07cd4a1..73bff664e 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -37,6 +37,7 @@ Config = 'Thread Updater': [true, 'Fetch and insert new replies. Has more options in its own dialog.'] '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.'] '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 b270ee580..5556442e7 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -3524,14 +3524,15 @@ Unread = for ID, post of @posts posts.push post if post.isReply Unread.addPosts posts - if Unread.hr.parentNode - Unread.hr.scrollIntoView false - else if posts.length and !Unread.posts.length + 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. posts[posts.length - 1].nodes.root.scrollIntoView() $.on d, 'ThreadUpdate', Unread.onUpdate $.on d, 'scroll visibilitychange', Unread.read - $.on d, 'visibilitychange', Unread.setLine + $.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] addPosts: (newPosts) -> if Conf['Quick Reply'] @@ -3543,8 +3544,9 @@ Unread = continue Unread.posts.push post Unread.addPostQuotingYou post, yourPosts if yourPosts - # Force line on visible threads if there were no unread posts previously. - Unread.setLine Unread.posts[0] in newPosts + if Conf['Unread Line'] + # Force line on visible threads if there were no unread posts previously. + Unread.setLine Unread.posts[0] in newPosts Unread.read() Unread.update()