Cache sauce functions.

This commit is contained in:
Nicolas Stepien 2012-02-06 14:28:30 +01:00
parent 7a2eee99f7
commit 3a13f86258
2 changed files with 30 additions and 30 deletions

View File

@ -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(/\=+$/, '');
}
});
}
};

View File

@ -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: ->