From c03072f0e055d17dd47be8175376dd040c9d5687 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 29 Dec 2010 13:39:35 -0800 Subject: [PATCH] add replies in correct order --- 4chan_x.coffee | 20 ++++++++++++-------- 4chan_x.js | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/4chan_x.coffee b/4chan_x.coffee index 39f5ea8b5..02aa96c57 100644 --- a/4chan_x.coffee +++ b/4chan_x.coffee @@ -832,20 +832,24 @@ updateCallback = -> body = n 'body', innerHTML: @responseText replies = $$ 'td.reply', body - root = $('br[clear]').previousElementSibling - if reply = $ 'td.reply, td.replyhl', root + root = $('br[clear]') + if reply = $ 'td.reply, td.replyhl', root.previousElementSibling id = Number reply.id else id = 0 - i = 0 + arr = [] while (reply = replies.pop()) and (Number reply.id > id) - table = x 'ancestor::table', reply - inAfter root, table - ++i + arr.push reply - count.textContent = "+#{i}" - count.className = if i is 0 then '' else 'new' + l = arr.length + count.textContent = "+#{l}" + count.className = if l is 0 then '' else 'new' + + #insert replies in order, so backlinks resolve + while reply = arr.pop() + table = x 'ancestor::table', reply + inBefore root, table timer.textContent = -1 * GM_getValue 'Interval', 10 diff --git a/4chan_x.js b/4chan_x.js index f21ba7c13..41f83d800 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1070,7 +1070,7 @@ return r; }; updateCallback = function() { - var body, count, i, id, input, replies, reply, root, s, table, timer, _i, _len, _ref; + var arr, body, count, id, input, l, replies, reply, root, s, table, timer, _i, _len, _ref; count = $('#updater #count'); timer = $('#updater #timer'); if (this.status === 404) { @@ -1098,20 +1098,23 @@ innerHTML: this.responseText }); replies = $$('td.reply', body); - root = $('br[clear]').previousElementSibling; - if (reply = $('td.reply, td.replyhl', root)) { + root = $('br[clear]'); + if (reply = $('td.reply, td.replyhl', root.previousElementSibling)) { id = Number(reply.id); } else { id = 0; } - i = 0; + arr = []; while ((reply = replies.pop()) && (Number(reply.id > id))) { - table = x('ancestor::table', reply); - inAfter(root, table); - ++i; + arr.push(reply); + } + l = arr.length; + count.textContent = "+" + l; + count.className = l === 0 ? '' : 'new'; + while (reply = arr.pop()) { + table = x('ancestor::table', reply); + inBefore(root, table); } - count.textContent = "+" + i; - count.className = i === 0 ? '' : 'new'; return timer.textContent = -1 * GM_getValue('Interval', 10); }; updateFavicon = function() {