diff --git a/4chan_x.coffee b/4chan_x.coffee index 30d24a388..f33584d05 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -28,6 +28,7 @@ config = 'Thread Navigation': [true, 'Navigate to previous / next thread'] 'Thread Updater': [true, 'Update threads'] 'Thread Watcher': [true, 'Bookmark threads'] + 'Unread Count': [true, 'Show unread post count in tab title'] #utility AEOS = @@ -1077,6 +1078,15 @@ for el in $$ '#recaptcha_table a' recaptcha = $ '#recaptcha_response_field' recaptcha.addEventListener('keydown', recaptchaListener, true) +scroll = -> + height = document.body.clientHeight + while reply = g.replies[0] + bottom = reply.getBoundingClientRect().bottom + if bottom > height #post is not completely read + break + g.replies.shift() + document.title = document.title.replace /\d+/, g.replies.length + #major features if getConfig 'Image Expansion' delform = $ 'form[name=delform]' @@ -1307,5 +1317,11 @@ else #not reply for a in as a.addEventListener('click', expandComment, true) +if getConfig 'Unread Count' + g.replies = $$ 'td.reply, td.replyhl' + document.title = '(0) ' + document.title + scroll() + document.addEventListener 'scroll', scroll, true + callback() for callback in g.callbacks d.body.addEventListener('DOMNodeInserted', nodeInserted, true) diff --git a/4chan_x.js b/4chan_x.js index 5b7868c88..809dd90f2 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -27,7 +27,8 @@ 'Thread Hiding': [true, 'Hide entire threads'], 'Thread Navigation': [true, 'Navigate to previous / next thread'], 'Thread Updater': [true, 'Update threads'], - 'Thread Watcher': [true, 'Bookmark threads'] + 'Thread Watcher': [true, 'Bookmark threads'], + 'Unread Count': [true, 'Show unread post count in tab title'] }; AEOS = { init: function() { @@ -1359,6 +1360,18 @@ } recaptcha = $('#recaptcha_response_field'); recaptcha.addEventListener('keydown', recaptchaListener, true); + scroll = function() { + var bottom, height, reply; + height = document.body.clientHeight; + while (reply = g.replies[0]) { + bottom = reply.getBoundingClientRect().bottom; + if (bottom > height) { + break; + } + g.replies.shift(); + } + return document.title = document.title.replace(/\d+/, g.replies.length); + }; if (getConfig('Image Expansion')) { delform = $('form[name=delform]'); expand = n('div', { @@ -1671,6 +1684,12 @@ } } } + if (getConfig('Unread Count')) { + g.replies = $$('td.reply, td.replyhl'); + document.title = '(0) ' + document.title; + scroll(); + document.addEventListener('scroll', scroll, true); + } _ref4 = g.callbacks; for (_m = 0, _len6 = _ref4.length; _m < _len6; _m++) { callback = _ref4[_m];