Simplify quote resurrection now that 4chan parses these for us.

This commit is contained in:
Nicolas Stepien 2012-12-11 12:09:47 +01:00
parent 715e1fb54e
commit e130614363
2 changed files with 65 additions and 98 deletions

View File

@ -4308,52 +4308,43 @@
return Main.callbacks.push(this.node); return Main.callbacks.push(this.node);
}, },
node: function(post) { node: function(post) {
var a, board, data, i, id, index, m, node, nodes, quote, quotes, snapshot, text, _i, _j, _len, _ref; var a, board, deadlink, id, m, postBoard, quote, _i, _len, _ref;
if (post.isInlined && !post.isCrosspost) { if (post.isInlined && !post.isCrosspost) {
return; return;
} }
snapshot = d.evaluate('.//text()[not(parent::a)]', post.blockquote, null, 6, null); _ref = $$('.quote.deadlink', post.blockquote);
for (i = _i = 0, _ref = snapshot.snapshotLength; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = snapshot.snapshotItem(i); deadlink = _ref[_i];
data = node.data; quote = deadlink.textContent;
if (!(quotes = data.match(/>>(>\/[a-z\d]+\/)?\d+/g))) { a = $.el('a', {
continue; textContent: "" + quote + "\u00A0(Dead)"
});
id = quote.match(/\d+$/)[0];
if (m = quote.match(/^>>>\/([a-z\d]+)/)) {
board = m[1];
} else if (postBoard) {
board = postBoard;
} else {
board = postBoard = $('a[title="Highlight this post"]', post.el).pathname.split('/')[1];
} }
nodes = []; if (board === g.BOARD && $.id("p" + id)) {
for (_j = 0, _len = quotes.length; _j < _len; _j++) { a.href = "#p" + id;
quote = quotes[_j]; a.className = 'quotelink';
index = data.indexOf(quote); } else {
if (text = data.slice(0, index)) { a.href = Redirect.to({
nodes.push($.tn(text)); board: board,
threadID: 0,
postID: id
});
a.className = 'deadlink';
a.target = '_blank';
if (Redirect.post(board, id)) {
$.addClass(a, 'quotelink');
a.setAttribute('data-board', board);
a.setAttribute('data-id', id);
} }
id = quote.match(/\d+$/)[0];
board = (m = quote.match(/^>>>\/([a-z\d]+)/)) ? m[1] : $('a[title="Highlight this post"]', post.el).pathname.split('/')[1];
nodes.push(a = $.el('a', {
textContent: "" + quote + "\u00A0(Dead)"
}));
if (board === g.BOARD && $.id("p" + id)) {
a.href = "#p" + id;
a.className = 'quotelink';
} else {
a.href = Redirect.to({
board: board,
threadID: 0,
postID: id
});
a.className = 'deadlink';
a.target = '_blank';
if (Redirect.post(board, id)) {
$.addClass(a, 'quotelink');
a.setAttribute('data-board', board);
a.setAttribute('data-id', id);
}
}
data = data.slice(index + quote.length);
} }
if (data) { $.replace(deadlink, a);
nodes.push($.tn(data));
}
$.replace(node, nodes);
} }
} }
}; };

View File

@ -3522,67 +3522,43 @@ Quotify =
Main.callbacks.push @node Main.callbacks.push @node
node: (post) -> node: (post) ->
return if post.isInlined and not post.isCrosspost return if post.isInlined and not post.isCrosspost
for deadlink in $$ '.quote.deadlink', post.blockquote
quote = deadlink.textContent
a = $.el 'a',
# \u00A0 is nbsp
textContent: "#{quote}\u00A0(Dead)"
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 6 id = quote.match(/\d+$/)[0]
# Get all the text nodes that are not inside an anchor.
snapshot = d.evaluate './/text()[not(parent::a)]', post.blockquote, null, 6, null
for i in [0...snapshot.snapshotLength] if m = quote.match /^>>>\/([a-z\d]+)/
node = snapshot.snapshotItem i board = m[1]
data = node.data else if postBoard
board = postBoard
else
# Get the post's board, whether it's inlined or not.
board = postBoard = $('a[title="Highlight this post"]', post.el).pathname.split('/')[1]
unless quotes = data.match />>(>\/[a-z\d]+\/)?\d+/g if board is g.BOARD and $.id "p#{id}"
# Only accept nodes with potentially valid links a.href = "#p#{id}"
continue a.className = 'quotelink'
else
nodes = [] a.href =
Redirect.to
for quote in quotes board: board
index = data.indexOf quote threadID: 0
if text = data[...index] postID: id
# Potential text before this valid quote. a.className = 'deadlink'
nodes.push $.tn text a.target = '_blank'
if Redirect.post board, id
id = quote.match(/\d+$/)[0] $.addClass a, 'quotelink'
board = # XXX WTF Scriptish/Greasemonkey?
if m = quote.match /^>>>\/([a-z\d]+)/ # Setting dataset attributes that way doesn't affect the HTML,
m[1] # but are, I suspect, kept as object key/value pairs and GC'd later.
else # a.dataset.board = board
# Get the post's board, whether it's inlined or not. # a.dataset.id = id
$('a[title="Highlight this post"]', post.el).pathname.split('/')[1] a.setAttribute 'data-board', board
a.setAttribute 'data-id', id
nodes.push a = $.el 'a', $.replace deadlink, a
# \u00A0 is nbsp
textContent: "#{quote}\u00A0(Dead)"
if board is g.BOARD and $.id "p#{id}"
a.href = "#p#{id}"
a.className = 'quotelink'
else
a.href =
Redirect.to
board: board
threadID: 0
postID: id
a.className = 'deadlink'
a.target = '_blank'
if Redirect.post board, id
$.addClass a, 'quotelink'
# XXX WTF Scriptish/Greasemonkey?
# Setting dataset attributes that way doesn't affect the HTML,
# but are, I suspect, kept as object key/value pairs and GC'd later.
# a.dataset.board = board
# a.dataset.id = id
a.setAttribute 'data-board', board
a.setAttribute 'data-id', id
data = data[index + quote.length..]
if data
# Potential text after the last valid quote.
nodes.push $.tn data
$.replace node, nodes
return return
DeleteLink = DeleteLink =