Fix sauces to work with inlined archived posts.

This commit is contained in:
Nicolas Stepien 2012-06-17 22:36:21 +02:00
parent 1a078f6a0e
commit 4f7de6d3b5
2 changed files with 16 additions and 12 deletions

View File

@ -2825,33 +2825,35 @@
link = link.replace(/(\$\d)/g, function(parameter) { link = link.replace(/(\$\d)/g, function(parameter) {
switch (parameter) { switch (parameter) {
case '$1': case '$1':
return "http://thumbs.4chan.org' + img.pathname.replace(/src(\\/\\d+).+$/, 'thumb$1s.jpg') + '"; return "' + (isArchived ? img.firstChild.src : 'http://thumbs.4chan.org' + img.pathname.replace(/src(\\/\\d+).+$/, 'thumb$1s.jpg')) + '";
case '$2': case '$2':
return "' + img.href + '"; return "' + img.href + '";
case '$3': case '$3':
return "' + encodeURIComponent(img.firstChild.dataset.md5) + '"; return "' + encodeURIComponent(img.firstChild.dataset.md5) + '";
case '$4': case '$4':
return g.BOARD; return g.BOARD;
default:
return parameter;
} }
}); });
domain = (m = link.match(/;text:(.+)$/)) ? m[1] : link.match(/(\w+)\.\w+\//)[1]; domain = (m = link.match(/;text:(.+)$/)) ? m[1] : link.match(/(\w+)\.\w+\//)[1];
href = link.replace(/;text:.+$/, ''); href = link.replace(/;text:.+$/, '');
href = Function('img', "return '" + href + "'"); href = Function('img', 'isArchived', "return '" + href + "'");
el = $.el('a', { el = $.el('a', {
target: '_blank', target: '_blank',
textContent: domain textContent: domain
}); });
return function(img) { return function(img, isArchived) {
var a; var a;
a = el.cloneNode(true); a = el.cloneNode(true);
a.href = href(img); a.href = href(img, isArchived);
return a; return a;
}; };
}, },
node: function(post) { node: function(post) {
var img, link, nodes, _i, _len, _ref; var img, link, nodes, _i, _len, _ref;
img = post.img; img = post.img;
if (post.isInlined && !post.isCrosspost || post.isArchived || !img) { if (post.isInlined && !post.isCrosspost || !img) {
return; return;
} }
img = img.parentNode; img = img.parentNode;
@ -2859,7 +2861,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(img)); nodes.push($.tn('\u00A0'), link(img, post.isArchived));
} }
return $.add(post.fileInfo, nodes); return $.add(post.fileInfo, nodes);
} }

View File

@ -2212,32 +2212,34 @@ Sauce =
link = link.replace /(\$\d)/g, (parameter) -> link = link.replace /(\$\d)/g, (parameter) ->
switch parameter switch parameter
when '$1' when '$1'
"http://thumbs.4chan.org' + img.pathname.replace(/src(\\/\\d+).+$/, 'thumb$1s.jpg') + '" "' + (isArchived ? img.firstChild.src : 'http://thumbs.4chan.org' + img.pathname.replace(/src(\\/\\d+).+$/, 'thumb$1s.jpg')) + '"
when '$2' when '$2'
"' + img.href + '" "' + img.href + '"
when '$3' when '$3'
"' + encodeURIComponent(img.firstChild.dataset.md5) + '" "' + encodeURIComponent(img.firstChild.dataset.md5) + '"
when '$4' when '$4'
g.BOARD g.BOARD
else
parameter
domain = if m = link.match(/;text:(.+)$/) then m[1] else link.match(/(\w+)\.\w+\//)[1] domain = if m = link.match(/;text:(.+)$/) then m[1] else link.match(/(\w+)\.\w+\//)[1]
href = link.replace /;text:.+$/, '' href = link.replace /;text:.+$/, ''
href = Function 'img', "return '#{href}'" href = Function 'img', 'isArchived', "return '#{href}'"
el = $.el 'a', el = $.el 'a',
target: '_blank' target: '_blank'
textContent: domain textContent: domain
(img) -> (img, isArchived) ->
a = el.cloneNode true a = el.cloneNode true
a.href = href img a.href = href img, isArchived
a a
node: (post) -> node: (post) ->
{img} = post {img} = post
return if post.isInlined and not post.isCrosspost or post.isArchived or not img return if post.isInlined and not post.isCrosspost or not img
img = img.parentNode img = img.parentNode
nodes = [] nodes = []
for link in Sauce.links for link in Sauce.links
# \u00A0 is nbsp # \u00A0 is nbsp
nodes.push $.tn('\u00A0'), link img nodes.push $.tn('\u00A0'), link img, post.isArchived
$.add post.fileInfo, nodes $.add post.fileInfo, nodes
RevealSpoilers = RevealSpoilers =