From 3f58572603af2283372a5d8a5ce1a7e7c9c45ca5 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 23 May 2011 01:47:18 +0200 Subject: [PATCH] Thread stats. --- 4chan_x.js | 37 ++++++++++++++++++++++++++++++++++++- script.coffee | 25 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/4chan_x.js b/4chan_x.js index c2659cf4c..2116127cd 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -59,7 +59,7 @@ */ (function() { - var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threading, titlePost, ui, unread, updater, watcher, _config, _ref; + var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threadStats, threading, titlePost, ui, unread, updater, watcher, _config, _ref; var __slice = Array.prototype.slice; if (typeof console !== "undefined" && console !== null) { log = function(arg) { @@ -72,6 +72,7 @@ 'Thread Updater': [true, 'Update threads'], 'Unread Count': [true, 'Show unread post count in tab title'], 'Post in Title': [true, 'Show the op\'s post in the tab title'], + 'Thread Stats': [true, 'Display reply and image count'], 'Thread Watcher': [true, 'Bookmark threads'], 'Auto Watch': [true, 'Automatically watch threads that you start'], 'Auto Watch Reply': [false, 'Automatically watch threads that you reply to'] @@ -1967,6 +1968,33 @@ return input.click(); } }; + threadStats = { + init: function() { + var html; + html = "
Replies: 0 Images: 1
"; + $.append(d.body, ui.dialog('stats', { + bottom: '0px', + left: '0px' + }, html)); + threadStats.replies = 0; + threadStats.images = 1; + return g.callbacks.push(threadStats.node); + }, + node: function(root) { + if (root.className) { + return; + } + threadStats.replies++; + if ($('img[md5]', root)) { + threadStats.images++; + if (threadStats.images > 151) { + $('#icount').className = 'error'; + } + } + $('#rcount').textContent = threadStats.replies; + return $('#icount').textContent = threadStats.images; + } + }; unread = { init: function() { unread.replies = []; @@ -2425,6 +2453,9 @@ if ($.config('Post in Title')) { titlePost.init(); } + if ($.config('Thread Stats')) { + threadStats.init(); + } if ($.config('Unread Count')) { unread.init(); } @@ -2598,6 +2629,10 @@ #updater:not(:hover) > div:not(.move) {\ display: none;\ }\ +\ + #stats {\ + position: fixed;\ + }\ \ #watcher {\ position: absolute;\ diff --git a/script.coffee b/script.coffee index 5baf6c58a..92c45af14 100644 --- a/script.coffee +++ b/script.coffee @@ -15,6 +15,7 @@ config = 'Thread Updater': [true, 'Update threads'] 'Unread Count': [true, 'Show unread post count in tab title'] 'Post in Title': [true, 'Show the op\'s post in the tab title'] + 'Thread Stats': [true, 'Display reply and image count'] 'Thread Watcher': [true, 'Bookmark threads'] 'Auto Watch': [true, 'Automatically watch threads that you start'] 'Auto Watch Reply': [false, 'Automatically watch threads that you reply to'] @@ -1544,6 +1545,23 @@ reportButton = $('input[value="Report"]').click() input.click() +threadStats = + init: -> + html = "
Replies: 0 Images: 1
" + $.append d.body, (ui.dialog 'stats', bottom: '0px', left: '0px', html) + threadStats.replies = 0 + threadStats.images = 1 + g.callbacks.push threadStats.node + node: (root) -> + return if root.className + threadStats.replies++ + if $ 'img[md5]', root + threadStats.images++ + if threadStats.images > 151 + $('#icount').className = 'error' + $('#rcount').textContent = threadStats.replies + $('#icount').textContent = threadStats.images + unread = init: -> unread.replies = [] @@ -1881,6 +1899,9 @@ main = if $.config 'Post in Title' titlePost.init() + if $.config 'Thread Stats' + threadStats.init() + if $.config 'Unread Count' unread.init() @@ -2043,6 +2064,10 @@ main = display: none; } + #stats { + position: fixed; + } + #watcher { position: absolute; }