From 3a13f862587a9e624dc4900af65e879bb4ce860e Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 6 Feb 2012 14:28:30 +0100 Subject: [PATCH] Cache sauce functions. --- 4chan_x.user.js | 34 +++++++++++++++++----------------- script.coffee | 26 +++++++++++++------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 278c5ea2c..60379c816 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2588,12 +2588,24 @@ sauce = { init: function() { - var link, links, _i, _len; + var domain, fc, link, links, _i, _len; links = conf['sauces'].match(/^[^#].+$/gm); + if (!links.length) return; this.links = []; for (_i = 0, _len = links.length; _i < _len; _i++) { link = links[_i]; - this.links.push([link, link.match(/(\w+)\.\w+\//)[1]]); + domain = link.match(/(\w+)\.\w+\//)[1]; + fc = link.replace(/\$\d/, function(fragment) { + switch (fragment) { + case '$1': + return "' + img.src + '"; + case '$2': + return "' + img.parentNode.href + '"; + case '$3': + return "' + img.getAttribute('md5').replace(/\=*$/, '') + '"; + } + }); + this.links.push([Function('img', "return '" + fc + "'"), domain]); } return g.callbacks.push(this.node); }, @@ -2605,24 +2617,12 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { link = _ref[_i]; a = $.el('a', { - textContent: link[1], - href: sauce.href(link[0], img), - target: '_blank' + href: link[0](img), + target: '_blank', + textContent: link[1] }); $.add(span, $.tn(' '), a); } - }, - href: function(link, img) { - return link.replace(/\$\d/, function(fragment) { - switch (fragment) { - case '$1': - return img.src; - case '$2': - return img.parentNode.href; - case '$3': - return img.getAttribute('md5').replace(/\=+$/, ''); - } - }); } }; diff --git a/script.coffee b/script.coffee index d4f82c505..c2cdf082d 100644 --- a/script.coffee +++ b/script.coffee @@ -2051,31 +2051,31 @@ anonymize = sauce = init: -> - # return unless links = conf['sauces'].match /^[^#].+$/gm + return unless links.length @links = [] for link in links - @links.push [link, link.match(/(\w+)\.\w+\//)[1]] + domain = link.match(/(\w+)\.\w+\//)[1] + fc = link.replace /\$\d/, (fragment) -> + switch fragment + when '$1' + "' + img.src + '" + when '$2' + "' + img.parentNode.href + '" + when '$3' + "' + img.getAttribute('md5').replace(/\=*$/, '') + '" + @links.push [Function('img', "return '#{fc}'"), domain] g.callbacks.push @node node: (root) -> return if root.className is 'inline' or not span = $ '.filesize', root img = $ 'img', root for link in sauce.links a = $.el 'a', - textContent: link[1] - href: sauce.href link[0], img + href: link[0] img target: '_blank' + textContent: link[1] $.add span, $.tn(' '), a return - href: (link, img) -> - link.replace /\$\d/, (fragment) -> - switch fragment - when '$1' - img.src - when '$2' - img.parentNode.href - when '$3' - img.getAttribute('md5').replace /\=+$/, '' revealSpoilers = init: ->