From 7751f7abd1f815e4158113c0c8d419a9d24f12c0 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 1 May 2012 18:41:44 +0200 Subject: [PATCH] Thread Expansions fix and improvement. --- 4chan_x.user.js | 18 ++++++++++-------- script.coffee | 12 ++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index cf4194cf8..706534d10 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -837,12 +837,12 @@ return _results; }, toggle: function(thread) { - var a, backlink, container, div, next, num, pathname, _i, _len, _ref, _results; + var a, backlink, container, num, pathname, replies, reply, _i, _j, _len, _len1, _ref, _results; pathname = "/" + g.BOARD + "/res/" + thread.id.slice(1); a = $('.summary', thread); switch (a.textContent[0]) { case '+': - if (container = $('.container', thread.firstElementChild)) { + if (container = $('.container', a.previousElementSibling)) { $.rm(container); } a.textContent = a.textContent.replace('+', '\u00d7 Loading...'); @@ -865,14 +865,16 @@ return 5; } })(); - div = $.x("following-sibling::div[last()]/preceding-sibling::div[" + (num - 1) + "]", a); - while ((next = a.nextSibling) && next !== div) { - $.rm(next); + replies = $$('.replyContainer', thread); + replies.splice(replies.length - num, num); + for (_i = 0, _len = replies.length; _i < _len; _i++) { + reply = replies[_i]; + $.rm(reply); } _ref = $$('.backlink', a.previousElementSibling); _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - backlink = _ref[_i]; + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { + backlink = _ref[_j]; if (!$.id(backlink.hash.slice(1))) { _results.push($.rm(backlink)); } else { @@ -4130,7 +4132,7 @@ }, preParse: function(node) { var el, fileInfo, img, klass, post; - el = node.lastElementChild; + el = $('.post', node); klass = el.className; post = { root: node, diff --git a/script.coffee b/script.coffee index 8e0251ea2..5e5094628 100644 --- a/script.coffee +++ b/script.coffee @@ -667,7 +667,7 @@ ExpandThread = switch a.textContent[0] when '+' - if container = $ '.container', thread.firstElementChild + if container = $ '.container', a.previousElementSibling $.rm container a.textContent = a.textContent.replace '+', '\u00d7 Loading...' $.cache pathname, -> ExpandThread.parse @, pathname, thread, a @@ -683,13 +683,13 @@ ExpandThread = when 'b', 'vg' then 3 when 't' then 1 else 5 - div = $.x "following-sibling::div[last()]/preceding-sibling::div[#{num - 1}]", a - while (next = a.nextSibling) and next isnt div - $.rm next + replies = $$ '.replyContainer', thread + replies.splice replies.length - num, num + for reply in replies + $.rm reply for backlink in $$ '.backlink', a.previousElementSibling $.rm backlink unless $.id backlink.hash[1..] - parse: (req, pathname, thread, a) -> if req.status isnt 200 a.textContent = "#{req.status} #{req.statusText}" @@ -3171,7 +3171,7 @@ Main = window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js" preParse: (node) -> - el = node.lastElementChild + el = $ '.post', node klass = el.className post = root: node