From ac6aea9a232211de46ecc65455008d6590cd0f93 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 31 Oct 2011 00:25:57 +0100 Subject: [PATCH] Create anchor backlinks outside of the loop. --- 4chan_x.user.js | 15 ++++++++------- script.coffee | 13 +++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 42338d928..17c038894 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2336,11 +2336,10 @@ format = conf['backlink'].replace(/%id/, "' + id + '"); quoteBacklink.funk = Function('id', "return'" + format + "'"); return g.callbacks.push(function(root) { - var container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results; + var a, container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results; if (root.classList.contains('inline')) { return; } - id = $('input', root).name; quotes = {}; _ref = $$('.quotelink', root); for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -2350,6 +2349,12 @@ } quotes[qid] = quote; } + id = $('input', root).name; + a = $.el('a', { + href: "#" + id, + className: root.hidden ? 'filtered backlink' : 'backlink', + textContent: quoteBacklink.funk(id) + }); _results = []; for (qid in quotes) { if (!(el = $.id(qid))) { @@ -2358,11 +2363,7 @@ if (!conf['OP Backlinks'] && el.className === 'op') { continue; } - link = $.el('a', { - href: "#" + id, - className: root.hidden ? 'filtered backlink' : 'backlink', - textContent: quoteBacklink.funk(id) - }); + link = a.cloneNode(true); if (conf['Quote Preview']) { $.bind(link, 'mouseover', quotePreview.mouseover); $.bind(link, 'mousemove', ui.hover); diff --git a/script.coffee b/script.coffee index c72112c0c..870ee5c9e 100644 --- a/script.coffee +++ b/script.coffee @@ -1765,22 +1765,23 @@ quoteBacklink = quoteBacklink.funk = Function 'id', "return'#{format}'" g.callbacks.push (root) -> return if root.classList.contains 'inline' - # op or reply - id = $('input', root).name quotes = {} for quote in $$ '.quotelink', root #don't process >>>/b/ continue unless qid = quote.hash[1..] #duplicate quotes get overwritten quotes[qid] = quote + # op or reply + id = $('input', root).name + a = $.el 'a', + href: "##{id}" + className: if root.hidden then 'filtered backlink' else 'backlink' + textContent: quoteBacklink.funk id for qid of quotes continue unless el = $.id qid #don't backlink the op continue if !conf['OP Backlinks'] and el.className is 'op' - link = $.el 'a', - href: "##{id}" - className: if root.hidden then 'filtered backlink' else 'backlink' - textContent: quoteBacklink.funk id + link = a.cloneNode true if conf['Quote Preview'] $.bind link, 'mouseover', quotePreview.mouseover $.bind link, 'mousemove', ui.hover