Implement Mark New IPs. #190
This commit is contained in:
parent
e43db40140
commit
70a8c639c3
@ -311,6 +311,10 @@ Config =
|
||||
true
|
||||
'Adds a shortcut for the thread watcher, hides the watcher by default, and makes it scroll with the page.'
|
||||
]
|
||||
'Mark New IPs': [
|
||||
false
|
||||
'Label each post from a new IP with the thread\'s current IP count.'
|
||||
]
|
||||
|
||||
'Posting':
|
||||
'Quick Reply': [
|
||||
|
||||
@ -337,6 +337,7 @@ Main =
|
||||
['Thread Updater', ThreadUpdater]
|
||||
['Thread Watcher', ThreadWatcher]
|
||||
['Thread Watcher (Menu)', ThreadWatcher.menu]
|
||||
['Mark New IPs', MarkNewIPs]
|
||||
['Index Navigation', Nav]
|
||||
['Keybinds', Keybinds]
|
||||
['Banner', Banner]
|
||||
|
||||
46
src/Monitoring/MarkNewIPs.coffee
Normal file
46
src/Monitoring/MarkNewIPs.coffee
Normal file
@ -0,0 +1,46 @@
|
||||
MarkNewIPs =
|
||||
init: ->
|
||||
return if g.VIEW isnt 'thread' or !Conf['Mark New IPs']
|
||||
Thread.callbacks.push
|
||||
name: 'Mark New IPs'
|
||||
cb: @node
|
||||
|
||||
node: ->
|
||||
MarkNewIPs.ipCount = @ipCount
|
||||
MarkNewIPs.postIDs = @posts.keys.map (x) -> +x
|
||||
$.on d, 'ThreadUpdate', MarkNewIPs.onUpdate
|
||||
|
||||
onUpdate: (e) ->
|
||||
{ipCount, newPosts} = e.detail
|
||||
{postIDs} = ThreadUpdater
|
||||
return unless ipCount?
|
||||
if newPosts.length
|
||||
obj = {}
|
||||
obj[x] = true for x in MarkNewIPs.postIDs
|
||||
added = 0
|
||||
added++ for x in postIDs when not (x of obj)
|
||||
removed = MarkNewIPs.postIDs.length + added - postIDs.length
|
||||
switch ipCount - MarkNewIPs.ipCount
|
||||
when added
|
||||
i = MarkNewIPs.ipCount
|
||||
for fullID in newPosts
|
||||
MarkNewIPs.mark g.posts[fullID], ++i
|
||||
when -removed
|
||||
for fullID in newPosts
|
||||
$.addClass g.posts[fullID].nodes.root, 'old-ip'
|
||||
MarkNewIPs.ipCount = ipCount
|
||||
MarkNewIPs.postIDs = postIDs
|
||||
|
||||
mark: (post, ipCount) ->
|
||||
suffix = switch ipCount
|
||||
when 1 then 'st'
|
||||
when 2 then 'nd'
|
||||
when 3 then 'rd'
|
||||
else 'th'
|
||||
counter = $.el 'span',
|
||||
className: 'ip-counter'
|
||||
textContent: "(#{ipCount})"
|
||||
title: "This is the #{ipCount}#{suffix} IP in the thread."
|
||||
nameBlock = $ '.nameBlock', post.nodes.info
|
||||
$.add nameBlock, [$.tn(' '), counter]
|
||||
$.addClass post.nodes.root, 'new-ip'
|
||||
@ -340,6 +340,8 @@ ThreadUpdater =
|
||||
ipCountEl.previousSibling.textContent = ipCountEl.previousSibling.textContent.replace(/\b(?:is|are)\b/, if OP.unique_ips is 1 then 'is' else 'are')
|
||||
ipCountEl.nextSibling.textContent = ipCountEl.nextSibling.textContent.replace(/\bposters?\b/, if OP.unique_ips is 1 then 'poster' else 'posters')
|
||||
|
||||
ThreadUpdater.postIDs = index
|
||||
|
||||
$.event 'ThreadUpdate',
|
||||
404: false
|
||||
threadID: ThreadUpdater.thread.fullID
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user