diff --git a/4chan_x.user.js b/4chan_x.user.js index 8ccc92849..8b9d21d5a 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -562,12 +562,15 @@ } }, toggle: function(thread) { - var a, num, pathname, prev, table, threadID, _results; + var a, backlink, num, pathname, prev, table, threadID, _i, _len, _ref, _results; threadID = thread.firstChild.id; pathname = "/" + g.BOARD + "/res/" + threadID; a = $('a.omittedposts', thread); switch (a.textContent[0]) { case '+': + if ($.config('OP Backlinks')) { + $('.op .container', thread).innerHTML = ''; + } a.textContent = a.textContent.replace('+', 'X Loading...'); return $.cache(pathname, (function() { return expandThread.parse(this, pathname, thread, a); @@ -579,11 +582,18 @@ a.textContent = a.textContent.replace('-', '+'); num = g.BOARD === 'b' ? 3 : 5; table = $.x("following::br[@clear][1]/preceding::table[" + num + "]", a); - _results = []; while ((prev = table.previousSibling) && (prev.nodeName === 'TABLE')) { - _results.push($.rm(prev)); + $.rm(prev); + } + if ($.config('OP Backlinks')) { + _ref = $$('.op a.backlink'); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + backlink = _ref[_i]; + _results.push(!d.getElementById(backlink.hash.slice(1)) ? $.rm(backlink) : void 0); + } + return _results; } - return _results; } }, parse: function(req, pathname, thread, a) { diff --git a/script.coffee b/script.coffee index df86712a6..f801b82fe 100644 --- a/script.coffee +++ b/script.coffee @@ -386,6 +386,7 @@ expandThread = switch a.textContent[0] when '+' + $('.op .container', thread).innerHTML = '' if $.config 'OP Backlinks' a.textContent = a.textContent.replace '+', 'X Loading...' $.cache pathname, (-> expandThread.parse @, pathname, thread, a) @@ -401,6 +402,10 @@ expandThread = table = $.x "following::br[@clear][1]/preceding::table[#{num}]", a while (prev = table.previousSibling) and (prev.nodeName is 'TABLE') $.rm prev + if $.config 'OP Backlinks' + for backlink in $$ '.op a.backlink' + $.rm backlink if !d.getElementById backlink.hash[1..] + parse: (req, pathname, thread, a) -> if req.status isnt 200