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);
},
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) {
return;
}
snapshot = d.evaluate('.//text()[not(parent::a)]', post.blockquote, null, 6, null);
for (i = _i = 0, _ref = snapshot.snapshotLength; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
node = snapshot.snapshotItem(i);
data = node.data;
if (!(quotes = data.match(/>>(>\/[a-z\d]+\/)?\d+/g))) {
continue;
_ref = $$('.quote.deadlink', post.blockquote);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
deadlink = _ref[_i];
quote = deadlink.textContent;
a = $.el('a', {
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 = [];
for (_j = 0, _len = quotes.length; _j < _len; _j++) {
quote = quotes[_j];
index = data.indexOf(quote);
if (text = data.slice(0, index)) {
nodes.push($.tn(text));
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);
}
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) {
nodes.push($.tn(data));
}
$.replace(node, nodes);
$.replace(deadlink, a);
}
}
};

View File

@ -3522,67 +3522,43 @@ Quotify =
Main.callbacks.push @node
node: (post) ->
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
# Get all the text nodes that are not inside an anchor.
snapshot = d.evaluate './/text()[not(parent::a)]', post.blockquote, null, 6, null
id = quote.match(/\d+$/)[0]
for i in [0...snapshot.snapshotLength]
node = snapshot.snapshotItem i
data = node.data
if m = quote.match /^>>>\/([a-z\d]+)/
board = m[1]
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
# Only accept nodes with potentially valid links
continue
nodes = []
for quote in quotes
index = data.indexOf quote
if text = data[...index]
# Potential text before this valid quote.
nodes.push $.tn text
id = quote.match(/\d+$/)[0]
board =
if m = quote.match /^>>>\/([a-z\d]+)/
m[1]
else
# Get the post's board, whether it's inlined or not.
$('a[title="Highlight this post"]', post.el).pathname.split('/')[1]
nodes.push a = $.el '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
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
$.replace deadlink, a
return
DeleteLink =