diff --git a/4chan_x.user.js b/4chan_x.user.js index 706534d10..9f1cc18ff 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -922,6 +922,73 @@ } }; + ThreadHiding = { + init: function() { + 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]; + a = $.el('a', { + className: 'hide_thread_button', + innerHTML: '[ - ]', + href: 'javascript:;' + }); + $.on(a, 'click', ThreadHiding.cb); + $.prepend(thread, a); + if (thread.id.slice(1) in hiddenThreads) { + ThreadHiding.hide(thread); + } + } + }, + cb: function() { + return ThreadHiding.toggle(this.parentNode); + }, + toggle: function(thread) { + var hiddenThreads, id; + hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); + id = thread.id.slice(1); + if (thread.hidden || /\bhidden_thread\b/.test(thread.firstChild.className)) { + ThreadHiding.show(thread); + delete hiddenThreads[id]; + } else { + ThreadHiding.hide(thread); + hiddenThreads[id] = Date.now(); + } + return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); + }, + hide: function(thread) { + var a, num, opInfo, span, text; + if (!Conf['Show Stubs']) { + thread.hidden = true; + thread.nextElementSibling.hidden = true; + return; + } + if (thread.firstChild.className === 'block') { + return; + } + num = 0; + if (span = $('.summary', thread)) { + num = Number(span.textContent.match(/\d+/)); + } + num += $$('.opContainer ~ .replyContainer', thread).length; + text = num === 1 ? '1 reply' : "" + num + " replies"; + 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) { + var a; + a = $('.hide_thread_button', thread); + $.removeClass(a, 'hidden_thread'); + a.innerHTML = '[ - ]'; + thread.hidden = false; + return thread.nextElementSibling.hidden = false; + } + }; + ReplyHiding = { init: function() { return Main.callbacks.push(this.node); @@ -2373,73 +2440,6 @@ } }; - ThreadHiding = { - init: function() { - 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]; - a = $.el('a', { - className: 'hide_thread_button', - innerHTML: '[ - ]', - href: 'javascript:;' - }); - $.on(a, 'click', ThreadHiding.cb); - $.prepend(thread, a); - if (thread.id.slice(1) in hiddenThreads) { - ThreadHiding.hide(thread); - } - } - }, - cb: function() { - return ThreadHiding.toggle(this.parentNode); - }, - toggle: function(thread) { - var hiddenThreads, id; - hiddenThreads = $.get("hiddenThreads/" + g.BOARD + "/", {}); - id = thread.id.slice(1); - if (thread.hidden || /\bhidden_thread\b/.test(thread.firstChild.className)) { - ThreadHiding.show(thread); - delete hiddenThreads[id]; - } else { - ThreadHiding.hide(thread); - hiddenThreads[id] = Date.now(); - } - return $.set("hiddenThreads/" + g.BOARD + "/", hiddenThreads); - }, - hide: function(thread) { - var a, num, opInfo, span, text; - if (!Conf['Show Stubs']) { - thread.hidden = true; - thread.nextElementSibling.hidden = true; - return; - } - if (thread.firstChild.className === 'block') { - return; - } - num = 0; - if (span = $('.summary', thread)) { - num = Number(span.textContent.match(/\d+/)); - } - num += $$('.opContainer ~ .replyContainer', thread).length; - text = num === 1 ? '1 reply' : "" + num + " replies"; - 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) { - var a; - a = $('.hide_thread_button', thread); - $.removeClass(a, 'hidden_thread'); - a.innerHTML = '[ - ]'; - thread.hidden = false; - return thread.nextElementSibling.hidden = false; - } - }; - Updater = { init: function() { var checkbox, checked, dialog, html, input, name, title, _i, _len, _ref; diff --git a/script.coffee b/script.coffee index 5e5094628..f4a18e807 100644 --- a/script.coffee +++ b/script.coffee @@ -719,6 +719,62 @@ ExpandThread = $.rm next $.after a, nodes +ThreadHiding = + init: -> + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + for thread in $$ '.thread' + a = $.el 'a', + className: 'hide_thread_button' + innerHTML: '[ - ]' + href: 'javascript:;' + $.on a, 'click', ThreadHiding.cb + $.prepend thread, a + + if thread.id[1..] of hiddenThreads + ThreadHiding.hide thread + return + + cb: -> + ThreadHiding.toggle @parentNode + + toggle: (thread) -> + hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} + id = thread.id[1..] + if thread.hidden or /\bhidden_thread\b/.test thread.firstChild.className + ThreadHiding.show thread + delete hiddenThreads[id] + else + ThreadHiding.hide thread + hiddenThreads[id] = Date.now() + $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads + + hide: (thread) -> + unless Conf['Show Stubs'] + thread.hidden = true + thread.nextElementSibling.hidden = true + return + + return if thread.firstChild.className is 'block' # already hidden by filter + + 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 = $ '.hide_thread_button', thread + $.addClass a, 'hidden_thread' + a.firstChild.textContent = '[ + ]' + $.add a, $.tn " #{opInfo} (#{text})" + + show: (thread) -> + a = $ '.hide_thread_button', thread + $.removeClass a, 'hidden_thread' + a.innerHTML = '[ - ]' + thread.hidden = false + thread.nextElementSibling.hidden = false + ReplyHiding = init: -> Main.callbacks.push @node @@ -1871,62 +1927,6 @@ Options = Unread.update true @nextElementSibling.innerHTML = " " -ThreadHiding = - init: -> - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} - for thread in $$ '.thread' - a = $.el 'a', - className: 'hide_thread_button' - innerHTML: '[ - ]' - href: 'javascript:;' - $.on a, 'click', ThreadHiding.cb - $.prepend thread, a - - if thread.id[1..] of hiddenThreads - ThreadHiding.hide thread - return - - cb: -> - ThreadHiding.toggle @parentNode - - toggle: (thread) -> - hiddenThreads = $.get "hiddenThreads/#{g.BOARD}/", {} - id = thread.id[1..] - if thread.hidden or /\bhidden_thread\b/.test thread.firstChild.className - ThreadHiding.show thread - delete hiddenThreads[id] - else - ThreadHiding.hide thread - hiddenThreads[id] = Date.now() - $.set "hiddenThreads/#{g.BOARD}/", hiddenThreads - - hide: (thread) -> - unless Conf['Show Stubs'] - thread.hidden = true - thread.nextElementSibling.hidden = true - return - - return if thread.firstChild.className is 'block' # already hidden by filter - - 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 = $ '.hide_thread_button', thread - $.addClass a, 'hidden_thread' - a.firstChild.textContent = '[ + ]' - $.add a, $.tn " #{opInfo} (#{text})" - - show: (thread) -> - a = $ '.hide_thread_button', thread - $.removeClass a, 'hidden_thread' - a.innerHTML = '[ - ]' - thread.hidden = false - thread.nextElementSibling.hidden = false - Updater = init: -> html = "
-#{Conf['Interval']}
"