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,29 +4308,25 @@
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;
}
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));
}
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)" 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];
}
if (board === g.BOARD && $.id("p" + id)) { if (board === g.BOARD && $.id("p" + id)) {
a.href = "#p" + id; a.href = "#p" + id;
a.className = 'quotelink'; a.className = 'quotelink';
@ -4348,12 +4344,7 @@
a.setAttribute('data-id', id); a.setAttribute('data-id', id);
} }
} }
data = data.slice(index + quote.length); $.replace(deadlink, a);
}
if (data) {
nodes.push($.tn(data));
}
$.replace(node, nodes);
} }
} }
}; };

View File

@ -3522,39 +3522,22 @@ 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
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 6 quote = deadlink.textContent
# Get all the text nodes that are not inside an anchor. a = $.el 'a',
snapshot = d.evaluate './/text()[not(parent::a)]', post.blockquote, null, 6, null
for i in [0...snapshot.snapshotLength]
node = snapshot.snapshotItem i
data = node.data
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 # \u00A0 is nbsp
textContent: "#{quote}\u00A0(Dead)" 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
# Get the post's board, whether it's inlined or not.
board = postBoard = $('a[title="Highlight this post"]', post.el).pathname.split('/')[1]
if board is g.BOARD and $.id "p#{id}" if board is g.BOARD and $.id "p#{id}"
a.href = "#p#{id}" a.href = "#p#{id}"
a.className = 'quotelink' a.className = 'quotelink'
@ -3575,14 +3558,7 @@ Quotify =
# a.dataset.id = id # a.dataset.id = id
a.setAttribute 'data-board', board a.setAttribute 'data-board', board
a.setAttribute 'data-id', id a.setAttribute 'data-id', id
$.replace deadlink, a
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 =