diff --git a/CHANGELOG.md b/CHANGELOG.md index b8928f24f..8bc06f6a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- The Thread Stats counters now include the number of the page where the thread is. + ### 3.4.3 - *2013-05-17* - More minor fixes. diff --git a/html/Monitoring/ThreadStats.html b/html/Monitoring/ThreadStats.html new file mode 100644 index 000000000..73904d14f --- /dev/null +++ b/html/Monitoring/ThreadStats.html @@ -0,0 +1 @@ +
... / ... / ...
diff --git a/src/General/Config.coffee b/src/General/Config.coffee index a219525ae..fe501f2ae 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -44,7 +44,7 @@ Config = 'Unread Line': [true, 'Show a line to distinguish read posts from unread ones.'] 'Scroll to Last Read Post': [true, 'Scroll back to the last read post when reopening a thread.'] 'Thread Excerpt': [true, 'Show an excerpt of the thread in the tab title.'] - 'Thread Stats': [true, 'Display reply and image count.'] + 'Thread Stats': [true, 'Display reply, image and page count.'] 'Thread Watcher': [true, 'Bookmark threads.'] 'Auto Watch': [true, 'Automatically watch threads you start.'] 'Auto Watch Reply': [false, 'Automatically watch threads you reply to.'] diff --git a/src/Monitoring/ThreadStats.coffee b/src/Monitoring/ThreadStats.coffee index a4467beef..8b0b2e55f 100644 --- a/src/Monitoring/ThreadStats.coffee +++ b/src/Monitoring/ThreadStats.coffee @@ -2,11 +2,13 @@ ThreadStats = init: -> return if g.VIEW isnt 'thread' or !Conf['Thread Stats'] @dialog = UI.dialog 'thread-stats', 'bottom: 0; left: 0;', """ -
0 / 0
- """ + <%= grunt.file.read('html/Monitoring/ThreadStats.html').replace(/>\s+<').trim() %> + """ - @postCountEl = $ '#post-count', @dialog - @fileCountEl = $ '#file-count', @dialog + @postCountEl = $ '#post-count', @dialog + @fileCountEl = $ '#file-count', @dialog + @pageCountEl = $ '#page-count', @dialog + @lastModified = '0' Thread::callbacks.push name: 'Thread Stats' @@ -18,6 +20,7 @@ ThreadStats = postCount++ fileCount++ if post.file ThreadStats.thread = @ + ThreadStats.fetchPage() ThreadStats.update postCount, fileCount $.on d, 'ThreadUpdate', ThreadStats.onUpdate $.add d.body, ThreadStats.dialog @@ -31,3 +34,18 @@ ThreadStats = fileCountEl.textContent = fileCount (if thread.postLimit and !thread.isSticky then $.addClass else $.rmClass) postCountEl, 'warning' (if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning' + fetchPage: -> + return if ThreadStats.thread.isDead + setTimeout ThreadStats.fetchPage, 2 * $.MINUTE + $.ajax "//api.4chan.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad, + headers: 'If-Modified-Since': ThreadStats.lastModified + onThreadsLoad: -> + ThreadStats.lastModified = @getResponseHeader 'Last-Modified' + return if @status isnt 200 + pages = JSON.parse @response + for page in pages + for thread in page.threads + if thread.no is ThreadStats.thread.ID + ThreadStats.pageCountEl.textContent = page.page + (if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning' + return