Implement UI to prune to last N replies. #767
This commit is contained in:
parent
7bf048ce85
commit
688abc4434
@ -1012,3 +1012,7 @@ Config =
|
||||
|
||||
customCooldown: 0
|
||||
customCooldownEnabled: true
|
||||
|
||||
pruneReplies:
|
||||
'Prune Replies': false
|
||||
'Max Replies': 1000
|
||||
|
||||
@ -446,6 +446,7 @@ Main =
|
||||
['Keybinds', Keybinds]
|
||||
['Banner', Banner]
|
||||
['Flash Features', Flash]
|
||||
['Prune Replies', PruneReplies]
|
||||
<% if (tests_enabled) { %>
|
||||
['Build Test', BuildTest]
|
||||
<% } %>
|
||||
|
||||
72
src/Monitoring/PruneReplies.coffee
Normal file
72
src/Monitoring/PruneReplies.coffee
Normal file
@ -0,0 +1,72 @@
|
||||
PruneReplies =
|
||||
init: ->
|
||||
return unless g.VIEW is 'thread' and not Conf['Quote Threading']
|
||||
|
||||
label = UI.checkbox 'Prune Replies', 'Show Last'
|
||||
el = $.el 'span',
|
||||
title: 'Maximum number of replies to show.'
|
||||
,
|
||||
<%= html(' <input type="number" name="Max Replies" min="0" step="1" value="${Conf["Max Replies"]}" class="field">') %>
|
||||
$.prepend el, label
|
||||
|
||||
@inputs =
|
||||
enabled: label.firstElementChild
|
||||
replies: el.lastElementChild
|
||||
|
||||
$.on @inputs.enabled, 'change', $.cb.checked
|
||||
$.on @inputs.replies, 'change', $.cb.value
|
||||
|
||||
Header.menu.addEntry
|
||||
el: el
|
||||
order: 190
|
||||
|
||||
Thread.callbacks.push
|
||||
name: 'Prune Replies'
|
||||
cb: @node
|
||||
|
||||
position: 0
|
||||
hidden: 0
|
||||
total: 0
|
||||
|
||||
node: ->
|
||||
PruneReplies.thread = @
|
||||
PruneReplies.total = @posts.keys.length - 1
|
||||
$.on PruneReplies.inputs.enabled, 'change', PruneReplies.setEnabled
|
||||
$.on PruneReplies.inputs.enabled, 'change', PruneReplies.update
|
||||
if Conf['Prune Replies']
|
||||
PruneReplies.setEnabled()
|
||||
PruneReplies.update()
|
||||
|
||||
setEnabled: ->
|
||||
PruneReplies.container or= $.frag()
|
||||
onOff = if Conf['Prune Replies'] then $.on else $.off
|
||||
onOff PruneReplies.inputs.replies, 'change', PruneReplies.update
|
||||
onOff d, 'ThreadUpdate', PruneReplies.update
|
||||
|
||||
update: (e) ->
|
||||
if e and e.type is 'ThreadUpdate' and not e.detail[404]
|
||||
PruneReplies.total += e.detail.newPosts.length
|
||||
|
||||
hidden2 = if Conf['Prune Replies']
|
||||
Math.max(PruneReplies.total - +Conf["Max Replies"], 0)
|
||||
else
|
||||
0
|
||||
|
||||
{posts, OP} = PruneReplies.thread
|
||||
|
||||
if PruneReplies.hidden < hidden2
|
||||
while PruneReplies.hidden < hidden2 and PruneReplies.position < posts.keys.length
|
||||
post = posts[posts.keys[PruneReplies.position++]]
|
||||
if post.isReply and not post.isFetchedQuote
|
||||
$.add PruneReplies.container, post.nodes.root
|
||||
PruneReplies.hidden++
|
||||
|
||||
else if PruneReplies.hidden > hidden2
|
||||
frag = $.frag()
|
||||
while PruneReplies.hidden > hidden2 and PruneReplies.position > 0
|
||||
post = posts[posts.keys[--PruneReplies.position]]
|
||||
if post.isReply and not post.isFetchedQuote
|
||||
$.prepend frag, post.nodes.root
|
||||
PruneReplies.hidden--
|
||||
$.after OP.nodes.root, frag
|
||||
$.event 'PostsInserted'
|
||||
@ -1759,6 +1759,9 @@ a:only-of-type > .remove {
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
.entry input[type="number"] {
|
||||
width: 4em;
|
||||
}
|
||||
.entry.has-shortcut-text {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@ -2077,9 +2080,6 @@ grunt.file.expand('src/Linkification/icons/*.png').map(function(file) {
|
||||
:root.gal-hide-thumbnails:.gal-fit-height:not(.gal-pdf) .gal-count {
|
||||
right: 28px !important;
|
||||
}
|
||||
.field[name="Slide Delay"] {
|
||||
width: 4em;
|
||||
}
|
||||
:root.gallery-open.fixed #header-bar:not(.autohide),
|
||||
:root.gallery-open.fixed #header-bar:not(.autohide) #shortcuts .fa::before {
|
||||
visibility: hidden;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user