From bc57aa561f8a94546743231b899867a2254286db Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 13 Dec 2011 15:17:48 +0100 Subject: [PATCH] Thread expansion optimizations. --- 4chan_x.user.js | 21 ++++++++------------- script.coffee | 18 ++++++++---------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index cf8637270..c6070a4f5 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -760,21 +760,18 @@ } }, parse: function(req, pathname, thread, a) { - var body, br, href, link, next, quote, reply, table, tables, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _results; + var body, br, frag, href, link, next, quote, reply, _i, _j, _len, _len2, _ref, _ref2; if (req.status !== 200) { a.textContent = "" + req.status + " " + req.statusText; $.off(a, 'click', expandThread.cb.toggle); return; } a.textContent = a.textContent.replace('X Loading...', '-'); - while ((next = a.nextSibling) && !next.clear) { - $.rm(next); - } - br = next; body = $.el('body', { innerHTML: req.responseText }); - _ref = $$('td[id]', body); + frag = d.createDocumentFragment(); + _ref = $$('.reply', body); for (_i = 0, _len = _ref.length; _i < _len; _i++) { reply = _ref[_i]; _ref2 = $$('.quotelink', reply); @@ -789,15 +786,13 @@ link = $('.quotejs', reply); link.href = "res/" + thread.firstChild.id + "#" + reply.id; link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id; + $.add(frag, reply.parentNode.parentNode.parentNode); } - tables = $$('form[name=delform] table', body); - tables.pop(); - _results = []; - for (_k = 0, _len3 = tables.length; _k < _len3; _k++) { - table = tables[_k]; - _results.push($.before(br, table)); + while ((next = a.nextSibling) && !next.clear) { + $.rm(next); } - return _results; + br = next; + return $.before(br, frag); } }; diff --git a/script.coffee b/script.coffee index 20f9f8a16..ae31643ae 100644 --- a/script.coffee +++ b/script.coffee @@ -545,15 +545,11 @@ expandThread = a.textContent = a.textContent.replace 'X Loading...', '-' - # eat everything, then replace with fresh full posts - while (next = a.nextSibling) and not next.clear #br[clear] - $.rm next - br = next - body = $.el 'body', innerHTML: req.responseText - for reply in $$ 'td[id]', body + frag = d.createDocumentFragment() + for reply in $$ '.reply', body for quote in $$ '.quotelink', reply if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes quote.pathname = pathname @@ -562,10 +558,12 @@ expandThread = link = $ '.quotejs', reply link.href = "res/#{thread.firstChild.id}##{reply.id}" link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}" - tables = $$ 'form[name=delform] table', body - tables.pop() - for table in tables - $.before br, table + $.add frag, reply.parentNode.parentNode.parentNode + # eat everything, then replace with fresh full posts + while (next = a.nextSibling) and not next.clear #br[clear] + $.rm next + br = next + $.before br, frag replyHiding = init: ->