that's actually changed. Honestly, all I wanted was the 4cdn changes, but any excuse to merge was good enough, I guess. Merge branch 'v3' of git://github.com/MayhemYDG/4chan-x into v3 Conflicts: CHANGELOG.md Gruntfile.coffee changelog-old css/style.css html/General/Settings.html html/Monitoring/ThreadUpdater.html html/Monitoring/ThreadWatcher.html html/Posting/QR.html package.json src/Filtering/ThreadHiding.coffee src/General/Build.coffee src/General/Config.coffee src/General/Header.coffee src/General/Main.coffee src/General/Settings.coffee src/General/lib/post.class src/General/meta/manifest.json src/Images/ImageExpand.coffee src/Meta/banner.js src/Miscellaneous/ExpandComment.coffee src/Miscellaneous/ExpandThread.coffee src/Miscellaneous/Keybinds.coffee src/Miscellaneous/Nav.coffee src/Monitoring/Favicon.coffee src/Monitoring/ThreadStats.coffee src/Monitoring/ThreadUpdater.coffee src/Monitoring/ThreadWatcher.coffee src/Monitoring/Unread.coffee src/Posting/QuickReply.coffee
68 lines
2.6 KiB
CoffeeScript
Executable File
68 lines
2.6 KiB
CoffeeScript
Executable File
ThreadStats =
|
|
init: ->
|
|
return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
|
|
|
|
if Conf['Updater and Stats in Header']
|
|
@dialog = sc = $.el 'span',
|
|
innerHTML: "<span id=post-count>0</span> / <span id=file-count>0</span>#{if Conf["Page Count in Stats"] then " / <span id=page-count>0</span>" else ""}"
|
|
id: 'thread-stats'
|
|
title: 'Post Count / File Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "")
|
|
$.ready ->
|
|
Header.addShortcut sc
|
|
else
|
|
@dialog = sc = UI.dialog 'thread-stats', 'bottom: 0px; right: 0px;',
|
|
"<div class=move title='Post Count / File Count#{if Conf["Page Count in Stats"] then " / Page Count" else ""}'><span id=post-count>0</span> / <span id=file-count>0</span>#{if Conf["Page Count in Stats"] then " / <span id=page-count>0</span>" else ""}</div>"
|
|
$.ready =>
|
|
$.add d.body, sc
|
|
|
|
@postCountEl = $ '#post-count', sc
|
|
@fileCountEl = $ '#file-count', sc
|
|
@pageCountEl = $ '#page-count', sc
|
|
|
|
Thread.callbacks.push
|
|
name: 'Thread Stats'
|
|
cb: @node
|
|
|
|
node: ->
|
|
postCount = 0
|
|
fileCount = 0
|
|
for ID, post of @posts
|
|
postCount++
|
|
fileCount++ if post.file
|
|
ThreadStats.thread = @
|
|
ThreadStats.fetchPage()
|
|
ThreadStats.update postCount, fileCount
|
|
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
|
|
|
|
onUpdate: (e) ->
|
|
return if e.detail[404]
|
|
{postCount, fileCount} = e.detail
|
|
ThreadStats.update postCount, fileCount
|
|
|
|
update: (postCount, fileCount) ->
|
|
{thread, postCountEl, fileCountEl} = ThreadStats
|
|
postCountEl.textContent = postCount
|
|
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 !Conf["Page Count in Stats"]
|
|
if ThreadStats.thread.isDead
|
|
ThreadStats.pageCountEl.textContent = 'Dead'
|
|
$.addClass ThreadStats.pageCountEl, 'warning'
|
|
return
|
|
setTimeout ThreadStats.fetchPage, 2 * $.MINUTE
|
|
$.ajax "//a.4cdn.org/#{ThreadStats.thread.board}/threads.json", onload: ThreadStats.onThreadsLoad,
|
|
whenModified: true
|
|
|
|
onThreadsLoad: ->
|
|
return unless Conf["Page Count in Stats"] and @status is 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
|