Add unique IP count to thread stats.

This commit is contained in:
ccd0 2014-11-09 12:48:45 -08:00
parent b09fadb744
commit f1dbda4b13
2 changed files with 16 additions and 9 deletions

View File

@ -2,25 +2,26 @@ ThreadStats =
init: ->
return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
countHTML = <%= html('<span id="post-count">?</span> / <span id="file-count">?</span>') %>
countHTML = <%= html('<span id="post-count">?</span> / <span id="file-count">?</span> / <span id="ip-count">?</span>') %>
countHTML = <%= html('&{countHTML} / <span id="page-count">?</span>') %> if Conf['Page Count in Stats']
if Conf['Updater and Stats in Header']
@dialog = sc = $.el 'span',
id: 'thread-stats'
title: 'Post Count / File Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "")
title: 'Post Count / File Count / IP Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "")
$.extend sc, countHTML
$.ready ->
Header.addShortcut sc
else
@dialog = sc = UI.dialog 'thread-stats', 'bottom: 0px; right: 0px;',
<%= html('<div class="move" title="Post Count / File Count${Conf["Page Count in Stats"] ? " / Page Count" : ""}">&{countHTML}</div>') %>
<%= html('<div class="move" title="Post Count / File Count / IP Count${Conf["Page Count in Stats"] ? " / Page Count" : ""}">&{countHTML}</div>') %>
$.ready =>
$.add d.body, sc
@postCountEl = $ '#post-count', sc
@fileCountEl = $ '#file-count', sc
@pageCountEl = $ '#page-count', sc
@ipCountEl = $ '#ip-count', sc
@pageCountEl = $ '#page-count', sc
Thread.callbacks.push
name: 'Thread Stats'
@ -33,25 +34,30 @@ ThreadStats =
postCount++
fileCount++ if post.file
ThreadStats.lastPost = post.info.date if Conf["Page Count in Stats"]
for script in $$ 'script[type="text/javascript"]:not([src])', d.head
if m = script.textContent.match /\bvar unique_ips = (\d+);/
ipCount = +m[1]
break
ThreadStats.thread = @
ThreadStats.fetchPage()
ThreadStats.update postCount, fileCount
ThreadStats.update postCount, fileCount, ipCount
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
onUpdate: (e) ->
return if e.detail[404]
{postCount, fileCount, newPosts} = e.detail
ThreadStats.update postCount, fileCount
{postCount, fileCount, ipCount, newPosts} = e.detail
ThreadStats.update postCount, fileCount, ipCount
return unless Conf["Page Count in Stats"]
if newPosts.length
ThreadStats.lastPost = g.posts[newPosts[newPosts.length - 1]].info.date
if ThreadStats.lastPost > ThreadStats.lastPageUpdate and ThreadStats.pageCountEl?.textContent isnt '1'
ThreadStats.fetchPage()
update: (postCount, fileCount) ->
{thread, postCountEl, fileCountEl} = ThreadStats
update: (postCount, fileCount, ipCount) ->
{thread, postCountEl, fileCountEl, ipCountEl} = ThreadStats
postCountEl.textContent = postCount
fileCountEl.textContent = fileCount
ipCountEl.textContent = if ipCount? then ipCount else '?'
(if thread.postLimit and !thread.isSticky then $.addClass else $.rmClass) postCountEl, 'warning'
(if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning'

View File

@ -339,3 +339,4 @@ ThreadUpdater =
newPosts: posts.map (post) -> post.fullID
postCount: OP.replies + 1
fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead)
ipCount: OP.unique_ips