From 688abc4434dfaafea580d62f637de2ebb12daac0 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 16 Mar 2016 03:41:16 -0700 Subject: [PATCH] Implement UI to prune to last N replies. #767 --- src/General/Config.coffee | 4 ++ src/General/Main.coffee | 1 + src/Monitoring/PruneReplies.coffee | 72 ++++++++++++++++++++++++++++++ src/css/style.css | 6 +-- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/Monitoring/PruneReplies.coffee diff --git a/src/General/Config.coffee b/src/General/Config.coffee index c937ba950..fa8f09aa6 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -1012,3 +1012,7 @@ Config = customCooldown: 0 customCooldownEnabled: true + + pruneReplies: + 'Prune Replies': false + 'Max Replies': 1000 diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 8245bf35a..7c891c09a 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -446,6 +446,7 @@ Main = ['Keybinds', Keybinds] ['Banner', Banner] ['Flash Features', Flash] + ['Prune Replies', PruneReplies] <% if (tests_enabled) { %> ['Build Test', BuildTest] <% } %> diff --git a/src/Monitoring/PruneReplies.coffee b/src/Monitoring/PruneReplies.coffee new file mode 100644 index 000000000..eaf5ac490 --- /dev/null +++ b/src/Monitoring/PruneReplies.coffee @@ -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(' ') %> + $.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' diff --git a/src/css/style.css b/src/css/style.css index 61cf3c041..d999a8cf6 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -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;