From ee2c5000c227c4c2b803210d87e955474c1ef348 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 9 May 2011 18:21:21 +0200 Subject: [PATCH] Fix multiple backlinks --- 4chan_x.js | 31 +++++++++++++++++++++++++------ script.coffee | 7 ++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index ee8ede328..1bbb6edff 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1681,16 +1681,35 @@ return g.callbacks.push(quoteBacklink.node); }, node: function(root) { - var el, id, link, quote, _i, _len, _ref, _results; + var backlink, el, id, link, nogood, quote, _i, _len, _ref, _results; _ref = $$('a.quotelink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - _results.push((el = d.getElementById(quote.textContent.slice(2))) ? (id = quote.parentNode.parentNode.parentNode.id, link = $.el('a', { - href: '#' + id, - className: 'backlink', - textContent: '>>' + id - }), el.className !== 'op' ? $.before($('br, blockquote', el), link) : void 0) : void 0); + _results.push((function() { + var _j, _len2, _ref2; + if (el = d.getElementById(quote.textContent.slice(2))) { + id = quote.parentNode.parentNode.parentNode.id; + link = $.el('a', { + href: '#' + id, + className: 'backlink', + textContent: '>>' + id + }); + if (el.className !== 'op') { + nogood = 0; + _ref2 = $$('a.backlink', el); + for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { + backlink = _ref2[_j]; + if (backlink.textContent === '>>' + id) { + nogood = 1; + } + } + if (!nogood) { + return $.before($('br, blockquote', el), link); + } + } + } + })()); } return _results; } diff --git a/script.coffee b/script.coffee index 41667573c..dc1908eb0 100644 --- a/script.coffee +++ b/script.coffee @@ -1353,7 +1353,12 @@ quoteBacklink = className: 'backlink' textContent: '>>'+id unless el.className is 'op' - $.before $('br, blockquote', el), link + nogood = 0 + for backlink in $$ 'a.backlink', el + if backlink.textContent is '>>'+id + nogood = 1 + unless nogood + $.before $('br, blockquote', el), link quotePreview = init: ->