From b843f7832530b5a03c384fb7bfafb7c13223d2b2 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 22 Feb 2012 06:28:55 +0100 Subject: [PATCH] More comment text reading for filter optimizations. --- 4chan_x.user.js | 11 +++-------- script.coffee | 8 ++------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4953abbad..04a293c82 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -639,18 +639,13 @@ return sub.textContent; }, comment: function(root) { - var i, len, node, nodes, text; + var data, i, len, nodes, text; text = []; - nodes = d.evaluate('.//node()', root.lastChild, null, 7, null); + nodes = d.evaluate('.//br|.//text()', root.lastChild, null, 7, 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.push((data = nodes.snapshotItem(i++).data) ? data : '\n'); } return text.join(''); }, diff --git a/script.coffee b/script.coffee index 08c981e07..0605e5703 100644 --- a/script.coffee +++ b/script.coffee @@ -554,15 +554,11 @@ filter = comment: (root) -> text = [] # XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 7 - nodes = d.evaluate './/node()', root.lastChild, null, 7, null + nodes = d.evaluate './/br|.//text()', root.lastChild, null, 7, 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.push if data = nodes.snapshotItem(i++).data then data else '\n' text.join '' filename: (root) -> if file = $ '.filesize > span', root