From b72083552ce833b9aa0e467c29039d3ec214362f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 30 Apr 2012 14:21:25 +0200 Subject: [PATCH] Fix Reply Hiding. --- 4chan_x.user.js | 82 +++++++++++++++++++++++-------------------------- script.coffee | 69 +++++++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 77 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 08fa1c699..328463c9d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -923,69 +923,61 @@ ReplyHiding = { init: function() { - this.td = $.el('td', { - noWrap: true, - className: 'replyhider', - innerHTML: '[ - ]' - }); return Main.callbacks.push(this.node); }, node: function(post) { - var td; - if (post["class"]) { + var button; + if (post.isInlined || /\bop\b/.test(post["class"])) { return; } - td = ReplyHiding.td.cloneNode(true); - $.on(td.firstChild, 'click', ReplyHiding.toggle); - $.replace(post.el.previousSibling, td); + button = post.el.previousElementSibling; + button.innerHTML = '[ - ]'; + $.addClass(button, 'hide_reply_button'); + $.on(button.firstChild, 'click', ReplyHiding.toggle); if (post.id in g.hiddenReplies) { - return ReplyHiding.hide(post.root); + return ReplyHiding.hide(post.root.firstElementChild); } }, toggle: function() { - var id, parent, quote, table, _i, _j, _len, _len1, _ref, _ref1; - parent = this.parentNode; - if (parent.className === 'replyhider') { - ReplyHiding.hide(parent.parentNode.parentNode.parentNode); - id = parent.nextSibling.id; - _ref = $$(".quotelink[href='#" + id + "'], .backlink[href='#" + id + "']"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - quote = _ref[_i]; - $.addClass(quote, 'filtered'); - } - g.hiddenReplies[id] = Date.now(); - } else { - table = parent.nextSibling; - table.hidden = false; - $.rm(parent); - id = table.firstChild.firstChild.lastChild.id; - _ref1 = $$(".quotelink[href$='#" + id + "'], .backlink[href='#" + id + "']"); - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - quote = _ref1[_j]; + var button, id, quote, quotes, _i, _j, _len, _len1; + button = this.parentNode; + id = button.id.slice(2); + quotes = $$(".quotelink[href$='#p" + id + "'], .backlink[href='#p" + id + "']"); + if (/\bhidden_reply\b/.test(button.className)) { + ReplyHiding.show(button); + for (_i = 0, _len = quotes.length; _i < _len; _i++) { + quote = quotes[_i]; $.removeClass(quote, 'filtered'); } delete g.hiddenReplies[id]; + } else { + ReplyHiding.hide(button); + for (_j = 0, _len1 = quotes.length; _j < _len1; _j++) { + quote = quotes[_j]; + $.addClass(quote, 'filtered'); + } + g.hiddenReplies[id] = Date.now(); } return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); }, - hide: function(table) { - var div, name, trip, uid, _ref, _ref1; - if (table.hidden) { + hide: function(button) { + if (/\bhidden_reply\b/.test(button.className)) { return; } - table.hidden = true; + $.addClass(button, 'hidden_reply'); if (!Conf['Show Stubs']) { + button.hidden = true; return; } - name = $('.commentpostername', table).textContent; - uid = ((_ref = $('.posteruid', table)) != null ? _ref.textContent : void 0) || ''; - trip = ((_ref1 = $('.postertrip', table)) != null ? _ref1.textContent : void 0) || ''; - div = $.el('div', { - className: 'stub', - innerHTML: "[ + ] " + name + " " + uid + " " + trip + "" - }); - $.on(div.firstChild, 'click', ReplyHiding.toggle); - return $.before(table, div); + return button.firstChild.textContent = "[ + ] " + ($('.nameBlock', button.nextElementSibling).textContent); + }, + show: function(button) { + $.removeClass(button, 'hidden_reply'); + if (!Conf['Show Stubs']) { + button.hidden = false; + return; + } + return button.firstChild.textContent = '[ - ]'; } }; @@ -4210,8 +4202,12 @@ a[href="javascript:;"] {\ .hide_thread_button {\ float: left;\ }\ +.hide_reply_button.hidden_reply {\ + float: none;\ +}\ \ .hidden_thread ~ *,\ +.hidden_reply + .reply,\ #content > [name=tab]:not(:checked) + div,\ #updater:not(:hover) > :not(.move),\ #qp > input, #qp .inline, .forwarded {\ diff --git a/script.coffee b/script.coffee index 86aeb0dfc..87de1ef6f 100644 --- a/script.coffee +++ b/script.coffee @@ -730,55 +730,52 @@ ExpandThread = ReplyHiding = init: -> - @td = $.el 'td', - noWrap: true - className: 'replyhider' - innerHTML: '[ - ]' Main.callbacks.push @node node: (post) -> - return if post.class - td = ReplyHiding.td.cloneNode true - $.on td.firstChild, 'click', ReplyHiding.toggle - $.replace post.el.previousSibling, td + return if post.isInlined or /\bop\b/.test post.class + button = post.el.previousElementSibling + button.innerHTML = '[ - ]' + $.addClass button, 'hide_reply_button' + $.on button.firstChild, 'click', ReplyHiding.toggle if post.id of g.hiddenReplies - ReplyHiding.hide post.root + ReplyHiding.hide post.root.firstElementChild toggle: -> - parent = @parentNode - if parent.className is 'replyhider' - ReplyHiding.hide parent.parentNode.parentNode.parentNode - id = parent.nextSibling.id - for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" - $.addClass quote, 'filtered' - g.hiddenReplies[id] = Date.now() - else - table = parent.nextSibling - table.hidden = false - $.rm parent - id = table.firstChild.firstChild.lastChild.id - for quote in $$ ".quotelink[href$='##{id}'], .backlink[href='##{id}']" + button = @parentNode + id = button.id[2..] + quotes = $$ ".quotelink[href$='#p#{id}'], .backlink[href='#p#{id}']" + if /\bhidden_reply\b/.test button.className + ReplyHiding.show button + for quote in quotes $.removeClass quote, 'filtered' delete g.hiddenReplies[id] + else + ReplyHiding.hide button + for quote in quotes + $.addClass quote, 'filtered' + g.hiddenReplies[id] = Date.now() $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies - hide: (table) -> - return if table.hidden # already hidden by filter + hide: (button) -> + return if /\bhidden_reply\b/.test button.className # already hidden once by filter + $.addClass button, 'hidden_reply' - table.hidden = true + unless Conf['Show Stubs'] + button.hidden = true + return - return unless Conf['Show Stubs'] + button.firstChild.textContent = "[ + ] #{$('.nameBlock', button.nextElementSibling).textContent}" - name = $('.commentpostername', table).textContent - uid = $('.posteruid', table)?.textContent or '' - trip = $('.postertrip', table)?.textContent or '' + show: (button) -> + $.removeClass button, 'hidden_reply' - div = $.el 'div', - className: 'stub' - innerHTML: "[ + ] #{name} #{uid} #{trip}" - $.on div.firstChild, 'click', ReplyHiding.toggle - $.before table, div + unless Conf['Show Stubs'] + button.hidden = false + return + + button.firstChild.textContent = '[ - ]' Keybinds = init: -> @@ -3233,8 +3230,12 @@ a[href="javascript:;"] { .hide_thread_button { float: left; } +.hide_reply_button.hidden_reply { + float: none; +} .hidden_thread ~ *, +.hidden_reply + .reply, #content > [name=tab]:not(:checked) + div, #updater:not(:hover) > :not(.move), #qp > input, #qp .inline, .forwarded {