diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 2cd2abd02..d28934899 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -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': [ diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 970227583..ee10abd8f 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -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] diff --git a/src/Monitoring/MarkNewIPs.coffee b/src/Monitoring/MarkNewIPs.coffee new file mode 100644 index 000000000..7726a8e80 --- /dev/null +++ b/src/Monitoring/MarkNewIPs.coffee @@ -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' diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index b6dec04f1..b94cab67f 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -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