From a3c00a57924e11f343244a4216e917c8a35b9035 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 30 Apr 2012 11:50:03 +0200 Subject: [PATCH] Fix Thread Hiding. --- 4chan_x.user.js | 68 +++++++++++++++++++++++-------------------------- script.coffee | 65 ++++++++++++++++++++++------------------------ 2 files changed, 63 insertions(+), 70 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 07aafcfc2..08fa1c699 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -637,7 +637,7 @@ if (result === true) { if (isOP) { if (!g.REPLY) { - ThreadHiding.hide(post.el.parentNode); + ThreadHiding.hide(post.root.parentNode); } else { continue; } @@ -2369,31 +2369,31 @@ ThreadHiding = { init: function() { - var a, hiddenThreads, op, thread, _i, _len, _ref; + var a, hiddenThreads, thread, _i, _len, _ref; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); _ref = $$('.thread'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { thread = _ref[_i]; - op = $('.op', thread); a = $.el('a', { - textContent: '[ - ]', + className: 'hide_thread_button', + innerHTML: '[ - ]', href: 'javascript:;' }); $.on(a, 'click', ThreadHiding.cb); - $.prepend(op, a); - if (op.id in hiddenThreads) { + $.prepend(thread, a); + if (thread.id.slice(1) in hiddenThreads) { ThreadHiding.hide(thread); } } }, cb: function() { - return ThreadHiding.toggle(this.parentNode.parentNode); + return ThreadHiding.toggle(this.parentNode); }, toggle: function(thread) { var hiddenThreads, id; hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); - id = $('.op', thread).id; - if (thread.hidden || thread.firstChild.className === 'block') { + id = thread.id.slice(1); + if (thread.hidden || /\bhidden_thread\b/.test(thread.firstChild.className)) { ThreadHiding.show(thread); delete hiddenThreads[id]; } else { @@ -2403,40 +2403,34 @@ return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); }, hide: function(thread) { - var a, div, name, num, op, span, text, trip, uid, _ref, _ref1; + var a, num, opInfo, span, text; if (!Conf['Show Stubs']) { thread.hidden = true; - thread.nextSibling.hidden = true; + thread.nextElementSibling.hidden = true; return; } if (thread.firstChild.className === 'block') { return; } num = 0; - if (span = $('.omittedposts', thread)) { - num = Number(span.textContent.match(/\d+/)[0]); + if (span = $('.summary', thread)) { + num = Number(span.textContent.match(/\d+/)); } - num += $$('.op ~ table', thread).length; + num += $$('.opContainer ~ .replyContainer', thread).length; text = num === 1 ? '1 reply' : "" + num + " replies"; - op = $('.op', thread); - name = $('.postername', op).textContent; - uid = ((_ref = $('.posteruid', op)) != null ? _ref.textContent : void 0) || ''; - trip = ((_ref1 = $('.postertrip', op)) != null ? _ref1.textContent : void 0) || ''; - a = $.el('a', { - innerHTML: "[ + ] " + name + " " + uid + " " + trip + " (" + text + ")", - href: 'javascript:;' - }); - $.on(a, 'click', ThreadHiding.cb); - div = $.el('div', { - className: 'block' - }); - $.add(div, a); - return $.prepend(thread, div); + opInfo = $('.op > .postInfo > .nameBlock', thread).textContent; + a = $('.hide_thread_button', thread); + $.addClass(a, 'hidden_thread'); + a.firstChild.textContent = '[ + ]'; + return $.add(a, $.tn(" " + opInfo + " (" + text + ")")); }, - show: function(thread, id) { - $.rm($('.block', thread)); + show: function(thread) { + var a; + a = $('.hide_thread_button', thread); + $.removeClass(a, 'hidden_thread'); + a.innerHTML = '[ - ]'; thread.hidden = false; - return thread.nextSibling.hidden = false; + return thread.nextElementSibling.hidden = false; } }; @@ -4066,9 +4060,7 @@ } } else { if (Conf['Thread Hiding']) { - setTimeout(function() { - return ThreadHiding.init(); - }); + ThreadHiding.init(); } if (Conf['Thread Expansion']) { setTimeout(function() { @@ -4215,11 +4207,15 @@ a[href="javascript:;"] {\ text-decoration: none;\ }\ \ -.block ~ *,\ +.hide_thread_button {\ + float: left;\ +}\ +\ +.hidden_thread ~ *,\ #content > [name=tab]:not(:checked) + div,\ #updater:not(:hover) > :not(.move),\ #qp > input, #qp .inline, .forwarded {\ - display: none;\ + display: none !important;\ }\ \ h1 {\ diff --git a/script.coffee b/script.coffee index b5c1af466..86aeb0dfc 100644 --- a/script.coffee +++ b/script.coffee @@ -528,7 +528,7 @@ Filter = if result is true if isOP unless g.REPLY - ThreadHiding.hide post.el.parentNode + ThreadHiding.hide post.root.parentNode else continue else @@ -1879,24 +1879,24 @@ ThreadHiding = init: -> hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} for thread in $$ '.thread' - op = $ '.op', thread a = $.el 'a', - textContent: '[ - ]' + className: 'hide_thread_button' + innerHTML: '[ - ]' href: 'javascript:;' $.on a, 'click', ThreadHiding.cb - $.prepend op, a + $.prepend thread, a - if op.id of hiddenThreads + if thread.id[1..] of hiddenThreads ThreadHiding.hide thread return cb: -> - ThreadHiding.toggle @parentNode.parentNode + ThreadHiding.toggle @parentNode toggle: (thread) -> hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} - id = $('.op', thread).id - if thread.hidden or thread.firstChild.className is 'block' + id = thread.id[1..] + if thread.hidden or /\bhidden_thread\b/.test thread.firstChild.className ThreadHiding.show thread delete hiddenThreads[id] else @@ -1907,36 +1907,29 @@ ThreadHiding = hide: (thread) -> unless Conf['Show Stubs'] thread.hidden = true - thread.nextSibling.hidden = true + thread.nextElementSibling.hidden = true return return if thread.firstChild.className is 'block' # already hidden by filter - num = 0 - if span = $ '.omittedposts', thread - num = Number span.textContent.match(/\d+/)[0] - num += $$('.op ~ table', thread).length - text = if num is 1 then '1 reply' else "#{num} replies" - op = $ '.op', thread - name = $('.postername', op).textContent - uid = $('.posteruid', op)?.textContent or '' - trip = $('.postertrip', op)?.textContent or '' + num = 0 + if span = $ '.summary', thread + num = Number span.textContent.match /\d+/ + num += $$('.opContainer ~ .replyContainer', thread).length + text = if num is 1 then '1 reply' else "#{num} replies" + opInfo = $('.op > .postInfo > .nameBlock', thread).textContent - a = $.el 'a', - innerHTML: "[ + ] #{name} #{uid} #{trip} (#{text})" - href: 'javascript:;' - $.on a, 'click', ThreadHiding.cb + a = $ '.hide_thread_button', thread + $.addClass a, 'hidden_thread' + a.firstChild.textContent = '[ + ]' + $.add a, $.tn " #{opInfo} (#{text})" - div = $.el 'div', - className: 'block' - - $.add div, a - $.prepend thread, div - - show: (thread, id) -> - $.rm $ '.block', thread + show: (thread) -> + a = $ '.hide_thread_button', thread + $.removeClass a, 'hidden_thread' + a.innerHTML = '[ - ]' thread.hidden = false - thread.nextSibling.hidden = false + thread.nextElementSibling.hidden = false Updater = init: -> @@ -3134,7 +3127,7 @@ Main = else #not reply if Conf['Thread Hiding'] - setTimeout -> ThreadHiding.init() + ThreadHiding.init() if Conf['Thread Expansion'] setTimeout -> ExpandThread.init() @@ -3237,11 +3230,15 @@ a[href="javascript:;"] { text-decoration: none; } -.block ~ *, +.hide_thread_button { + float: left; +} + +.hidden_thread ~ *, #content > [name=tab]:not(:checked) + div, #updater:not(:hover) > :not(.move), #qp > input, #qp .inline, .forwarded { - display: none; + display: none !important; } h1 {