Use % for sauce parameters for consistency with other rice settings.

Create only one sauce element to clone, instead of one per closure.
Don't use a closure, just a simple Function.
This also fixes the parameters in the optional text.
This commit is contained in:
Nicolas Stepien 2012-09-17 01:31:10 +02:00
parent 0897fe5c5b
commit 92bece87ea
2 changed files with 35 additions and 44 deletions

View File

@ -165,7 +165,7 @@
filesize: [''].join('\n'), filesize: [''].join('\n'),
md5: [''].join('\n') md5: [''].join('\n')
}, },
sauces: ['http://iqdb.org/?url=$turl', 'http://www.google.com/searchbyimage?image_url=$turl', '#http://tineye.com/search?url=$turl', '#http://saucenao.com/search.php?db=999&url=$turl', '#http://3d.iqdb.org/?url=$turl', '#http://regex.info/exif.cgi?imgurl=$url', '# uploaders:', '#http://imgur.com/upload?url=$url;text:Upload to imgur', '#http://omploader.org/upload?url1=$url;text:Upload to omploader', '# "View Same" in archives:', '#http://archive.foolz.us/_/search/image/$md5/;text:View same on foolz', '#http://archive.foolz.us/$board/search/image/$md5/;text:View same on foolz /$board/', '#https://archive.installgentoo.net/$board/image/$md5;text:View same on installgentoo /$board/'].join('\n'), sauces: ['http://iqdb.org/?url=%turl', 'http://www.google.com/searchbyimage?image_url=%turl', '#http://tineye.com/search?url=%turl', '#http://saucenao.com/search.php?db=999&url=%turl', '#http://3d.iqdb.org/?url=%turl', '#http://regex.info/exif.cgi?imgurl=%url', '# uploaders:', '#http://imgur.com/upload?url=%url;text:Upload to imgur', '#http://omploader.org/upload?url1=%url;text:Upload to omploader', '# "View Same" in archives:', '#//archive.foolz.us/_/search/image/%md5/;text:View same on foolz', '#//archive.foolz.us/%board/search/image/%md5/;text:View same on foolz /%board/', '#//archive.installgentoo.net/%board/image/%md5;text:View same on installgentoo /%board/'].join('\n'),
time: '%m/%d/%y(%a)%H:%M:%S', time: '%m/%d/%y(%a)%H:%M:%S',
backlink: '>>%id', backlink: '>>%id',
fileInfo: '%l (%p%s, %r)', fileInfo: '%l (%p%s, %r)',
@ -2328,22 +2328,25 @@
return; return;
} }
this.links = links; this.links = links;
this.link = $.el('a', {
target: '_blank'
});
return Post.prototype.callbacks.push({ return Post.prototype.callbacks.push({
name: 'Sauce', name: 'Sauce',
cb: this.node cb: this.node
}); });
}, },
createSauceLink: function(link) { createSauceLink: function(link) {
var el, href, m, text; var m, text;
link = link.replace(/\$(turl|url|md5|board)/g, function(parameter) { link = link.replace(/%(t?url|md5|board)/g, function(parameter) {
switch (parameter) { switch (parameter) {
case '$turl': case '%turl':
return "' + post.file.thumbURL + '"; return "' + post.file.thumbURL + '";
case '$url': case '%url':
return "' + post.file.URL + '"; return "' + post.file.URL + '";
case '$md5': case '%md5':
return "' + encodeURIComponent(post.file.MD5) + '"; return "' + encodeURIComponent(post.file.MD5) + '";
case '$board': case '%board':
return "' + post.board + '"; return "' + post.board + '";
default: default:
return parameter; return parameter;
@ -2351,17 +2354,7 @@
}); });
text = (m = link.match(/;text:(.+)$/)) ? m[1] : link.match(/(\w+)\.\w+\//)[1]; text = (m = link.match(/;text:(.+)$/)) ? m[1] : link.match(/(\w+)\.\w+\//)[1];
link = link.replace(/;text:.+$/, ''); link = link.replace(/;text:.+$/, '');
href = Function('post', "return '" + link + "'"); return Function('post', 'a', "a.href = '" + link + "';\na.textContent = '" + text + "';\nreturn a;");
el = $.el('a', {
target: '_blank',
textContent: text
});
return function(post) {
var a;
a = el.cloneNode(true);
a.href = href(post);
return a;
};
}, },
node: function() { node: function() {
var link, nodes, _i, _len, _ref; var link, nodes, _i, _len, _ref;
@ -2372,7 +2365,7 @@
_ref = Sauce.links; _ref = Sauce.links;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
link = _ref[_i]; link = _ref[_i];
nodes.push($.tn('\u00A0'), link(this)); nodes.push($.tn('\u00A0'), link(this, Sauce.link.cloneNode(true)));
} }
return $.add(this.file.info, nodes); return $.add(this.file.info, nodes);
} }

View File

@ -106,19 +106,19 @@ Config =
'' ''
].join '\n' ].join '\n'
sauces: [ sauces: [
'http://iqdb.org/?url=$turl' 'http://iqdb.org/?url=%turl'
'http://www.google.com/searchbyimage?image_url=$turl' 'http://www.google.com/searchbyimage?image_url=%turl'
'#http://tineye.com/search?url=$turl' '#http://tineye.com/search?url=%turl'
'#http://saucenao.com/search.php?db=999&url=$turl' '#http://saucenao.com/search.php?db=999&url=%turl'
'#http://3d.iqdb.org/?url=$turl' '#http://3d.iqdb.org/?url=%turl'
'#http://regex.info/exif.cgi?imgurl=$url' '#http://regex.info/exif.cgi?imgurl=%url'
'# uploaders:' '# uploaders:'
'#http://imgur.com/upload?url=$url;text:Upload to imgur' '#http://imgur.com/upload?url=%url;text:Upload to imgur'
'#http://omploader.org/upload?url1=$url;text:Upload to omploader' '#http://omploader.org/upload?url1=%url;text:Upload to omploader'
'# "View Same" in archives:' '# "View Same" in archives:'
'#http://archive.foolz.us/_/search/image/$md5/;text:View same on foolz' '#//archive.foolz.us/_/search/image/%md5/;text:View same on foolz'
'#http://archive.foolz.us/$board/search/image/$md5/;text:View same on foolz /$board/' '#//archive.foolz.us/%board/search/image/%md5/;text:View same on foolz /%board/'
'#https://archive.installgentoo.net/$board/image/$md5;text:View same on installgentoo /$board/' '#//archive.installgentoo.net/%board/image/%md5;text:View same on installgentoo /%board/'
].join '\n' ].join '\n'
time: '%m/%d/%y(%a)%H:%M:%S' time: '%m/%d/%y(%a)%H:%M:%S'
backlink: '>>%id' backlink: '>>%id'
@ -2119,38 +2119,36 @@ Sauce =
links.push @createSauceLink link.trim() links.push @createSauceLink link.trim()
return unless links.length return unless links.length
@links = links @links = links
@link = $.el 'a', target: '_blank'
Post::callbacks.push Post::callbacks.push
name: 'Sauce' name: 'Sauce'
cb: @node cb: @node
createSauceLink: (link) -> createSauceLink: (link) ->
link = link.replace /\$(turl|url|md5|board)/g, (parameter) -> link = link.replace /%(t?url|md5|board)/g, (parameter) ->
switch parameter switch parameter
when '$turl' when '%turl'
"' + post.file.thumbURL + '" "' + post.file.thumbURL + '"
when '$url' when '%url'
"' + post.file.URL + '" "' + post.file.URL + '"
when '$md5' when '%md5'
"' + encodeURIComponent(post.file.MD5) + '" "' + encodeURIComponent(post.file.MD5) + '"
when '$board' when '%board'
"' + post.board + '" "' + post.board + '"
else else
parameter parameter
text = if m = link.match(/;text:(.+)$/) then m[1] else link.match(/(\w+)\.\w+\//)[1] text = if m = link.match(/;text:(.+)$/) then m[1] else link.match(/(\w+)\.\w+\//)[1]
link = link.replace /;text:.+$/, '' link = link.replace /;text:.+$/, ''
href = Function 'post', "return '#{link}'" Function 'post', 'a', """
el = $.el 'a', a.href = '#{link}';
target: '_blank' a.textContent = '#{text}';
textContent: text return a;
(post) -> """
a = el.cloneNode true
a.href = href post
a
node: -> node: ->
return if @isClone or !@file return if @isClone or !@file
nodes = [] nodes = []
for link in Sauce.links for link in Sauce.links
# \u00A0 is nbsp # \u00A0 is nbsp
nodes.push $.tn('\u00A0'), link @ nodes.push $.tn('\u00A0'), link @, Sauce.link.cloneNode true
$.add @file.info, nodes $.add @file.info, nodes
RevealSpoilers = RevealSpoilers =