From f9e615501d65d2efd24cad0d8c055a86e5f1256f Mon Sep 17 00:00:00 2001 From: alexadam Date: Mon, 19 Sep 2016 16:36:55 +0300 Subject: [PATCH] misc performance improvements --- web-extension/extractHtml.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/web-extension/extractHtml.js b/web-extension/extractHtml.js index 65930da..8c9e065 100644 --- a/web-extension/extractHtml.js +++ b/web-extension/extractHtml.js @@ -115,15 +115,18 @@ function force($content, withError) { } }); - if ($('*').length < maxNrOfElements) { - allowedTags.forEach(function (tagName) { - var tmpElems = $content.find(tagName); - while (tmpElems.length > 0) { - $tmpElem = $(tmpElems[0]); - $tmpElem.replaceWith(startEl + tagOpen + tagName + tagClose + $tmpElem.html() + tagOpen + '/' + tagName + tagClose + endEl); - tmpElems = $content.find(tagName); + all($content); + + function all($startElement) { + var tagName = $startElement.get(0).tagName.toLowerCase(); + if (allowedTags.indexOf(tagName) >= 0) { + var children = $startElement.children(); + var childrenLen = children.length; + while (childrenLen--) { + all($(children[childrenLen])); } - }); + $startElement.replaceWith(startEl + tagOpen + tagName + tagClose + $startElement.html() + tagOpen + '/' + tagName + tagClose + endEl); + } } var contentString = $content.text();