Make Thread Stats work on Tinyboard/vichan sites. #2171
This commit is contained in:
parent
64d1e5b21d
commit
8091065f03
@ -1,15 +1,22 @@
|
|||||||
ThreadStats =
|
ThreadStats =
|
||||||
|
postCount: 0
|
||||||
|
fileCount: 0
|
||||||
|
postIndex: 0
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
|
return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
|
||||||
|
|
||||||
|
if Conf['Page Count in Stats']
|
||||||
|
@[if g.SITE.isPrunedByAge?(g.BOARD) then 'showPurgePos' else 'showPage'] = true
|
||||||
|
|
||||||
statsHTML = <%= html(
|
statsHTML = <%= html(
|
||||||
'<span id="post-count">?</span> / <span id="file-count">?</span>' +
|
'<span id="post-count">?</span> / <span id="file-count">?</span>' +
|
||||||
'?{Conf["IP Count in Stats"]}{ / <span id="ip-count">?</span>}' +
|
'?{Conf["IP Count in Stats"] && g.SITE.hasIPCount}{ / <span id="ip-count">?</span>}' +
|
||||||
'?{Conf["Page Count in Stats"]}{ / <span id="page-count">?</span>}'
|
'?{Conf["Page Count in Stats"]}{ / <span id="page-count">?</span>}'
|
||||||
) %>
|
) %>
|
||||||
statsTitle = 'Posts / Files'
|
statsTitle = 'Posts / Files'
|
||||||
statsTitle += ' / IPs' if Conf['IP Count in Stats']
|
statsTitle += ' / IPs' if Conf['IP Count in Stats'] and g.SITE.hasIPCount
|
||||||
statsTitle += (if g.BOARD.ID is 'f' then ' / Purge Position' else ' / Page') if Conf['Page Count in Stats']
|
statsTitle += (if @showPurgePos then ' / Purge Position' else ' / Page') if Conf['Page Count in Stats']
|
||||||
|
|
||||||
if Conf['Updater and Stats in Header']
|
if Conf['Updater and Stats in Header']
|
||||||
@dialog = sc = $.el 'span',
|
@dialog = sc = $.el 'span',
|
||||||
@ -37,35 +44,46 @@ ThreadStats =
|
|||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
postCount = 0
|
|
||||||
fileCount = 0
|
|
||||||
@posts.forEach (post) ->
|
|
||||||
postCount++
|
|
||||||
fileCount++ if post.file
|
|
||||||
(ThreadStats.lastPost = post.info.date if ThreadStats.pageCountEl)
|
|
||||||
ThreadStats.thread = @
|
ThreadStats.thread = @
|
||||||
|
ThreadStats.count()
|
||||||
|
ThreadStats.update()
|
||||||
ThreadStats.fetchPage()
|
ThreadStats.fetchPage()
|
||||||
ThreadStats.update postCount, fileCount, @ipCount
|
$.on d, 'PostsInserted', -> $.queueTask ThreadStats.onPostsInserted
|
||||||
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
|
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
|
||||||
|
|
||||||
|
count: ->
|
||||||
|
{posts} = ThreadStats.thread
|
||||||
|
n = posts.keys.length
|
||||||
|
for i in [ThreadStats.postIndex...n] by 1
|
||||||
|
post = posts[posts.keys[i]]
|
||||||
|
unless post.isFetchedQuote
|
||||||
|
ThreadStats.postCount++
|
||||||
|
ThreadStats.fileCount += post.files.length
|
||||||
|
ThreadStats.postIndex = n
|
||||||
|
|
||||||
onUpdate: (e) ->
|
onUpdate: (e) ->
|
||||||
return if e.detail[404]
|
return if e.detail[404]
|
||||||
{postCount, fileCount, ipCount, newPosts} = e.detail
|
{postCount, fileCount} = e.detail
|
||||||
ThreadStats.update postCount, fileCount, ipCount
|
$.extend ThreadStats, {postCount, fileCount}
|
||||||
return unless ThreadStats.pageCountEl
|
ThreadStats.postIndex = ThreadStats.thread.posts.keys.length
|
||||||
if newPosts.length
|
ThreadStats.update()
|
||||||
ThreadStats.lastPost = g.posts[newPosts[newPosts.length - 1]].info.date
|
if ThreadStats.showPage and ThreadStats.pageCountEl.textContent isnt '1'
|
||||||
if g.BOARD.ID isnt 'f' and ThreadStats.pageCountEl?.textContent isnt '1'
|
|
||||||
ThreadStats.fetchPage()
|
ThreadStats.fetchPage()
|
||||||
|
|
||||||
update: (postCount, fileCount, ipCount) ->
|
onPostsInserted: ->
|
||||||
|
return unless ThreadStats.thread.posts.keys.length > ThreadStats.postIndex
|
||||||
|
ThreadStats.count()
|
||||||
|
ThreadStats.update()
|
||||||
|
if ThreadStats.showPage and ThreadStats.pageCountEl.textContent isnt '1'
|
||||||
|
ThreadStats.fetchPage()
|
||||||
|
|
||||||
|
update: ->
|
||||||
{thread, postCountEl, fileCountEl, ipCountEl} = ThreadStats
|
{thread, postCountEl, fileCountEl, ipCountEl} = ThreadStats
|
||||||
postCountEl.textContent = postCount
|
postCountEl.textContent = ThreadStats.postCount
|
||||||
fileCountEl.textContent = fileCount
|
fileCountEl.textContent = ThreadStats.fileCount
|
||||||
if ipCount? and ipCountEl
|
ipCountEl?.textContent = thread.ipCount ? '?'
|
||||||
ipCountEl.textContent = ipCount
|
postCountEl.classList.toggle 'warning', (thread.postLimit and !thread.isSticky)
|
||||||
(if thread.postLimit and !thread.isSticky then $.addClass else $.rmClass) postCountEl, 'warning'
|
fileCountEl.classList.toggle 'warning', (thread.fileLimit and !thread.isSticky)
|
||||||
(if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning'
|
|
||||||
|
|
||||||
fetchPage: ->
|
fetchPage: ->
|
||||||
return unless ThreadStats.pageCountEl
|
return unless ThreadStats.pageCountEl
|
||||||
@ -76,15 +94,15 @@ ThreadStats =
|
|||||||
return
|
return
|
||||||
ThreadStats.timeout = setTimeout ThreadStats.fetchPage, 2 * $.MINUTE
|
ThreadStats.timeout = setTimeout ThreadStats.fetchPage, 2 * $.MINUTE
|
||||||
$.whenModified(
|
$.whenModified(
|
||||||
g.SITE.urls.threadsListJSON({boardID: ThreadStats.thread.board}),
|
g.SITE.urls.threadsListJSON(ThreadStats.thread),
|
||||||
'ThreadStats',
|
'ThreadStats',
|
||||||
ThreadStats.onThreadsLoad
|
ThreadStats.onThreadsLoad
|
||||||
)
|
)
|
||||||
|
|
||||||
onThreadsLoad: ->
|
onThreadsLoad: ->
|
||||||
if @status is 200
|
if @status is 200
|
||||||
for page in @response
|
for page, pageNum in @response
|
||||||
if g.BOARD.ID is 'f'
|
if ThreadStats.showPurgePos
|
||||||
purgePos = 1
|
purgePos = 1
|
||||||
for thread in page.threads
|
for thread in page.threads
|
||||||
if thread.no < ThreadStats.thread.ID
|
if thread.no < ThreadStats.thread.ID
|
||||||
@ -92,9 +110,9 @@ ThreadStats =
|
|||||||
ThreadStats.pageCountEl.textContent = purgePos
|
ThreadStats.pageCountEl.textContent = purgePos
|
||||||
else
|
else
|
||||||
for thread in page.threads when thread.no is ThreadStats.thread.ID
|
for thread in page.threads when thread.no is ThreadStats.thread.ID
|
||||||
ThreadStats.pageCountEl.textContent = page.page
|
ThreadStats.pageCountEl.textContent = pageNum + 1
|
||||||
(if page.page is @response.length then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
ThreadStats.pageCountEl.classList.toggle 'warning', (pageNum is @response.length - 1)
|
||||||
ThreadStats.lastPageUpdate = new Date thread.last_modified * $.SECOND
|
ThreadStats.lastPageUpdate = new Date(thread.last_modified * $.SECOND)
|
||||||
ThreadStats.retry()
|
ThreadStats.retry()
|
||||||
return
|
return
|
||||||
else if @status is 304
|
else if @status is 304
|
||||||
@ -102,6 +120,12 @@ ThreadStats =
|
|||||||
|
|
||||||
retry: ->
|
retry: ->
|
||||||
# If thread data is stale (modification date given < time of last post), try again.
|
# If thread data is stale (modification date given < time of last post), try again.
|
||||||
if g.BOARD.ID isnt 'f' and ThreadStats.lastPost > ThreadStats.lastPageUpdate and ThreadStats.pageCountEl?.textContent isnt '1'
|
# Skip this on vichan sites due to sage posts not updating modification time in threads.json.
|
||||||
clearTimeout ThreadStats.timeout
|
return unless (
|
||||||
ThreadStats.timeout = setTimeout ThreadStats.fetchPage, 5 * $.SECOND
|
ThreadStats.showPage and
|
||||||
|
ThreadStats.pageCountEl.textContent isnt '1' and
|
||||||
|
!g.SITE.threadModTimeIgnoresSage and
|
||||||
|
ThreadStats.thread.posts[ThreadStats.thread.lastPost].info.date > ThreadStats.lastPageUpdate
|
||||||
|
)
|
||||||
|
clearTimeout ThreadStats.timeout
|
||||||
|
ThreadStats.timeout = setTimeout ThreadStats.fetchPage, 5 * $.SECOND
|
||||||
|
|||||||
@ -23,7 +23,6 @@ SW.tinyboard =
|
|||||||
'Thread Expansion'
|
'Thread Expansion'
|
||||||
'Favicon'
|
'Favicon'
|
||||||
'Quote Threading'
|
'Quote Threading'
|
||||||
'Thread Stats'
|
|
||||||
'Thread Updater'
|
'Thread Updater'
|
||||||
'Banner'
|
'Banner'
|
||||||
'Flash Features'
|
'Flash Features'
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
SW.yotsuba =
|
SW.yotsuba =
|
||||||
isOPContainerThread: false
|
isOPContainerThread: false
|
||||||
|
hasIPCount: true
|
||||||
|
|
||||||
urls:
|
urls:
|
||||||
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
|
thread: ({boardID, threadID}) -> "#{location.protocol}//#{BoardConfig.domain(boardID)}/#{boardID}/thread/#{threadID}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user