From 5bd1d3ebb5cf25862c45cdfb3eaddfcb786129d7 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 22 Feb 2012 00:55:16 +0100 Subject: [PATCH] Almost twice faster comment text reading for filters. --- 4chan_x.user.js | 17 ++++++++++++++--- script.coffee | 12 +++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 9b2566f4e..413141f04 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -631,9 +631,20 @@ return sub.textContent; }, comment: function(root) { - return ($.el('a', { - innerHTML: root.lastChild.innerHTML.replace(/
/g, '\n') - })).textContent; + var i, len, node, nodes, text; + text = []; + nodes = d.evaluate('.//node()', root.lastChild, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); + i = 0; + len = nodes.snapshotLength; + while (i < len) { + node = nodes.snapshotItem(i++); + if (node instanceof Text) { + text.push(node.data); + } else if (node instanceof HTMLBRElement) { + text.push('\n'); + } + } + return text.join(''); }, filename: function(root) { var file; diff --git a/script.coffee b/script.coffee index d75e92644..852cdf135 100644 --- a/script.coffee +++ b/script.coffee @@ -543,7 +543,17 @@ filter = sub = if isOP then $ '.filetitle', root else $ '.replytitle', root sub.textContent comment: (root) -> - ($.el 'a', innerHTML: root.lastChild.innerHTML.replace /
/g, '\n').textContent + text = [] + nodes = d.evaluate './/node()', root.lastChild, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null + i = 0 + len = nodes.snapshotLength + while i < len + node = nodes.snapshotItem i++ + if node instanceof Text + text.push node.data + else if node instanceof HTMLBRElement + text.push '\n' + text.join '' filename: (root) -> if file = $ '.filesize > span', root return file.title