Add page number in Thread Stats. Close #832

This commit is contained in:
Mayhem 2013-05-26 01:05:03 +02:00
parent e9b4c133ac
commit 121bd1834c
4 changed files with 26 additions and 5 deletions

View File

@ -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.

View File

@ -0,0 +1 @@
<div class="move" title="Post count / File count / Page count"><span id="post-count">...</span> / <span id="file-count">...</span> / <span id="page-count">...</span></div>

View File

@ -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.']

View File

@ -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;', """
<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>
"""
<%= grunt.file.read('html/Monitoring/ThreadStats.html').replace(/>\s+</g, '><').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