and uri in the given element to an absolute URI,\n * ignoring #ref URIs.\n *\n * @param Element\n * @return void\n */\n _fixRelativeUris: function(articleContent) {\n var baseURI = this._doc.baseURI;\n var documentURI = this._doc.documentURI;\n function toAbsoluteURI(uri) {\n // Leave hash links alone if the base URI matches the document URI:\n if (baseURI == documentURI && uri.charAt(0) == \"#\") {\n return uri;\n }\n\n // Otherwise, resolve against base URI:\n try {\n return new URL(uri, baseURI).href;\n } catch (ex) {\n // Something went wrong, just return the original:\n }\n return uri;\n }\n\n var links = this._getAllNodesWithTag(articleContent, [\"a\"]);\n this._forEachNode(links, function(link) {\n var href = link.getAttribute(\"href\");\n if (href) {\n // Remove links with javascript: URIs, since\n // they won't work after scripts have been removed from the page.\n if (href.indexOf(\"javascript:\") === 0) {\n // if the link only contains simple text content, it can be converted to a text node\n if (link.childNodes.length === 1 && link.childNodes[0].nodeType === this.TEXT_NODE) {\n var text = this._doc.createTextNode(link.textContent);\n link.parentNode.replaceChild(text, link);\n } else {\n // if the link has multiple children, they should all be preserved\n var container = this._doc.createElement(\"span\");\n while (link.firstChild) {\n container.appendChild(link.firstChild);\n }\n link.parentNode.replaceChild(container, link);\n }\n } else {\n link.setAttribute(\"href\", toAbsoluteURI(href));\n }\n }\n });\n\n var medias = this._getAllNodesWithTag(articleContent, [\n \"img\", \"picture\", \"figure\", \"video\", \"audio\", \"source\"\n ]);\n\n this._forEachNode(medias, function(media) {\n var src = media.getAttribute(\"src\");\n var poster = media.getAttribute(\"poster\");\n var srcset = media.getAttribute(\"srcset\");\n\n if (src) {\n media.setAttribute(\"src\", toAbsoluteURI(src));\n }\n\n if (poster) {\n media.setAttribute(\"poster\", toAbsoluteURI(poster));\n }\n\n if (srcset) {\n var newSrcset = srcset.replace(this.REGEXPS.srcsetUrl, function(_, p1, p2, p3) {\n return toAbsoluteURI(p1) + (p2 || \"\") + p3;\n });\n\n media.setAttribute(\"srcset\", newSrcset);\n }\n });\n },\n\n _simplifyNestedElements: function(articleContent) {\n var node = articleContent;\n\n while (node) {\n if (node.parentNode && [\"DIV\", \"SECTION\"].includes(node.tagName) && !(node.id && node.id.startsWith(\"readability\"))) {\n if (this._isElementWithoutContent(node)) {\n node = this._removeAndGetNext(node);\n continue;\n } else if (this._hasSingleTagInsideElement(node, \"DIV\") || this._hasSingleTagInsideElement(node, \"SECTION\")) {\n var child = node.children[0];\n for (var i = 0; i < node.attributes.length; i++) {\n child.setAttribute(node.attributes[i].name, node.attributes[i].value);\n }\n node.parentNode.replaceChild(child, node);\n node = child;\n continue;\n }\n }\n\n node = this._getNextNode(node);\n }\n },\n\n /**\n * Get the article title as an H1.\n *\n * @return string\n **/\n _getArticleTitle: function() {\n var doc = this._doc;\n var curTitle = \"\";\n var origTitle = \"\";\n\n try {\n curTitle = origTitle = doc.title.trim();\n\n // If they had an element with id \"title\" in their HTML\n if (typeof curTitle !== \"string\")\n curTitle = origTitle = this._getInnerText(doc.getElementsByTagName(\"title\")[0]);\n } catch (e) {/* ignore exceptions setting the title. */}\n\n var titleHadHierarchicalSeparators = false;\n function wordCount(str) {\n return str.split(/\\s+/).length;\n }\n\n // If there's a separator in the title, first remove the final part\n if ((/ [\\|\\-\\\\\\/>»] /).test(curTitle)) {\n titleHadHierarchicalSeparators = / [\\\\\\/>»] /.test(curTitle);\n curTitle = origTitle.replace(/(.*)[\\|\\-\\\\\\/>»] .*/gi, \"$1\");\n\n // If the resulting title is too short (3 words or fewer), remove\n // the first part instead:\n if (wordCount(curTitle) < 3)\n curTitle = origTitle.replace(/[^\\|\\-\\\\\\/>»]*[\\|\\-\\\\\\/>»](.*)/gi, \"$1\");\n } else if (curTitle.indexOf(\": \") !== -1) {\n // Check if we have an heading containing this exact string, so we\n // could assume it's the full title.\n var headings = this._concatNodeLists(\n doc.getElementsByTagName(\"h1\"),\n doc.getElementsByTagName(\"h2\")\n );\n var trimmedTitle = curTitle.trim();\n var match = this._someNode(headings, function(heading) {\n return heading.textContent.trim() === trimmedTitle;\n });\n\n // If we don't, let's extract the title out of the original title string.\n if (!match) {\n curTitle = origTitle.substring(origTitle.lastIndexOf(\":\") + 1);\n\n // If the title is now too short, try the first colon instead:\n if (wordCount(curTitle) < 3) {\n curTitle = origTitle.substring(origTitle.indexOf(\":\") + 1);\n // But if we have too many words before the colon there's something weird\n // with the titles and the H tags so let's just use the original title instead\n } else if (wordCount(origTitle.substr(0, origTitle.indexOf(\":\"))) > 5) {\n curTitle = origTitle;\n }\n }\n } else if (curTitle.length > 150 || curTitle.length < 15) {\n var hOnes = doc.getElementsByTagName(\"h1\");\n\n if (hOnes.length === 1)\n curTitle = this._getInnerText(hOnes[0]);\n }\n\n curTitle = curTitle.trim().replace(this.REGEXPS.normalize, \" \");\n // If we now have 4 words or fewer as our title, and either no\n // 'hierarchical' separators (\\, /, > or ») were found in the original\n // title or we decreased the number of words by more than 1 word, use\n // the original title.\n var curTitleWordCount = wordCount(curTitle);\n if (curTitleWordCount <= 4 &&\n (!titleHadHierarchicalSeparators ||\n curTitleWordCount != wordCount(origTitle.replace(/[\\|\\-\\\\\\/>»]+/g, \"\")) - 1)) {\n curTitle = origTitle;\n }\n\n return curTitle;\n },\n\n /**\n * Prepare the HTML document for readability to scrape it.\n * This includes things like stripping javascript, CSS, and handling terrible markup.\n *\n * @return void\n **/\n _prepDocument: function() {\n var doc = this._doc;\n\n // Remove all style tags in head\n this._removeNodes(this._getAllNodesWithTag(doc, [\"style\"]));\n\n if (doc.body) {\n this._replaceBrs(doc.body);\n }\n\n this._replaceNodeTags(this._getAllNodesWithTag(doc, [\"font\"]), \"SPAN\");\n },\n\n /**\n * Finds the next node, starting from the given node, and ignoring\n * whitespace in between. If the given node is an element, the same node is\n * returned.\n */\n _nextNode: function (node) {\n var next = node;\n while (next\n && (next.nodeType != this.ELEMENT_NODE)\n && this.REGEXPS.whitespace.test(next.textContent)) {\n next = next.nextSibling;\n }\n return next;\n },\n\n /**\n * Replaces 2 or more successive elements with a single .\n * Whitespace between elements are ignored. For example:\n *
foo bar abc
\n * will become:\n * \n */\n _replaceBrs: function (elem) {\n this._forEachNode(this._getAllNodesWithTag(elem, [\"br\"]), function(br) {\n var next = br.nextSibling;\n\n // Whether 2 or more elements have been found and replaced with a\n // block.\n var replaced = false;\n\n // If we find a chain, remove the s until we hit another node\n // or non-whitespace. This leaves behind the first in the chain\n // (which will be replaced with a
later).\n while ((next = this._nextNode(next)) && (next.tagName == \"BR\")) {\n replaced = true;\n var brSibling = next.nextSibling;\n next.parentNode.removeChild(next);\n next = brSibling;\n }\n\n // If we removed a chain, replace the remaining with a
. Add\n // all sibling nodes as children of the
until we hit another \n // chain.\n if (replaced) {\n var p = this._doc.createElement(\"p\");\n br.parentNode.replaceChild(p, br);\n\n next = p.nextSibling;\n while (next) {\n // If we've hit another , we're done adding children to this
.\n if (next.tagName == \"BR\") {\n var nextElem = this._nextNode(next.nextSibling);\n if (nextElem && nextElem.tagName == \"BR\")\n break;\n }\n\n if (!this._isPhrasingContent(next))\n break;\n\n // Otherwise, make this node a child of the new
.\n var sibling = next.nextSibling;\n p.appendChild(next);\n next = sibling;\n }\n\n while (p.lastChild && this._isWhitespace(p.lastChild)) {\n p.removeChild(p.lastChild);\n }\n\n if (p.parentNode.tagName === \"P\")\n this._setNodeTag(p.parentNode, \"DIV\");\n }\n });\n },\n\n _setNodeTag: function (node, tag) {\n this.log(\"_setNodeTag\", node, tag);\n if (this._docJSDOMParser) {\n node.localName = tag.toLowerCase();\n node.tagName = tag.toUpperCase();\n return node;\n }\n\n var replacement = node.ownerDocument.createElement(tag);\n while (node.firstChild) {\n replacement.appendChild(node.firstChild);\n }\n node.parentNode.replaceChild(replacement, node);\n if (node.readability)\n replacement.readability = node.readability;\n\n for (var i = 0; i < node.attributes.length; i++) {\n try {\n replacement.setAttribute(node.attributes[i].name, node.attributes[i].value);\n } catch (ex) {\n /* it's possible for setAttribute() to throw if the attribute name\n * isn't a valid XML Name. Such attributes can however be parsed from\n * source in HTML docs, see https://github.com/whatwg/html/issues/4275,\n * so we can hit them here and then throw. We don't care about such\n * attributes so we ignore them.\n */\n }\n }\n return replacement;\n },\n\n /**\n * Prepare the article node for display. Clean out any inline styles,\n * iframes, forms, strip extraneous
tags, etc.\n *\n * @param Element\n * @return void\n **/\n _prepArticle: function(articleContent) {\n this._cleanStyles(articleContent);\n\n // Check for data tables before we continue, to avoid removing items in\n // those tables, which will often be isolated even though they're\n // visually linked to other content-ful elements (text, images, etc.).\n this._markDataTables(articleContent);\n\n this._fixLazyImages(articleContent);\n\n // Clean out junk from the article content\n this._cleanConditionally(articleContent, \"form\");\n this._cleanConditionally(articleContent, \"fieldset\");\n this._clean(articleContent, \"object\");\n this._clean(articleContent, \"embed\");\n this._clean(articleContent, \"footer\");\n this._clean(articleContent, \"link\");\n this._clean(articleContent, \"aside\");\n\n // Clean out elements with little content that have \"share\" in their id/class combinations from final top candidates,\n // which means we don't remove the top candidates even they have \"share\".\n\n var shareElementThreshold = this.DEFAULT_CHAR_THRESHOLD;\n\n this._forEachNode(articleContent.children, function (topCandidate) {\n this._cleanMatchedNodes(topCandidate, function (node, matchString) {\n return this.REGEXPS.shareElements.test(matchString) && node.textContent.length < shareElementThreshold;\n });\n });\n\n this._clean(articleContent, \"iframe\");\n this._clean(articleContent, \"input\");\n this._clean(articleContent, \"textarea\");\n this._clean(articleContent, \"select\");\n this._clean(articleContent, \"button\");\n this._cleanHeaders(articleContent);\n\n // Do these last as the previous stuff may have removed junk\n // that will affect these\n this._cleanConditionally(articleContent, \"table\");\n this._cleanConditionally(articleContent, \"ul\");\n this._cleanConditionally(articleContent, \"div\");\n\n // replace H1 with H2 as H1 should be only title that is displayed separately\n this._replaceNodeTags(this._getAllNodesWithTag(articleContent, [\"h1\"]), \"h2\");\n\n // Remove extra paragraphs\n this._removeNodes(this._getAllNodesWithTag(articleContent, [\"p\"]), function (paragraph) {\n var imgCount = paragraph.getElementsByTagName(\"img\").length;\n var embedCount = paragraph.getElementsByTagName(\"embed\").length;\n var objectCount = paragraph.getElementsByTagName(\"object\").length;\n // At this point, nasty iframes have been removed, only remain embedded video ones.\n var iframeCount = paragraph.getElementsByTagName(\"iframe\").length;\n var totalCount = imgCount + embedCount + objectCount + iframeCount;\n\n return totalCount === 0 && !this._getInnerText(paragraph, false);\n });\n\n this._forEachNode(this._getAllNodesWithTag(articleContent, [\"br\"]), function(br) {\n var next = this._nextNode(br.nextSibling);\n if (next && next.tagName == \"P\")\n br.parentNode.removeChild(br);\n });\n\n // Remove single-cell tables\n this._forEachNode(this._getAllNodesWithTag(articleContent, [\"table\"]), function(table) {\n var tbody = this._hasSingleTagInsideElement(table, \"TBODY\") ? table.firstElementChild : table;\n if (this._hasSingleTagInsideElement(tbody, \"TR\")) {\n var row = tbody.firstElementChild;\n if (this._hasSingleTagInsideElement(row, \"TD\")) {\n var cell = row.firstElementChild;\n cell = this._setNodeTag(cell, this._everyNode(cell.childNodes, this._isPhrasingContent) ? \"P\" : \"DIV\");\n table.parentNode.replaceChild(cell, table);\n }\n }\n });\n },\n\n /**\n * Initialize a node with the readability object. Also checks the\n * className/id for special names to add to its score.\n *\n * @param Element\n * @return void\n **/\n _initializeNode: function(node) {\n node.readability = {\"contentScore\": 0};\n\n switch (node.tagName) {\n case \"DIV\":\n node.readability.contentScore += 5;\n break;\n\n case \"PRE\":\n case \"TD\":\n case \"BLOCKQUOTE\":\n node.readability.contentScore += 3;\n break;\n\n case \"ADDRESS\":\n case \"OL\":\n case \"UL\":\n case \"DL\":\n case \"DD\":\n case \"DT\":\n case \"LI\":\n case \"FORM\":\n node.readability.contentScore -= 3;\n break;\n\n case \"H1\":\n case \"H2\":\n case \"H3\":\n case \"H4\":\n case \"H5\":\n case \"H6\":\n case \"TH\":\n node.readability.contentScore -= 5;\n break;\n }\n\n node.readability.contentScore += this._getClassWeight(node);\n },\n\n _removeAndGetNext: function(node) {\n var nextNode = this._getNextNode(node, true);\n node.parentNode.removeChild(node);\n return nextNode;\n },\n\n /**\n * Traverse the DOM from node to node, starting at the node passed in.\n * Pass true for the second parameter to indicate this node itself\n * (and its kids) are going away, and we want the next node over.\n *\n * Calling this in a loop will traverse the DOM depth-first.\n */\n _getNextNode: function(node, ignoreSelfAndKids) {\n // First check for kids if those aren't being ignored\n if (!ignoreSelfAndKids && node.firstElementChild) {\n return node.firstElementChild;\n }\n // Then for siblings...\n if (node.nextElementSibling) {\n return node.nextElementSibling;\n }\n // And finally, move up the parent chain *and* find a sibling\n // (because this is depth-first traversal, we will have already\n // seen the parent nodes themselves).\n do {\n node = node.parentNode;\n } while (node && !node.nextElementSibling);\n return node && node.nextElementSibling;\n },\n\n // compares second text to first one\n // 1 = same text, 0 = completely different text\n // works the way that it splits both texts into words and then finds words that are unique in second text\n // the result is given by the lower length of unique parts\n _textSimilarity: function(textA, textB) {\n var tokensA = textA.toLowerCase().split(this.REGEXPS.tokenize).filter(Boolean);\n var tokensB = textB.toLowerCase().split(this.REGEXPS.tokenize).filter(Boolean);\n if (!tokensA.length || !tokensB.length) {\n return 0;\n }\n var uniqTokensB = tokensB.filter(token => !tokensA.includes(token));\n var distanceB = uniqTokensB.join(\" \").length / tokensB.join(\" \").length;\n return 1 - distanceB;\n },\n\n _checkByline: function(node, matchString) {\n if (this._articleByline) {\n return false;\n }\n\n if (node.getAttribute !== undefined) {\n var rel = node.getAttribute(\"rel\");\n var itemprop = node.getAttribute(\"itemprop\");\n }\n\n if ((rel === \"author\" || (itemprop && itemprop.indexOf(\"author\") !== -1) || this.REGEXPS.byline.test(matchString)) && this._isValidByline(node.textContent)) {\n this._articleByline = node.textContent.trim();\n return true;\n }\n\n return false;\n },\n\n _getNodeAncestors: function(node, maxDepth) {\n maxDepth = maxDepth || 0;\n var i = 0, ancestors = [];\n while (node.parentNode) {\n ancestors.push(node.parentNode);\n if (maxDepth && ++i === maxDepth)\n break;\n node = node.parentNode;\n }\n return ancestors;\n },\n\n /***\n * grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is\n * most likely to be the stuff a user wants to read. Then return it wrapped up in a div.\n *\n * @param page a document to run upon. Needs to be a full document, complete with body.\n * @return Element\n **/\n _grabArticle: function (page) {\n this.log(\"**** grabArticle ****\");\n var doc = this._doc;\n var isPaging = page !== null;\n page = page ? page : this._doc.body;\n\n // We can't grab an article if we don't have a page!\n if (!page) {\n this.log(\"No body found in document. Abort.\");\n return null;\n }\n\n var pageCacheHtml = page.innerHTML;\n\n while (true) {\n this.log(\"Starting grabArticle loop\");\n var stripUnlikelyCandidates = this._flagIsActive(this.FLAG_STRIP_UNLIKELYS);\n\n // First, node prepping. Trash nodes that look cruddy (like ones with the\n // class name \"comment\", etc), and turn divs into P tags where they have been\n // used inappropriately (as in, where they contain no other block level elements.)\n var elementsToScore = [];\n var node = this._doc.documentElement;\n\n let shouldRemoveTitleHeader = true;\n\n while (node) {\n\n if (node.tagName === \"HTML\") {\n this._articleLang = node.getAttribute(\"lang\");\n }\n\n var matchString = node.className + \" \" + node.id;\n\n if (!this._isProbablyVisible(node)) {\n this.log(\"Removing hidden node - \" + matchString);\n node = this._removeAndGetNext(node);\n continue;\n }\n\n // User is not able to see elements applied with both \"aria-modal = true\" and \"role = dialog\"\n if (node.getAttribute(\"aria-modal\") == \"true\" && node.getAttribute(\"role\") == \"dialog\") {\n node = this._removeAndGetNext(node);\n continue;\n }\n\n // Check to see if this node is a byline, and remove it if it is.\n if (this._checkByline(node, matchString)) {\n node = this._removeAndGetNext(node);\n continue;\n }\n\n if (shouldRemoveTitleHeader && this._headerDuplicatesTitle(node)) {\n this.log(\"Removing header: \", node.textContent.trim(), this._articleTitle.trim());\n shouldRemoveTitleHeader = false;\n node = this._removeAndGetNext(node);\n continue;\n }\n\n // Remove unlikely candidates\n if (stripUnlikelyCandidates) {\n if (this.REGEXPS.unlikelyCandidates.test(matchString) &&\n !this.REGEXPS.okMaybeItsACandidate.test(matchString) &&\n !this._hasAncestorTag(node, \"table\") &&\n !this._hasAncestorTag(node, \"code\") &&\n node.tagName !== \"BODY\" &&\n node.tagName !== \"A\") {\n this.log(\"Removing unlikely candidate - \" + matchString);\n node = this._removeAndGetNext(node);\n continue;\n }\n\n if (this.UNLIKELY_ROLES.includes(node.getAttribute(\"role\"))) {\n this.log(\"Removing content with role \" + node.getAttribute(\"role\") + \" - \" + matchString);\n node = this._removeAndGetNext(node);\n continue;\n }\n }\n\n // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).\n if ((node.tagName === \"DIV\" || node.tagName === \"SECTION\" || node.tagName === \"HEADER\" ||\n node.tagName === \"H1\" || node.tagName === \"H2\" || node.tagName === \"H3\" ||\n node.tagName === \"H4\" || node.tagName === \"H5\" || node.tagName === \"H6\") &&\n this._isElementWithoutContent(node)) {\n node = this._removeAndGetNext(node);\n continue;\n }\n\n if (this.DEFAULT_TAGS_TO_SCORE.indexOf(node.tagName) !== -1) {\n elementsToScore.push(node);\n }\n\n // Turn all divs that don't have children block level elements into p's\n if (node.tagName === \"DIV\") {\n // Put phrasing content into paragraphs.\n var p = null;\n var childNode = node.firstChild;\n while (childNode) {\n var nextSibling = childNode.nextSibling;\n if (this._isPhrasingContent(childNode)) {\n if (p !== null) {\n p.appendChild(childNode);\n } else if (!this._isWhitespace(childNode)) {\n p = doc.createElement(\"p\");\n node.replaceChild(p, childNode);\n p.appendChild(childNode);\n }\n } else if (p !== null) {\n while (p.lastChild && this._isWhitespace(p.lastChild)) {\n p.removeChild(p.lastChild);\n }\n p = null;\n }\n childNode = nextSibling;\n }\n\n // Sites like http://mobile.slate.com encloses each paragraph with a DIV\n // element. DIVs with only a P element inside and no text content can be\n // safely converted into plain P elements to avoid confusing the scoring\n // algorithm with DIVs with are, in practice, paragraphs.\n if (this._hasSingleTagInsideElement(node, \"P\") && this._getLinkDensity(node) < 0.25) {\n var newNode = node.children[0];\n node.parentNode.replaceChild(newNode, node);\n node = newNode;\n elementsToScore.push(node);\n } else if (!this._hasChildBlockElement(node)) {\n node = this._setNodeTag(node, \"P\");\n elementsToScore.push(node);\n }\n }\n node = this._getNextNode(node);\n }\n\n /**\n * Loop through all paragraphs, and assign a score to them based on how content-y they look.\n * Then add their score to their parent node.\n *\n * A score is determined by things like number of commas, class names, etc. Maybe eventually link density.\n **/\n var candidates = [];\n this._forEachNode(elementsToScore, function(elementToScore) {\n if (!elementToScore.parentNode || typeof(elementToScore.parentNode.tagName) === \"undefined\")\n return;\n\n // If this paragraph is less than 25 characters, don't even count it.\n var innerText = this._getInnerText(elementToScore);\n if (innerText.length < 25)\n return;\n\n // Exclude nodes with no ancestor.\n var ancestors = this._getNodeAncestors(elementToScore, 5);\n if (ancestors.length === 0)\n return;\n\n var contentScore = 0;\n\n // Add a point for the paragraph itself as a base.\n contentScore += 1;\n\n // Add points for any commas within this paragraph.\n contentScore += innerText.split(this.REGEXPS.commas).length;\n\n // For every 100 characters in this paragraph, add another point. Up to 3 points.\n contentScore += Math.min(Math.floor(innerText.length / 100), 3);\n\n // Initialize and score ancestors.\n this._forEachNode(ancestors, function(ancestor, level) {\n if (!ancestor.tagName || !ancestor.parentNode || typeof(ancestor.parentNode.tagName) === \"undefined\")\n return;\n\n if (typeof(ancestor.readability) === \"undefined\") {\n this._initializeNode(ancestor);\n candidates.push(ancestor);\n }\n\n // Node score divider:\n // - parent: 1 (no division)\n // - grandparent: 2\n // - great grandparent+: ancestor level * 3\n if (level === 0)\n var scoreDivider = 1;\n else if (level === 1)\n scoreDivider = 2;\n else\n scoreDivider = level * 3;\n ancestor.readability.contentScore += contentScore / scoreDivider;\n });\n });\n\n // After we've calculated scores, loop through all of the possible\n // candidate nodes we found and find the one with the highest score.\n var topCandidates = [];\n for (var c = 0, cl = candidates.length; c < cl; c += 1) {\n var candidate = candidates[c];\n\n // Scale the final candidates score based on link density. Good content\n // should have a relatively small link density (5% or less) and be mostly\n // unaffected by this operation.\n var candidateScore = candidate.readability.contentScore * (1 - this._getLinkDensity(candidate));\n candidate.readability.contentScore = candidateScore;\n\n this.log(\"Candidate:\", candidate, \"with score \" + candidateScore);\n\n for (var t = 0; t < this._nbTopCandidates; t++) {\n var aTopCandidate = topCandidates[t];\n\n if (!aTopCandidate || candidateScore > aTopCandidate.readability.contentScore) {\n topCandidates.splice(t, 0, candidate);\n if (topCandidates.length > this._nbTopCandidates)\n topCandidates.pop();\n break;\n }\n }\n }\n\n var topCandidate = topCandidates[0] || null;\n var neededToCreateTopCandidate = false;\n var parentOfTopCandidate;\n\n // If we still have no top candidate, just use the body as a last resort.\n // We also have to copy the body node so it is something we can modify.\n if (topCandidate === null || topCandidate.tagName === \"BODY\") {\n // Move all of the page's children into topCandidate\n topCandidate = doc.createElement(\"DIV\");\n neededToCreateTopCandidate = true;\n // Move everything (not just elements, also text nodes etc.) into the container\n // so we even include text directly in the body:\n while (page.firstChild) {\n this.log(\"Moving child out:\", page.firstChild);\n topCandidate.appendChild(page.firstChild);\n }\n\n page.appendChild(topCandidate);\n\n this._initializeNode(topCandidate);\n } else if (topCandidate) {\n // Find a better top candidate node if it contains (at least three) nodes which belong to `topCandidates` array\n // and whose scores are quite closed with current `topCandidate` node.\n var alternativeCandidateAncestors = [];\n for (var i = 1; i < topCandidates.length; i++) {\n if (topCandidates[i].readability.contentScore / topCandidate.readability.contentScore >= 0.75) {\n alternativeCandidateAncestors.push(this._getNodeAncestors(topCandidates[i]));\n }\n }\n var MINIMUM_TOPCANDIDATES = 3;\n if (alternativeCandidateAncestors.length >= MINIMUM_TOPCANDIDATES) {\n parentOfTopCandidate = topCandidate.parentNode;\n while (parentOfTopCandidate.tagName !== \"BODY\") {\n var listsContainingThisAncestor = 0;\n for (var ancestorIndex = 0; ancestorIndex < alternativeCandidateAncestors.length && listsContainingThisAncestor < MINIMUM_TOPCANDIDATES; ancestorIndex++) {\n listsContainingThisAncestor += Number(alternativeCandidateAncestors[ancestorIndex].includes(parentOfTopCandidate));\n }\n if (listsContainingThisAncestor >= MINIMUM_TOPCANDIDATES) {\n topCandidate = parentOfTopCandidate;\n break;\n }\n parentOfTopCandidate = parentOfTopCandidate.parentNode;\n }\n }\n if (!topCandidate.readability) {\n this._initializeNode(topCandidate);\n }\n\n // Because of our bonus system, parents of candidates might have scores\n // themselves. They get half of the node. There won't be nodes with higher\n // scores than our topCandidate, but if we see the score going *up* in the first\n // few steps up the tree, that's a decent sign that there might be more content\n // lurking in other places that we want to unify in. The sibling stuff\n // below does some of that - but only if we've looked high enough up the DOM\n // tree.\n parentOfTopCandidate = topCandidate.parentNode;\n var lastScore = topCandidate.readability.contentScore;\n // The scores shouldn't get too low.\n var scoreThreshold = lastScore / 3;\n while (parentOfTopCandidate.tagName !== \"BODY\") {\n if (!parentOfTopCandidate.readability) {\n parentOfTopCandidate = parentOfTopCandidate.parentNode;\n continue;\n }\n var parentScore = parentOfTopCandidate.readability.contentScore;\n if (parentScore < scoreThreshold)\n break;\n if (parentScore > lastScore) {\n // Alright! We found a better parent to use.\n topCandidate = parentOfTopCandidate;\n break;\n }\n lastScore = parentOfTopCandidate.readability.contentScore;\n parentOfTopCandidate = parentOfTopCandidate.parentNode;\n }\n\n // If the top candidate is the only child, use parent instead. This will help sibling\n // joining logic when adjacent content is actually located in parent's sibling node.\n parentOfTopCandidate = topCandidate.parentNode;\n while (parentOfTopCandidate.tagName != \"BODY\" && parentOfTopCandidate.children.length == 1) {\n topCandidate = parentOfTopCandidate;\n parentOfTopCandidate = topCandidate.parentNode;\n }\n if (!topCandidate.readability) {\n this._initializeNode(topCandidate);\n }\n }\n\n // Now that we have the top candidate, look through its siblings for content\n // that might also be related. Things like preambles, content split by ads\n // that we removed, etc.\n var articleContent = doc.createElement(\"DIV\");\n if (isPaging)\n articleContent.id = \"readability-content\";\n\n var siblingScoreThreshold = Math.max(10, topCandidate.readability.contentScore * 0.2);\n // Keep potential top candidate's parent node to try to get text direction of it later.\n parentOfTopCandidate = topCandidate.parentNode;\n var siblings = parentOfTopCandidate.children;\n\n for (var s = 0, sl = siblings.length; s < sl; s++) {\n var sibling = siblings[s];\n var append = false;\n\n this.log(\"Looking at sibling node:\", sibling, sibling.readability ? (\"with score \" + sibling.readability.contentScore) : \"\");\n this.log(\"Sibling has score\", sibling.readability ? sibling.readability.contentScore : \"Unknown\");\n\n if (sibling === topCandidate) {\n append = true;\n } else {\n var contentBonus = 0;\n\n // Give a bonus if sibling nodes and top candidates have the example same classname\n if (sibling.className === topCandidate.className && topCandidate.className !== \"\")\n contentBonus += topCandidate.readability.contentScore * 0.2;\n\n if (sibling.readability &&\n ((sibling.readability.contentScore + contentBonus) >= siblingScoreThreshold)) {\n append = true;\n } else if (sibling.nodeName === \"P\") {\n var linkDensity = this._getLinkDensity(sibling);\n var nodeContent = this._getInnerText(sibling);\n var nodeLength = nodeContent.length;\n\n if (nodeLength > 80 && linkDensity < 0.25) {\n append = true;\n } else if (nodeLength < 80 && nodeLength > 0 && linkDensity === 0 &&\n nodeContent.search(/\\.( |$)/) !== -1) {\n append = true;\n }\n }\n }\n\n if (append) {\n this.log(\"Appending node:\", sibling);\n\n if (this.ALTER_TO_DIV_EXCEPTIONS.indexOf(sibling.nodeName) === -1) {\n // We have a node that isn't a common block level element, like a form or td tag.\n // Turn it into a div so it doesn't get filtered out later by accident.\n this.log(\"Altering sibling:\", sibling, \"to div.\");\n\n sibling = this._setNodeTag(sibling, \"DIV\");\n }\n\n articleContent.appendChild(sibling);\n // Fetch children again to make it compatible\n // with DOM parsers without live collection support.\n siblings = parentOfTopCandidate.children;\n // siblings is a reference to the children array, and\n // sibling is removed from the array when we call appendChild().\n // As a result, we must revisit this index since the nodes\n // have been shifted.\n s -= 1;\n sl -= 1;\n }\n }\n\n if (this._debug)\n this.log(\"Article content pre-prep: \" + articleContent.innerHTML);\n // So we have all of the content that we need. Now we clean it up for presentation.\n this._prepArticle(articleContent);\n if (this._debug)\n this.log(\"Article content post-prep: \" + articleContent.innerHTML);\n\n if (neededToCreateTopCandidate) {\n // We already created a fake div thing, and there wouldn't have been any siblings left\n // for the previous loop, so there's no point trying to create a new div, and then\n // move all the children over. Just assign IDs and class names here. No need to append\n // because that already happened anyway.\n topCandidate.id = \"readability-page-1\";\n topCandidate.className = \"page\";\n } else {\n var div = doc.createElement(\"DIV\");\n div.id = \"readability-page-1\";\n div.className = \"page\";\n while (articleContent.firstChild) {\n div.appendChild(articleContent.firstChild);\n }\n articleContent.appendChild(div);\n }\n\n if (this._debug)\n this.log(\"Article content after paging: \" + articleContent.innerHTML);\n\n var parseSuccessful = true;\n\n // Now that we've gone through the full algorithm, check to see if\n // we got any meaningful content. If we didn't, we may need to re-run\n // grabArticle with different flags set. This gives us a higher likelihood of\n // finding the content, and the sieve approach gives us a higher likelihood of\n // finding the -right- content.\n var textLength = this._getInnerText(articleContent, true).length;\n if (textLength < this._charThreshold) {\n parseSuccessful = false;\n page.innerHTML = pageCacheHtml;\n\n if (this._flagIsActive(this.FLAG_STRIP_UNLIKELYS)) {\n this._removeFlag(this.FLAG_STRIP_UNLIKELYS);\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n } else if (this._flagIsActive(this.FLAG_WEIGHT_CLASSES)) {\n this._removeFlag(this.FLAG_WEIGHT_CLASSES);\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n } else if (this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY)) {\n this._removeFlag(this.FLAG_CLEAN_CONDITIONALLY);\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n } else {\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n // No luck after removing flags, just return the longest text we found during the different loops\n this._attempts.sort(function (a, b) {\n return b.textLength - a.textLength;\n });\n\n // But first check if we actually have something\n if (!this._attempts[0].textLength) {\n return null;\n }\n\n articleContent = this._attempts[0].articleContent;\n parseSuccessful = true;\n }\n }\n\n if (parseSuccessful) {\n // Find out text direction from ancestors of final top candidate.\n var ancestors = [parentOfTopCandidate, topCandidate].concat(this._getNodeAncestors(parentOfTopCandidate));\n this._someNode(ancestors, function(ancestor) {\n if (!ancestor.tagName)\n return false;\n var articleDir = ancestor.getAttribute(\"dir\");\n if (articleDir) {\n this._articleDir = articleDir;\n return true;\n }\n return false;\n });\n return articleContent;\n }\n }\n },\n\n /**\n * Check whether the input string could be a byline.\n * This verifies that the input is a string, and that the length\n * is less than 100 chars.\n *\n * @param possibleByline {string} - a string to check whether its a byline.\n * @return Boolean - whether the input string is a byline.\n */\n _isValidByline: function(byline) {\n if (typeof byline == \"string\" || byline instanceof String) {\n byline = byline.trim();\n return (byline.length > 0) && (byline.length < 100);\n }\n return false;\n },\n\n /**\n * Converts some of the common HTML entities in string to their corresponding characters.\n *\n * @param str {string} - a string to unescape.\n * @return string without HTML entity.\n */\n _unescapeHtmlEntities: function(str) {\n if (!str) {\n return str;\n }\n\n var htmlEscapeMap = this.HTML_ESCAPE_MAP;\n return str.replace(/&(quot|amp|apos|lt|gt);/g, function(_, tag) {\n return htmlEscapeMap[tag];\n }).replace(/(?:x([0-9a-z]{1,4})|([0-9]{1,4}));/gi, function(_, hex, numStr) {\n var num = parseInt(hex || numStr, hex ? 16 : 10);\n return String.fromCharCode(num);\n });\n },\n\n /**\n * Try to extract metadata from JSON-LD object.\n * For now, only Schema.org objects of type Article or its subtypes are supported.\n * @return Object with any metadata that could be extracted (possibly none)\n */\n _getJSONLD: function (doc) {\n var scripts = this._getAllNodesWithTag(doc, [\"script\"]);\n\n var metadata;\n\n this._forEachNode(scripts, function(jsonLdElement) {\n if (!metadata && jsonLdElement.getAttribute(\"type\") === \"application/ld+json\") {\n try {\n // Strip CDATA markers if present\n var content = jsonLdElement.textContent.replace(/^\\s*\\s*$/g, \"\");\n var parsed = JSON.parse(content);\n if (\n !parsed[\"@context\"] ||\n !parsed[\"@context\"].match(/^https?\\:\\/\\/schema\\.org$/)\n ) {\n return;\n }\n\n if (!parsed[\"@type\"] && Array.isArray(parsed[\"@graph\"])) {\n parsed = parsed[\"@graph\"].find(function(it) {\n return (it[\"@type\"] || \"\").match(\n this.REGEXPS.jsonLdArticleTypes\n );\n });\n }\n\n if (\n !parsed ||\n !parsed[\"@type\"] ||\n !parsed[\"@type\"].match(this.REGEXPS.jsonLdArticleTypes)\n ) {\n return;\n }\n\n metadata = {};\n\n if (typeof parsed.name === \"string\" && typeof parsed.headline === \"string\" && parsed.name !== parsed.headline) {\n // we have both name and headline element in the JSON-LD. They should both be the same but some websites like aktualne.cz\n // put their own name into \"name\" and the article title to \"headline\" which confuses Readability. So we try to check if either\n // \"name\" or \"headline\" closely matches the html title, and if so, use that one. If not, then we use \"name\" by default.\n\n var title = this._getArticleTitle();\n var nameMatches = this._textSimilarity(parsed.name, title) > 0.75;\n var headlineMatches = this._textSimilarity(parsed.headline, title) > 0.75;\n\n if (headlineMatches && !nameMatches) {\n metadata.title = parsed.headline;\n } else {\n metadata.title = parsed.name;\n }\n } else if (typeof parsed.name === \"string\") {\n metadata.title = parsed.name.trim();\n } else if (typeof parsed.headline === \"string\") {\n metadata.title = parsed.headline.trim();\n }\n if (parsed.author) {\n if (typeof parsed.author.name === \"string\") {\n metadata.byline = parsed.author.name.trim();\n } else if (Array.isArray(parsed.author) && parsed.author[0] && typeof parsed.author[0].name === \"string\") {\n metadata.byline = parsed.author\n .filter(function(author) {\n return author && typeof author.name === \"string\";\n })\n .map(function(author) {\n return author.name.trim();\n })\n .join(\", \");\n }\n }\n if (typeof parsed.description === \"string\") {\n metadata.excerpt = parsed.description.trim();\n }\n if (\n parsed.publisher &&\n typeof parsed.publisher.name === \"string\"\n ) {\n metadata.siteName = parsed.publisher.name.trim();\n }\n if (typeof parsed.datePublished === \"string\") {\n metadata.datePublished = parsed.datePublished.trim();\n }\n return;\n } catch (err) {\n this.log(err.message);\n }\n }\n });\n return metadata ? metadata : {};\n },\n\n /**\n * Attempts to get excerpt and byline metadata for the article.\n *\n * @param {Object} jsonld — object containing any metadata that\n * could be extracted from JSON-LD object.\n *\n * @return Object with optional \"excerpt\" and \"byline\" properties\n */\n _getArticleMetadata: function(jsonld) {\n var metadata = {};\n var values = {};\n var metaElements = this._doc.getElementsByTagName(\"meta\");\n\n // property is a space-separated list of values\n var propertyPattern = /\\s*(article|dc|dcterm|og|twitter)\\s*:\\s*(author|creator|description|published_time|title|site_name)\\s*/gi;\n\n // name is a single value\n var namePattern = /^\\s*(?:(dc|dcterm|og|twitter|weibo:(article|webpage))\\s*[\\.:]\\s*)?(author|creator|description|title|site_name)\\s*$/i;\n\n // Find description tags.\n this._forEachNode(metaElements, function(element) {\n var elementName = element.getAttribute(\"name\");\n var elementProperty = element.getAttribute(\"property\");\n var content = element.getAttribute(\"content\");\n if (!content) {\n return;\n }\n var matches = null;\n var name = null;\n\n if (elementProperty) {\n matches = elementProperty.match(propertyPattern);\n if (matches) {\n // Convert to lowercase, and remove any whitespace\n // so we can match below.\n name = matches[0].toLowerCase().replace(/\\s/g, \"\");\n // multiple authors\n values[name] = content.trim();\n }\n }\n if (!matches && elementName && namePattern.test(elementName)) {\n name = elementName;\n if (content) {\n // Convert to lowercase, remove any whitespace, and convert dots\n // to colons so we can match below.\n name = name.toLowerCase().replace(/\\s/g, \"\").replace(/\\./g, \":\");\n values[name] = content.trim();\n }\n }\n });\n\n // get title\n metadata.title = jsonld.title ||\n values[\"dc:title\"] ||\n values[\"dcterm:title\"] ||\n values[\"og:title\"] ||\n values[\"weibo:article:title\"] ||\n values[\"weibo:webpage:title\"] ||\n values[\"title\"] ||\n values[\"twitter:title\"];\n\n if (!metadata.title) {\n metadata.title = this._getArticleTitle();\n }\n\n // get author\n metadata.byline = jsonld.byline ||\n values[\"dc:creator\"] ||\n values[\"dcterm:creator\"] ||\n values[\"author\"];\n\n // get description\n metadata.excerpt = jsonld.excerpt ||\n values[\"dc:description\"] ||\n values[\"dcterm:description\"] ||\n values[\"og:description\"] ||\n values[\"weibo:article:description\"] ||\n values[\"weibo:webpage:description\"] ||\n values[\"description\"] ||\n values[\"twitter:description\"];\n\n // get site name\n metadata.siteName = jsonld.siteName ||\n values[\"og:site_name\"];\n\n // get article published time\n metadata.publishedTime = jsonld.datePublished ||\n values[\"article:published_time\"] || null;\n\n // in many sites the meta value is escaped with HTML entities,\n // so here we need to unescape it\n metadata.title = this._unescapeHtmlEntities(metadata.title);\n metadata.byline = this._unescapeHtmlEntities(metadata.byline);\n metadata.excerpt = this._unescapeHtmlEntities(metadata.excerpt);\n metadata.siteName = this._unescapeHtmlEntities(metadata.siteName);\n metadata.publishedTime = this._unescapeHtmlEntities(metadata.publishedTime);\n\n return metadata;\n },\n\n /**\n * Check if node is image, or if node contains exactly only one image\n * whether as a direct child or as its descendants.\n *\n * @param Element\n **/\n _isSingleImage: function(node) {\n if (node.tagName === \"IMG\") {\n return true;\n }\n\n if (node.children.length !== 1 || node.textContent.trim() !== \"\") {\n return false;\n }\n\n return this._isSingleImage(node.children[0]);\n },\n\n /**\n * Find all that are located after nodes, and which contain only one\n * element. Replace the first image with the image from inside the tag,\n * and remove the tag. This improves the quality of the images we use on\n * some sites (e.g. Medium).\n *\n * @param Element\n **/\n _unwrapNoscriptImages: function(doc) {\n // Find img without source or attributes that might contains image, and remove it.\n // This is done to prevent a placeholder img is replaced by img from noscript in next step.\n var imgs = Array.from(doc.getElementsByTagName(\"img\"));\n this._forEachNode(imgs, function(img) {\n for (var i = 0; i < img.attributes.length; i++) {\n var attr = img.attributes[i];\n switch (attr.name) {\n case \"src\":\n case \"srcset\":\n case \"data-src\":\n case \"data-srcset\":\n return;\n }\n\n if (/\\.(jpg|jpeg|png|webp)/i.test(attr.value)) {\n return;\n }\n }\n\n img.parentNode.removeChild(img);\n });\n\n // Next find noscript and try to extract its image\n var noscripts = Array.from(doc.getElementsByTagName(\"noscript\"));\n this._forEachNode(noscripts, function(noscript) {\n // Parse content of noscript and make sure it only contains image\n var tmp = doc.createElement(\"div\");\n tmp.innerHTML = noscript.innerHTML;\n if (!this._isSingleImage(tmp)) {\n return;\n }\n\n // If noscript has previous sibling and it only contains image,\n // replace it with noscript content. However we also keep old\n // attributes that might contains image.\n var prevElement = noscript.previousElementSibling;\n if (prevElement && this._isSingleImage(prevElement)) {\n var prevImg = prevElement;\n if (prevImg.tagName !== \"IMG\") {\n prevImg = prevElement.getElementsByTagName(\"img\")[0];\n }\n\n var newImg = tmp.getElementsByTagName(\"img\")[0];\n for (var i = 0; i < prevImg.attributes.length; i++) {\n var attr = prevImg.attributes[i];\n if (attr.value === \"\") {\n continue;\n }\n\n if (attr.name === \"src\" || attr.name === \"srcset\" || /\\.(jpg|jpeg|png|webp)/i.test(attr.value)) {\n if (newImg.getAttribute(attr.name) === attr.value) {\n continue;\n }\n\n var attrName = attr.name;\n if (newImg.hasAttribute(attrName)) {\n attrName = \"data-old-\" + attrName;\n }\n\n newImg.setAttribute(attrName, attr.value);\n }\n }\n\n noscript.parentNode.replaceChild(tmp.firstElementChild, prevElement);\n }\n });\n },\n\n /**\n * Removes script tags from the document.\n *\n * @param Element\n **/\n _removeScripts: function(doc) {\n this._removeNodes(this._getAllNodesWithTag(doc, [\"script\", \"noscript\"]));\n },\n\n /**\n * Check if this node has only whitespace and a single element with given tag\n * Returns false if the DIV node contains non-empty text nodes\n * or if it contains no element with given tag or more than 1 element.\n *\n * @param Element\n * @param string tag of child element\n **/\n _hasSingleTagInsideElement: function(element, tag) {\n // There should be exactly 1 element child with given tag\n if (element.children.length != 1 || element.children[0].tagName !== tag) {\n return false;\n }\n\n // And there should be no text nodes with real content\n return !this._someNode(element.childNodes, function(node) {\n return node.nodeType === this.TEXT_NODE &&\n this.REGEXPS.hasContent.test(node.textContent);\n });\n },\n\n _isElementWithoutContent: function(node) {\n return node.nodeType === this.ELEMENT_NODE &&\n node.textContent.trim().length == 0 &&\n (node.children.length == 0 ||\n node.children.length == node.getElementsByTagName(\"br\").length + node.getElementsByTagName(\"hr\").length);\n },\n\n /**\n * Determine whether element has any children block level elements.\n *\n * @param Element\n */\n _hasChildBlockElement: function (element) {\n return this._someNode(element.childNodes, function(node) {\n return this.DIV_TO_P_ELEMS.has(node.tagName) ||\n this._hasChildBlockElement(node);\n });\n },\n\n /***\n * Determine if a node qualifies as phrasing content.\n * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n **/\n _isPhrasingContent: function(node) {\n return node.nodeType === this.TEXT_NODE || this.PHRASING_ELEMS.indexOf(node.tagName) !== -1 ||\n ((node.tagName === \"A\" || node.tagName === \"DEL\" || node.tagName === \"INS\") &&\n this._everyNode(node.childNodes, this._isPhrasingContent));\n },\n\n _isWhitespace: function(node) {\n return (node.nodeType === this.TEXT_NODE && node.textContent.trim().length === 0) ||\n (node.nodeType === this.ELEMENT_NODE && node.tagName === \"BR\");\n },\n\n /**\n * Get the inner text of a node - cross browser compatibly.\n * This also strips out any excess whitespace to be found.\n *\n * @param Element\n * @param Boolean normalizeSpaces (default: true)\n * @return string\n **/\n _getInnerText: function(e, normalizeSpaces) {\n normalizeSpaces = (typeof normalizeSpaces === \"undefined\") ? true : normalizeSpaces;\n var textContent = e.textContent.trim();\n\n if (normalizeSpaces) {\n return textContent.replace(this.REGEXPS.normalize, \" \");\n }\n return textContent;\n },\n\n /**\n * Get the number of times a string s appears in the node e.\n *\n * @param Element\n * @param string - what to split on. Default is \",\"\n * @return number (integer)\n **/\n _getCharCount: function(e, s) {\n s = s || \",\";\n return this._getInnerText(e).split(s).length - 1;\n },\n\n /**\n * Remove the style attribute on every e and under.\n * TODO: Test if getElementsByTagName(*) is faster.\n *\n * @param Element\n * @return void\n **/\n _cleanStyles: function(e) {\n if (!e || e.tagName.toLowerCase() === \"svg\")\n return;\n\n // Remove `style` and deprecated presentational attributes\n for (var i = 0; i < this.PRESENTATIONAL_ATTRIBUTES.length; i++) {\n e.removeAttribute(this.PRESENTATIONAL_ATTRIBUTES[i]);\n }\n\n if (this.DEPRECATED_SIZE_ATTRIBUTE_ELEMS.indexOf(e.tagName) !== -1) {\n e.removeAttribute(\"width\");\n e.removeAttribute(\"height\");\n }\n\n var cur = e.firstElementChild;\n while (cur !== null) {\n this._cleanStyles(cur);\n cur = cur.nextElementSibling;\n }\n },\n\n /**\n * Get the density of links as a percentage of the content\n * This is the amount of text that is inside a link divided by the total text in the node.\n *\n * @param Element\n * @return number (float)\n **/\n _getLinkDensity: function(element) {\n var textLength = this._getInnerText(element).length;\n if (textLength === 0)\n return 0;\n\n var linkLength = 0;\n\n // XXX implement _reduceNodeList?\n this._forEachNode(element.getElementsByTagName(\"a\"), function(linkNode) {\n var href = linkNode.getAttribute(\"href\");\n var coefficient = href && this.REGEXPS.hashUrl.test(href) ? 0.3 : 1;\n linkLength += this._getInnerText(linkNode).length * coefficient;\n });\n\n return linkLength / textLength;\n },\n\n /**\n * Get an elements class/id weight. Uses regular expressions to tell if this\n * element looks good or bad.\n *\n * @param Element\n * @return number (Integer)\n **/\n _getClassWeight: function(e) {\n if (!this._flagIsActive(this.FLAG_WEIGHT_CLASSES))\n return 0;\n\n var weight = 0;\n\n // Look for a special classname\n if (typeof(e.className) === \"string\" && e.className !== \"\") {\n if (this.REGEXPS.negative.test(e.className))\n weight -= 25;\n\n if (this.REGEXPS.positive.test(e.className))\n weight += 25;\n }\n\n // Look for a special ID\n if (typeof(e.id) === \"string\" && e.id !== \"\") {\n if (this.REGEXPS.negative.test(e.id))\n weight -= 25;\n\n if (this.REGEXPS.positive.test(e.id))\n weight += 25;\n }\n\n return weight;\n },\n\n /**\n * Clean a node of all elements of type \"tag\".\n * (Unless it's a youtube/vimeo video. People love movies.)\n *\n * @param Element\n * @param string tag to clean\n * @return void\n **/\n _clean: function(e, tag) {\n var isEmbed = [\"object\", \"embed\", \"iframe\"].indexOf(tag) !== -1;\n\n this._removeNodes(this._getAllNodesWithTag(e, [tag]), function(element) {\n // Allow youtube and vimeo videos through as people usually want to see those.\n if (isEmbed) {\n // First, check the elements attributes to see if any of them contain youtube or vimeo\n for (var i = 0; i < element.attributes.length; i++) {\n if (this._allowedVideoRegex.test(element.attributes[i].value)) {\n return false;\n }\n }\n\n // For embed with tag, check inner HTML as well.\n if (element.tagName === \"object\" && this._allowedVideoRegex.test(element.innerHTML)) {\n return false;\n }\n }\n\n return true;\n });\n },\n\n /**\n * Check if a given node has one of its ancestor tag name matching the\n * provided one.\n * @param HTMLElement node\n * @param String tagName\n * @param Number maxDepth\n * @param Function filterFn a filter to invoke to determine whether this node 'counts'\n * @return Boolean\n */\n _hasAncestorTag: function(node, tagName, maxDepth, filterFn) {\n maxDepth = maxDepth || 3;\n tagName = tagName.toUpperCase();\n var depth = 0;\n while (node.parentNode) {\n if (maxDepth > 0 && depth > maxDepth)\n return false;\n if (node.parentNode.tagName === tagName && (!filterFn || filterFn(node.parentNode)))\n return true;\n node = node.parentNode;\n depth++;\n }\n return false;\n },\n\n /**\n * Return an object indicating how many rows and columns this table has.\n */\n _getRowAndColumnCount: function(table) {\n var rows = 0;\n var columns = 0;\n var trs = table.getElementsByTagName(\"tr\");\n for (var i = 0; i < trs.length; i++) {\n var rowspan = trs[i].getAttribute(\"rowspan\") || 0;\n if (rowspan) {\n rowspan = parseInt(rowspan, 10);\n }\n rows += (rowspan || 1);\n\n // Now look for column-related info\n var columnsInThisRow = 0;\n var cells = trs[i].getElementsByTagName(\"td\");\n for (var j = 0; j < cells.length; j++) {\n var colspan = cells[j].getAttribute(\"colspan\") || 0;\n if (colspan) {\n colspan = parseInt(colspan, 10);\n }\n columnsInThisRow += (colspan || 1);\n }\n columns = Math.max(columns, columnsInThisRow);\n }\n return {rows: rows, columns: columns};\n },\n\n /**\n * Look for 'data' (as opposed to 'layout') tables, for which we use\n * similar checks as\n * https://searchfox.org/mozilla-central/rev/f82d5c549f046cb64ce5602bfd894b7ae807c8f8/accessible/generic/TableAccessible.cpp#19\n */\n _markDataTables: function(root) {\n var tables = root.getElementsByTagName(\"table\");\n for (var i = 0; i < tables.length; i++) {\n var table = tables[i];\n var role = table.getAttribute(\"role\");\n if (role == \"presentation\") {\n table._readabilityDataTable = false;\n continue;\n }\n var datatable = table.getAttribute(\"datatable\");\n if (datatable == \"0\") {\n table._readabilityDataTable = false;\n continue;\n }\n var summary = table.getAttribute(\"summary\");\n if (summary) {\n table._readabilityDataTable = true;\n continue;\n }\n\n var caption = table.getElementsByTagName(\"caption\")[0];\n if (caption && caption.childNodes.length > 0) {\n table._readabilityDataTable = true;\n continue;\n }\n\n // If the table has a descendant with any of these tags, consider a data table:\n var dataTableDescendants = [\"col\", \"colgroup\", \"tfoot\", \"thead\", \"th\"];\n var descendantExists = function(tag) {\n return !!table.getElementsByTagName(tag)[0];\n };\n if (dataTableDescendants.some(descendantExists)) {\n this.log(\"Data table because found data-y descendant\");\n table._readabilityDataTable = true;\n continue;\n }\n\n // Nested tables indicate a layout table:\n if (table.getElementsByTagName(\"table\")[0]) {\n table._readabilityDataTable = false;\n continue;\n }\n\n var sizeInfo = this._getRowAndColumnCount(table);\n if (sizeInfo.rows >= 10 || sizeInfo.columns > 4) {\n table._readabilityDataTable = true;\n continue;\n }\n // Now just go by size entirely:\n table._readabilityDataTable = sizeInfo.rows * sizeInfo.columns > 10;\n }\n },\n\n /* convert images and figures that have properties like data-src into images that can be loaded without JS */\n _fixLazyImages: function (root) {\n this._forEachNode(this._getAllNodesWithTag(root, [\"img\", \"picture\", \"figure\"]), function (elem) {\n // In some sites (e.g. Kotaku), they put 1px square image as base64 data uri in the src attribute.\n // So, here we check if the data uri is too short, just might as well remove it.\n if (elem.src && this.REGEXPS.b64DataUrl.test(elem.src)) {\n // Make sure it's not SVG, because SVG can have a meaningful image in under 133 bytes.\n var parts = this.REGEXPS.b64DataUrl.exec(elem.src);\n if (parts[1] === \"image/svg+xml\") {\n return;\n }\n\n // Make sure this element has other attributes which contains image.\n // If it doesn't, then this src is important and shouldn't be removed.\n var srcCouldBeRemoved = false;\n for (var i = 0; i < elem.attributes.length; i++) {\n var attr = elem.attributes[i];\n if (attr.name === \"src\") {\n continue;\n }\n\n if (/\\.(jpg|jpeg|png|webp)/i.test(attr.value)) {\n srcCouldBeRemoved = true;\n break;\n }\n }\n\n // Here we assume if image is less than 100 bytes (or 133B after encoded to base64)\n // it will be too small, therefore it might be placeholder image.\n if (srcCouldBeRemoved) {\n var b64starts = elem.src.search(/base64\\s*/i) + 7;\n var b64length = elem.src.length - b64starts;\n if (b64length < 133) {\n elem.removeAttribute(\"src\");\n }\n }\n }\n\n // also check for \"null\" to work around https://github.com/jsdom/jsdom/issues/2580\n if ((elem.src || (elem.srcset && elem.srcset != \"null\")) && elem.className.toLowerCase().indexOf(\"lazy\") === -1) {\n return;\n }\n\n for (var j = 0; j < elem.attributes.length; j++) {\n attr = elem.attributes[j];\n if (attr.name === \"src\" || attr.name === \"srcset\" || attr.name === \"alt\") {\n continue;\n }\n var copyTo = null;\n if (/\\.(jpg|jpeg|png|webp)\\s+\\d/.test(attr.value)) {\n copyTo = \"srcset\";\n } else if (/^\\s*\\S+\\.(jpg|jpeg|png|webp)\\S*\\s*$/.test(attr.value)) {\n copyTo = \"src\";\n }\n if (copyTo) {\n //if this is an img or picture, set the attribute directly\n if (elem.tagName === \"IMG\" || elem.tagName === \"PICTURE\") {\n elem.setAttribute(copyTo, attr.value);\n } else if (elem.tagName === \"FIGURE\" && !this._getAllNodesWithTag(elem, [\"img\", \"picture\"]).length) {\n //if the item is a that does not contain an image or picture, create one and place it inside the figure\n //see the nytimes-3 testcase for an example\n var img = this._doc.createElement(\"img\");\n img.setAttribute(copyTo, attr.value);\n elem.appendChild(img);\n }\n }\n }\n });\n },\n\n _getTextDensity: function(e, tags) {\n var textLength = this._getInnerText(e, true).length;\n if (textLength === 0) {\n return 0;\n }\n var childrenLength = 0;\n var children = this._getAllNodesWithTag(e, tags);\n this._forEachNode(children, (child) => childrenLength += this._getInnerText(child, true).length);\n return childrenLength / textLength;\n },\n\n /**\n * Clean an element of all tags of type \"tag\" if they look fishy.\n * \"Fishy\" is an algorithm based on content length, classnames, link density, number of images & embeds, etc.\n *\n * @return void\n **/\n _cleanConditionally: function(e, tag) {\n if (!this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY))\n return;\n\n // Gather counts for other typical elements embedded within.\n // Traverse backwards so we can remove nodes at the same time\n // without effecting the traversal.\n //\n // TODO: Consider taking into account original contentScore here.\n this._removeNodes(this._getAllNodesWithTag(e, [tag]), function(node) {\n // First check if this node IS data table, in which case don't remove it.\n var isDataTable = function(t) {\n return t._readabilityDataTable;\n };\n\n var isList = tag === \"ul\" || tag === \"ol\";\n if (!isList) {\n var listLength = 0;\n var listNodes = this._getAllNodesWithTag(node, [\"ul\", \"ol\"]);\n this._forEachNode(listNodes, (list) => listLength += this._getInnerText(list).length);\n isList = listLength / this._getInnerText(node).length > 0.9;\n }\n\n if (tag === \"table\" && isDataTable(node)) {\n return false;\n }\n\n // Next check if we're inside a data table, in which case don't remove it as well.\n if (this._hasAncestorTag(node, \"table\", -1, isDataTable)) {\n return false;\n }\n\n if (this._hasAncestorTag(node, \"code\")) {\n return false;\n }\n\n var weight = this._getClassWeight(node);\n\n this.log(\"Cleaning Conditionally\", node);\n\n var contentScore = 0;\n\n if (weight + contentScore < 0) {\n return true;\n }\n\n if (this._getCharCount(node, \",\") < 10) {\n // If there are not very many commas, and the number of\n // non-paragraph elements is more than paragraphs or other\n // ominous signs, remove the element.\n var p = node.getElementsByTagName(\"p\").length;\n var img = node.getElementsByTagName(\"img\").length;\n var li = node.getElementsByTagName(\"li\").length - 100;\n var input = node.getElementsByTagName(\"input\").length;\n var headingDensity = this._getTextDensity(node, [\"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\"]);\n\n var embedCount = 0;\n var embeds = this._getAllNodesWithTag(node, [\"object\", \"embed\", \"iframe\"]);\n\n for (var i = 0; i < embeds.length; i++) {\n // If this embed has attribute that matches video regex, don't delete it.\n for (var j = 0; j < embeds[i].attributes.length; j++) {\n if (this._allowedVideoRegex.test(embeds[i].attributes[j].value)) {\n return false;\n }\n }\n\n // For embed with tag, check inner HTML as well.\n if (embeds[i].tagName === \"object\" && this._allowedVideoRegex.test(embeds[i].innerHTML)) {\n return false;\n }\n\n embedCount++;\n }\n\n var linkDensity = this._getLinkDensity(node);\n var contentLength = this._getInnerText(node).length;\n\n var haveToRemove =\n (img > 1 && p / img < 0.5 && !this._hasAncestorTag(node, \"figure\")) ||\n (!isList && li > p) ||\n (input > Math.floor(p/3)) ||\n (!isList && headingDensity < 0.9 && contentLength < 25 && (img === 0 || img > 2) && !this._hasAncestorTag(node, \"figure\")) ||\n (!isList && weight < 25 && linkDensity > 0.2) ||\n (weight >= 25 && linkDensity > 0.5) ||\n ((embedCount === 1 && contentLength < 75) || embedCount > 1);\n // Allow simple lists of images to remain in pages\n if (isList && haveToRemove) {\n for (var x = 0; x < node.children.length; x++) {\n let child = node.children[x];\n // Don't filter in lists with li's that contain more than one child\n if (child.children.length > 1) {\n return haveToRemove;\n }\n }\n let li_count = node.getElementsByTagName(\"li\").length;\n // Only allow the list to remain if every li contains an image\n if (img == li_count) {\n return false;\n }\n }\n return haveToRemove;\n }\n return false;\n });\n },\n\n /**\n * Clean out elements that match the specified conditions\n *\n * @param Element\n * @param Function determines whether a node should be removed\n * @return void\n **/\n _cleanMatchedNodes: function(e, filter) {\n var endOfSearchMarkerNode = this._getNextNode(e, true);\n var next = this._getNextNode(e);\n while (next && next != endOfSearchMarkerNode) {\n if (filter.call(this, next, next.className + \" \" + next.id)) {\n next = this._removeAndGetNext(next);\n } else {\n next = this._getNextNode(next);\n }\n }\n },\n\n /**\n * Clean out spurious headers from an Element.\n *\n * @param Element\n * @return void\n **/\n _cleanHeaders: function(e) {\n let headingNodes = this._getAllNodesWithTag(e, [\"h1\", \"h2\"]);\n this._removeNodes(headingNodes, function(node) {\n let shouldRemove = this._getClassWeight(node) < 0;\n if (shouldRemove) {\n this.log(\"Removing header with low class weight:\", node);\n }\n return shouldRemove;\n });\n },\n\n /**\n * Check if this node is an H1 or H2 element whose content is mostly\n * the same as the article title.\n *\n * @param Element the node to check.\n * @return boolean indicating whether this is a title-like header.\n */\n _headerDuplicatesTitle: function(node) {\n if (node.tagName != \"H1\" && node.tagName != \"H2\") {\n return false;\n }\n var heading = this._getInnerText(node, false);\n this.log(\"Evaluating similarity of header:\", heading, this._articleTitle);\n return this._textSimilarity(this._articleTitle, heading) > 0.75;\n },\n\n _flagIsActive: function(flag) {\n return (this._flags & flag) > 0;\n },\n\n _removeFlag: function(flag) {\n this._flags = this._flags & ~flag;\n },\n\n _isProbablyVisible: function(node) {\n // Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.\n return (!node.style || node.style.display != \"none\")\n && (!node.style || node.style.visibility != \"hidden\")\n && !node.hasAttribute(\"hidden\")\n //check for \"fallback-image\" so that wikimedia math images are displayed\n && (!node.hasAttribute(\"aria-hidden\") || node.getAttribute(\"aria-hidden\") != \"true\" || (node.className && node.className.indexOf && node.className.indexOf(\"fallback-image\") !== -1));\n },\n\n /**\n * Runs readability.\n *\n * Workflow:\n * 1. Prep the document by removing script tags, css, etc.\n * 2. Build readability's DOM tree.\n * 3. Grab the article content from the current dom tree.\n * 4. Replace the current DOM tree with the new one.\n * 5. Read peacefully.\n *\n * @return void\n **/\n parse: function () {\n // Avoid parsing too large documents, as per configuration option\n if (this._maxElemsToParse > 0) {\n var numTags = this._doc.getElementsByTagName(\"*\").length;\n if (numTags > this._maxElemsToParse) {\n throw new Error(\"Aborting parsing document; \" + numTags + \" elements found\");\n }\n }\n\n // Unwrap image from noscript\n this._unwrapNoscriptImages(this._doc);\n\n // Extract JSON-LD metadata before removing scripts\n var jsonLd = this._disableJSONLD ? {} : this._getJSONLD(this._doc);\n\n // Remove script tags from the document.\n this._removeScripts(this._doc);\n\n this._prepDocument();\n\n var metadata = this._getArticleMetadata(jsonLd);\n this._articleTitle = metadata.title;\n\n var articleContent = this._grabArticle();\n if (!articleContent)\n return null;\n\n this.log(\"Grabbed: \" + articleContent.innerHTML);\n\n this._postProcessContent(articleContent);\n\n // If we haven't found an excerpt in the article's metadata, use the article's\n // first paragraph as the excerpt. This is used for displaying a preview of\n // the article's content.\n if (!metadata.excerpt) {\n var paragraphs = articleContent.getElementsByTagName(\"p\");\n if (paragraphs.length > 0) {\n metadata.excerpt = paragraphs[0].textContent.trim();\n }\n }\n\n var textContent = articleContent.textContent;\n return {\n title: this._articleTitle,\n byline: metadata.byline || this._articleByline,\n dir: this._articleDir,\n lang: this._articleLang,\n content: this._serializer(articleContent),\n textContent: textContent,\n length: textContent.length,\n excerpt: metadata.excerpt,\n siteName: metadata.siteName || this._articleSiteName,\n publishedTime: metadata.publishedTime\n };\n }\n};\n\nif (typeof module === \"object\") {\n /* global module */\n module.exports = Readability;\n}\n","/* eslint-env node */\nvar Readability = require(\"./Readability\");\nvar isProbablyReaderable = require(\"./Readability-readerable\");\n\nmodule.exports = {\n Readability: Readability,\n isProbablyReaderable: isProbablyReaderable\n};\n","/*\n * Copyright (c) 2010 Arc90 Inc\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This code is heavily based on Arc90's readability.js (1.7.1) script\n * available at: http://code.google.com/p/arc90labs-readability\n */\n\nvar REGEXPS = {\n // NOTE: These two regular expressions are duplicated in\n // Readability.js. Please keep both copies in sync.\n unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,\n okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,\n};\n\nfunction isNodeVisible(node) {\n // Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.\n return (!node.style || node.style.display != \"none\")\n && !node.hasAttribute(\"hidden\")\n //check for \"fallback-image\" so that wikimedia math images are displayed\n && (!node.hasAttribute(\"aria-hidden\") || node.getAttribute(\"aria-hidden\") != \"true\" || (node.className && node.className.indexOf && node.className.indexOf(\"fallback-image\") !== -1));\n}\n\n/**\n * Decides whether or not the document is reader-able without parsing the whole thing.\n * @param {Object} options Configuration object.\n * @param {number} [options.minContentLength=140] The minimum node content length used to decide if the document is readerable.\n * @param {number} [options.minScore=20] The minumum cumulated 'score' used to determine if the document is readerable.\n * @param {Function} [options.visibilityChecker=isNodeVisible] The function used to determine if a node is visible.\n * @return {boolean} Whether or not we suspect Readability.parse() will suceeed at returning an article object.\n */\nfunction isProbablyReaderable(doc, options = {}) {\n // For backward compatibility reasons 'options' can either be a configuration object or the function used\n // to determine if a node is visible.\n if (typeof options == \"function\") {\n options = { visibilityChecker: options };\n }\n\n var defaultOptions = { minScore: 20, minContentLength: 140, visibilityChecker: isNodeVisible };\n options = Object.assign(defaultOptions, options);\n\n var nodes = doc.querySelectorAll(\"p, pre, article\");\n\n // Get nodes which have
node(s) and append them into the `nodes` variable.\n // Some articles' DOM structures might look like\n //
\n // Sentences \n // \n // Sentences \n //
\n var brNodes = doc.querySelectorAll(\"div > br\");\n if (brNodes.length) {\n var set = new Set(nodes);\n [].forEach.call(brNodes, function (node) {\n set.add(node.parentNode);\n });\n nodes = Array.from(set);\n }\n\n var score = 0;\n // This is a little cheeky, we use the accumulator 'score' to decide what to return from\n // this callback:\n return [].some.call(nodes, function (node) {\n if (!options.visibilityChecker(node)) {\n return false;\n }\n\n var matchString = node.className + \" \" + node.id;\n if (REGEXPS.unlikelyCandidates.test(matchString) &&\n !REGEXPS.okMaybeItsACandidate.test(matchString)) {\n return false;\n }\n\n if (node.matches(\"li p\")) {\n return false;\n }\n\n var textContentLength = node.textContent.trim().length;\n if (textContentLength < options.minContentLength) {\n return false;\n }\n\n score += Math.sqrt(textContentLength - options.minContentLength);\n\n if (score > options.minScore) {\n return true;\n }\n return false;\n });\n}\n\nif (typeof module === \"object\") {\n /* global module */\n module.exports = isProbablyReaderable;\n}\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { Readability } from '@mozilla/readability';\nimport { JSDOM, VirtualConsole } from 'jsdom';\nconst verifyMessages = [\n \"you are human\",\n \"are you human\",\n \"i'm not a robot\",\n \"recaptcha\"\n];\nconst getArticleContent = (_a) => __awaiter(void 0, [_a], void 0, function* ({ articles, browser, filterWords, logger }) {\n try {\n const processedArticlesPromises = articles.map(article => extractArticleContentAndFavicon({ article, browser, filterWords, logger }));\n const processedArticles = yield Promise.all(processedArticlesPromises);\n return processedArticles;\n }\n catch (err) {\n logger.error(\"getArticleContent ERROR:\", err);\n return articles;\n }\n});\nconst extractArticleContentAndFavicon = (_a) => __awaiter(void 0, [_a], void 0, function* ({ article, browser, filterWords, logger }) {\n var _b;\n try {\n const page = yield browser.newPage();\n yield page.goto(article.link, { waitUntil: 'networkidle2' });\n const content = yield page.evaluate(() => document.documentElement.innerHTML);\n const favicon = (_b = yield page.evaluate(() => {\n const link = document.querySelector('link[rel=\"icon\"], link[rel=\"shortcut icon\"]');\n return link ? link.getAttribute('href') : '';\n })) !== null && _b !== void 0 ? _b : \"\";\n const virtualConsole = new VirtualConsole();\n virtualConsole.on(\"error\", logger.error);\n const dom = new JSDOM(content, { url: article.link, virtualConsole });\n let reader = new Readability(dom.window.document);\n const articleContent = reader.parse();\n if (!articleContent || !articleContent.textContent) {\n logger.warn(\"Article content could not be parsed or is empty.\", { article });\n return Object.assign(Object.assign({}, article), { content: '', favicon });\n }\n const hasVerifyMessage = verifyMessages.find(w => articleContent.textContent.toLowerCase().includes(w));\n if (hasVerifyMessage) {\n logger.warn(\"Article requires human verification.\", { article });\n return Object.assign(Object.assign({}, article), { content: '', favicon });\n }\n const cleanedText = cleanText(articleContent.textContent, filterWords);\n if (cleanedText.split(' ').length < 100) { // Example threshold: 100 words\n logger.warn(\"Article content is too short and likely not valuable.\", { article });\n return Object.assign(Object.assign({}, article), { content: '', favicon });\n }\n logger.info(\"SUCCESSFULLY SCRAPED ARTICLE CONTENT:\", cleanedText);\n return Object.assign(Object.assign({}, article), { content: cleanedText, favicon });\n }\n catch (error) {\n logger.error(error);\n return Object.assign(Object.assign({}, article), { content: '', favicon: '' });\n }\n});\nconst cleanText = (text, filterWords) => {\n const unwantedKeywords = [\n \"subscribe now\",\n \"sign up\",\n \"newsletter\",\n \"subscribe now\",\n \"sign up for our newsletter\",\n \"exclusive offer\",\n \"limited time offer\",\n \"free trial\",\n \"download now\",\n \"join now\",\n \"register today\",\n \"special promotion\",\n \"promotional offer\",\n \"discount code\",\n \"early access\",\n \"sneak peek\",\n \"save now\",\n \"don't miss out\",\n \"act now\",\n \"last chance\",\n \"expires soon\",\n \"giveaway\",\n \"free access\",\n \"premium access\",\n \"unlock full access\",\n \"buy now\",\n \"learn more\",\n \"click here\",\n \"follow us on\",\n \"share this article\",\n \"connect with us\",\n \"advertisement\",\n \"sponsored content\",\n \"partner content\",\n \"affiliate links\",\n \"click here\",\n \"for more information\",\n \"you may also like\",\n \"we think you'll like\",\n \"from our network\",\n ...filterWords\n ];\n return text\n .split('\\n')\n .map(line => line.trim())\n .filter(line => line.split(' ').length > 4)\n .filter(line => !unwantedKeywords.some(keyword => line.toLowerCase().includes(keyword)))\n .join('\\n');\n};\nexport default getArticleContent;\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport puppeteer from 'puppeteer';\nimport * as cheerio from 'cheerio';\nimport getLogger from './getLogger';\nimport getTitle from './getTitle';\nimport getArticleType from './getArticleType';\nimport getPrettyUrl from './getPrettyUrl';\nimport buildQueryString from './buildQueryString';\nimport getArticleContent from './getArticleContent';\nconst googleNewsScraper = (userConfig) => __awaiter(void 0, void 0, void 0, function* () {\n var _a, _b;\n const config = Object.assign({\n prettyURLs: true,\n getArticleContent: false,\n puppeteerArgs: [],\n puppeteerHeadlessMode: true,\n logLevel: 'error',\n timeframe: '7d',\n queryVars: {},\n limit: 99\n }, userConfig);\n const logger = getLogger(config.logLevel);\n const queryVars = config.queryVars\n ? Object.assign(Object.assign({}, config.queryVars), { when: config.timeframe }) : { when: config.timeframe };\n if (userConfig.searchTerm) {\n queryVars.q = userConfig.searchTerm;\n }\n const queryString = (_a = buildQueryString(queryVars)) !== null && _a !== void 0 ? _a : '';\n const baseUrl = (_b = config.baseUrl) !== null && _b !== void 0 ? _b : `https://news.google.com/search`;\n const url = `${baseUrl}${queryString}`;\n logger.info(`📰 SCRAPING NEWS FROM: ${url}`);\n const requiredArgs = [\n '--disable-extensions-except=/path/to/manifest/folder/',\n '--load-extension=/path/to/manifest/folder/',\n ];\n const puppeteerConfig = {\n headless: userConfig.puppeteerHeadlessMode,\n args: puppeteer.defaultArgs().concat(config.puppeteerArgs).filter(Boolean).concat(requiredArgs)\n };\n const browser = yield puppeteer.launch(puppeteerConfig);\n const page = yield browser.newPage();\n page.setViewport({ width: 1366, height: 768 });\n page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');\n page.setRequestInterception(true);\n page.on('request', request => {\n if (!request.isNavigationRequest()) {\n request.continue();\n return;\n }\n const headers = request.headers();\n headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3';\n headers['Accept-Encoding'] = 'gzip';\n headers['Accept-Language'] = 'en-US,en;q=0.9,es;q=0.8';\n headers['Upgrade-Insecure-Requests'] = \"1\";\n headers['Referer'] = 'https://www.google.com/';\n request.continue({ headers });\n });\n yield page.setCookie({\n name: \"CONSENT\",\n value: `YES+cb.${new Date().toISOString().split('T')[0].replace(/-/g, '')}-04-p0.en-GB+FX+667`,\n domain: \".google.com\"\n });\n yield page.goto(url, { waitUntil: 'networkidle2' });\n try {\n yield page.$(`[aria-label=\"Reject all\"]`);\n yield Promise.all([\n page.click(`[aria-label=\"Reject all\"]`),\n page.waitForNavigation({ waitUntil: 'networkidle2' })\n ]);\n }\n catch (err) { }\n const content = yield page.content();\n const $ = cheerio.load(content);\n const articles = $('article');\n let results = [];\n let i = 0;\n const urlChecklist = [];\n $(articles).each(function (i) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j;\n const link = ((_c = (_b = (_a = $(this)) === null || _a === void 0 ? void 0 : _a.find('a[href^=\"./article\"]')) === null || _b === void 0 ? void 0 : _b.attr('href')) === null || _c === void 0 ? void 0 : _c.replace('./', 'https://news.google.com/')) || ((_f = (_e = (_d = $(this)) === null || _d === void 0 ? void 0 : _d.find('a[href^=\"./read\"]')) === null || _e === void 0 ? void 0 : _e.attr('href')) === null || _f === void 0 ? void 0 : _f.replace('./', 'https://news.google.com/')) || \"\";\n link && urlChecklist.push(link);\n const srcset = (_g = $(this).find('figure').find('img').attr('srcset')) === null || _g === void 0 ? void 0 : _g.split(' ');\n const image = srcset && srcset.length\n ? srcset[srcset.length - 2]\n : $(this).find('figure').find('img').attr('src');\n const articleType = getArticleType($(this));\n const title = getTitle($(this), articleType);\n const mainArticle = {\n title,\n \"link\": link,\n \"image\": (image === null || image === void 0 ? void 0 : image.startsWith(\"/\")) ? `https://news.google.com${image}` : image || \"\",\n \"source\": $(this).find('div[data-n-tid]').text() || \"\",\n \"datetime\": ((_j = new Date(((_h = $(this).find('div:last-child time')) === null || _h === void 0 ? void 0 : _h.attr('datetime')) || \"\")) === null || _j === void 0 ? void 0 : _j.toISOString()) || \"\",\n \"time\": $(this).find('div:last-child time').text() || \"\",\n articleType\n };\n results.push(mainArticle);\n i++;\n });\n if (config.prettyURLs) {\n results = yield Promise.all(results.map(article => {\n const url = getPrettyUrl(article.link, logger);\n if (url) {\n article.link = url;\n }\n return article;\n }));\n }\n if (config.getArticleContent) {\n const filterWords = config.filterWords || [];\n results = yield getArticleContent({ articles: results, browser, filterWords, logger });\n }\n yield page.close();\n yield browser.close();\n const filtered = results.filter(result => result.title);\n return config.limit < results.length ? filtered.slice(0, config.limit) : filtered;\n});\nexport * from \"./types\";\nexport default googleNewsScraper;\n","const buildQueryString = (query) => {\n // Bail if there's nothing in the Object\n if (Object.keys(query).length === 0)\n return \"\";\n // Build query string\n // Example: { q: 'puppies', hl: 'en', gl: 'US' } => '?q=puppies&hl=en&gl=US'\n const queryString = Object.keys(query).reduce((acc, key, index) => {\n const prefix = index === 0 ? '?' : '&';\n return `${acc}${prefix}${key}=${query[key]}`;\n }, '');\n return queryString;\n};\nexport default buildQueryString;\n","const getArticleType = (article) => {\n if (article.find('h4').text() ||\n article.find('div > div + div > div a').text())\n return \"regular\";\n if (article.find('figure').length) {\n return \"topicFeatured\";\n }\n if (article.find('> a').text())\n return \"topicSmall\";\n return \"\";\n};\nexport default getArticleType;\n","const getTitle = (article, articleType) => {\n var _a, _b;\n try {\n switch (articleType) {\n case \"regular\":\n return article.find('h4').text() || article.find('div > div + div > div a').text() || \"\";\n case \"topicFeatured\":\n return article.find('a[target=_blank]').text() || ((_a = article.find('button').attr('aria-label')) === null || _a === void 0 ? void 0 : _a.replace('More - ', '')) || \"\";\n case \"topicSmall\":\n return article.find('a[target=_blank]').text() || ((_b = article.find('button').attr('aria-label')) === null || _b === void 0 ? void 0 : _b.replace('More - ', '')) || \"\";\n default:\n return \"\";\n }\n }\n catch (err) {\n return \"\";\n }\n};\nexport default getTitle;\n","const getPrettyUrl = (uglyUrl, logger) => {\n const base64Match = uglyUrl.match(/\\/read\\/([A-Za-z0-9-_]+)/);\n if (!base64Match) {\n return null;\n }\n const base64String = base64Match[1];\n try {\n const decodedString = Buffer.from(base64String, \"base64\").toString(\"ascii\");\n const urlPattern = /https?:\\/\\/[^\\s\"']+/g;\n const matches = decodedString.match(urlPattern) || [];\n const urls = matches.flatMap(match => {\n const splitUrls = match.split(/(? {\n const cleanUrl = url.trim().replace(/[^\\w\\-\\/:.]+$/, '').replace(/\\\\x[0-9A-Fa-f]{2}/g, '');\n return cleanUrl;\n });\n });\n const uniqueUrls = [...new Set(urls)];\n const finalUrl = uniqueUrls.length ? uniqueUrls[0] : uglyUrl;\n logger.info(finalUrl);\n return finalUrl;\n }\n catch (error) {\n logger.error(error);\n return null;\n }\n};\nexport default getPrettyUrl;\n"],"names":["config","levels","none","error","warn","info","verbose","colors","winston","addColors","getLogger","level","createLogger","format","combine","colorize","simple","transports","Console","Readability","doc","options","documentElement","arguments","Error","this","_doc","_docJSDOMParser","firstChild","__JSDOMParser__","_articleTitle","_articleByline","_articleDir","_articleSiteName","_attempts","_debug","debug","_maxElemsToParse","maxElemsToParse","DEFAULT_MAX_ELEMS_TO_PARSE","_nbTopCandidates","nbTopCandidates","DEFAULT_N_TOP_CANDIDATES","_charThreshold","charThreshold","DEFAULT_CHAR_THRESHOLD","_classesToPreserve","CLASSES_TO_PRESERVE","concat","classesToPreserve","_keepClasses","keepClasses","_serializer","serializer","el","innerHTML","_disableJSONLD","disableJSONLD","_allowedVideoRegex","allowedVideoRegex","REGEXPS","videos","_flags","FLAG_STRIP_UNLIKELYS","FLAG_WEIGHT_CLASSES","FLAG_CLEAN_CONDITIONALLY","logNode","node","nodeType","TEXT_NODE","nodeName","textContent","attrPairs","Array","from","attributes","attr","name","value","join","localName","log","console","args","arg","ELEMENT_NODE","unshift","apply","dump","msg","prototype","map","call","x","DEFAULT_TAGS_TO_SCORE","toUpperCase","split","unlikelyCandidates","okMaybeItsACandidate","positive","negative","extraneous","byline","replaceFonts","normalize","shareElements","nextLink","prevLink","tokenize","whitespace","hasContent","hashUrl","srcsetUrl","b64DataUrl","commas","jsonLdArticleTypes","UNLIKELY_ROLES","DIV_TO_P_ELEMS","Set","ALTER_TO_DIV_EXCEPTIONS","PRESENTATIONAL_ATTRIBUTES","DEPRECATED_SIZE_ATTRIBUTE_ELEMS","PHRASING_ELEMS","HTML_ESCAPE_MAP","lt","gt","amp","quot","apos","_postProcessContent","articleContent","_fixRelativeUris","_simplifyNestedElements","_cleanClasses","_removeNodes","nodeList","filterFn","_isLiveNodeList","i","length","parentNode","removeChild","_replaceNodeTags","newTagName","_setNodeTag","_forEachNode","fn","forEach","_findNode","find","_someNode","some","_everyNode","every","_concatNodeLists","slice","nodeLists","list","_getAllNodesWithTag","tagNames","querySelectorAll","tag","collection","getElementsByTagName","isArray","className","getAttribute","filter","cls","indexOf","setAttribute","removeAttribute","firstElementChild","nextElementSibling","baseURI","documentURI","toAbsoluteURI","uri","charAt","URL","href","ex","links","link","childNodes","text","createTextNode","replaceChild","container","createElement","appendChild","medias","media","src","poster","srcset","newSrcset","replace","_","p1","p2","p3","includes","tagName","id","startsWith","_isElementWithoutContent","_removeAndGetNext","_hasSingleTagInsideElement","child","children","_getNextNode","_getArticleTitle","curTitle","origTitle","title","trim","_getInnerText","e","titleHadHierarchicalSeparators","wordCount","str","test","headings","trimmedTitle","heading","substring","lastIndexOf","substr","hOnes","curTitleWordCount","_prepDocument","body","_replaceBrs","_nextNode","next","nextSibling","elem","br","replaced","brSibling","p","nextElem","_isPhrasingContent","sibling","lastChild","_isWhitespace","toLowerCase","replacement","ownerDocument","readability","_prepArticle","_cleanStyles","_markDataTables","_fixLazyImages","_cleanConditionally","_clean","shareElementThreshold","topCandidate","_cleanMatchedNodes","matchString","_cleanHeaders","paragraph","table","tbody","row","cell","_initializeNode","contentScore","_getClassWeight","nextNode","ignoreSelfAndKids","_textSimilarity","textA","textB","tokensA","Boolean","tokensB","token","_checkByline","undefined","rel","itemprop","_isValidByline","_getNodeAncestors","maxDepth","ancestors","push","_grabArticle","page","isPaging","pageCacheHtml","stripUnlikelyCandidates","_flagIsActive","elementsToScore","shouldRemoveTitleHeader","_articleLang","_isProbablyVisible","_headerDuplicatesTitle","_hasAncestorTag","childNode","_getLinkDensity","newNode","_hasChildBlockElement","candidates","elementToScore","innerText","Math","min","floor","ancestor","scoreDivider","topCandidates","c","cl","candidate","candidateScore","t","aTopCandidate","splice","pop","parentOfTopCandidate","neededToCreateTopCandidate","alternativeCandidateAncestors","listsContainingThisAncestor","ancestorIndex","Number","lastScore","scoreThreshold","parentScore","siblingScoreThreshold","max","siblings","s","sl","append","contentBonus","linkDensity","nodeContent","nodeLength","search","div","parseSuccessful","textLength","_removeFlag","sort","a","b","articleDir","String","_unescapeHtmlEntities","htmlEscapeMap","hex","numStr","num","parseInt","fromCharCode","_getJSONLD","metadata","scripts","jsonLdElement","content","parsed","JSON","parse","match","it","headline","nameMatches","headlineMatches","author","description","excerpt","publisher","siteName","datePublished","err","message","_getArticleMetadata","jsonld","values","metaElements","propertyPattern","namePattern","element","elementName","elementProperty","matches","publishedTime","_isSingleImage","_unwrapNoscriptImages","imgs","img","noscripts","noscript","tmp","prevElement","previousElementSibling","prevImg","newImg","attrName","hasAttribute","_removeScripts","has","normalizeSpaces","_getCharCount","cur","linkLength","linkNode","coefficient","weight","isEmbed","depth","_getRowAndColumnCount","rows","columns","trs","rowspan","columnsInThisRow","cells","j","colspan","root","tables","_readabilityDataTable","caption","sizeInfo","exec","srcCouldBeRemoved","b64starts","copyTo","_getTextDensity","tags","childrenLength","isDataTable","isList","listLength","listNodes","li","input","headingDensity","embedCount","embeds","contentLength","haveToRemove","endOfSearchMarkerNode","headingNodes","shouldRemove","flag","style","display","visibility","numTags","jsonLd","paragraphs","dir","lang","module","require$$0","isProbablyReaderable","isNodeVisible","visibilityChecker","defaultOptions","minScore","minContentLength","Object","assign","nodes","brNodes","set","add","score","textContentLength","sqrt","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","rejected","result","done","then","verifyMessages","extractArticleContentAndFavicon","_a","article","browser","filterWords","logger","_b","newPage","goto","waitUntil","evaluate","document","favicon","querySelector","virtualConsole","VirtualConsole","on","dom","JSDOM","url","window","w","cleanedText","cleanText","unwantedKeywords","line","keyword","googleNewsScraper","userConfig","prettyURLs","getArticleContent","puppeteerArgs","puppeteerHeadlessMode","logLevel","timeframe","queryVars","limit","when","searchTerm","q","queryString","query","keys","reduce","acc","key","index","baseUrl","puppeteerConfig","headless","puppeteer","defaultArgs","launch","setViewport","width","height","setUserAgent","setRequestInterception","request","isNavigationRequest","continue","headers","setCookie","Date","toISOString","domain","$","all","click","waitForNavigation","cheerio","load","articles","results","each","_c","_d","_e","_f","_g","_h","_j","image","articleType","getTitle","mainArticle","source","datetime","time","uglyUrl","base64Match","base64String","decodedString","Buffer","toString","urlPattern","urls","flatMap","uniqueUrls","finalUrl","getPrettyUrl","processedArticlesPromises","close","filtered"],"mappings":"4HACA,MAAMA,EAAS,CACXC,OAAQ,CACJC,KAAM,EACNC,MAAO,EACPC,KAAM,EACNC,KAAM,EACNC,QAAS,GAEbC,OAAQ,CACJL,KAAM,QACNC,MAAO,MACPC,KAAM,SACNC,KAAM,OACNC,QAAS,UAGjBE,EAAQC,UAAUT,EAAOO,QACzB,MAAMG,EAAaC,GAAWH,EAAQI,aAAa,CAC/CX,OAAQD,EAAOC,OACfY,OAAQL,EAAQK,OAAOC,QAAQN,EAAQK,OAAOE,WAAYP,EAAQK,OAAOG,UACzEC,WAAY,CACR,IAAIT,EAAQS,WAAWC,SAE3BP,uECEJ,SAASQ,EAAYC,EAAKC,GAExB,GAAIA,GAAWA,EAAQC,gBACrBF,EAAMC,EACNA,EAAUE,UAAU,QACf,IAAKH,IAAQA,EAAIE,gBACtB,MAAM,IAAIE,MAAM,0EAgClB,GA9BAH,EAAUA,GAAW,GAErBI,KAAKC,KAAON,EACZK,KAAKE,gBAAkBF,KAAKC,KAAKE,WAAWC,gBAC5CJ,KAAKK,cAAgB,KACrBL,KAAKM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q,QACjD,OAAOvN,EAAO6gB,MAAQqC,EAAQva,OAASqc,EAASrb,MAAM,EAAG3J,EAAO6gB,OAASmE,CAC7E","x_google_ignoreList":[1,2,3]}
\ No newline at end of file
+{"version":3,"file":"index.min.mjs","sources":["../../tsc/getLogger.js","../../../node_modules/@mozilla/readability/Readability.js","../../../node_modules/@mozilla/readability/index.js","../../../node_modules/@mozilla/readability/Readability-readerable.js","../../tsc/getArticleContent.js","../../tsc/index.js","../../tsc/buildQueryString.js","../../tsc/getArticleType.js","../../tsc/getTitle.js","../../tsc/getPrettyUrl.js"],"sourcesContent":["import winston from 'winston';\nconst config = {\n levels: {\n none: 0,\n error: 1,\n warn: 2,\n info: 3,\n verbose: 4,\n },\n colors: {\n none: 'black',\n error: 'red',\n warn: 'yellow',\n info: 'blue',\n verbose: 'white',\n }\n};\nwinston.addColors(config.colors);\nconst getLogger = (level) => (winston.createLogger({\n levels: config.levels,\n format: winston.format.combine(winston.format.colorize(), winston.format.simple()),\n transports: [\n new winston.transports.Console()\n ],\n level\n}));\nexport default getLogger;\n","/*\n * Copyright (c) 2010 Arc90 Inc\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This code is heavily based on Arc90's readability.js (1.7.1) script\n * available at: http://code.google.com/p/arc90labs-readability\n */\n\n/**\n * Public constructor.\n * @param {HTMLDocument} doc The document to parse.\n * @param {Object} options The options object.\n */\nfunction Readability(doc, options) {\n // In some older versions, people passed a URI as the first argument. Cope:\n if (options && options.documentElement) {\n doc = options;\n options = arguments[2];\n } else if (!doc || !doc.documentElement) {\n throw new Error(\"First argument to Readability constructor should be a document object.\");\n }\n options = options || {};\n\n this._doc = doc;\n this._docJSDOMParser = this._doc.firstChild.__JSDOMParser__;\n this._articleTitle = null;\n this._articleByline = null;\n this._articleDir = null;\n this._articleSiteName = null;\n this._attempts = [];\n\n // Configurable options\n this._debug = !!options.debug;\n this._maxElemsToParse = options.maxElemsToParse || this.DEFAULT_MAX_ELEMS_TO_PARSE;\n this._nbTopCandidates = options.nbTopCandidates || this.DEFAULT_N_TOP_CANDIDATES;\n this._charThreshold = options.charThreshold || this.DEFAULT_CHAR_THRESHOLD;\n this._classesToPreserve = this.CLASSES_TO_PRESERVE.concat(options.classesToPreserve || []);\n this._keepClasses = !!options.keepClasses;\n this._serializer = options.serializer || function(el) {\n return el.innerHTML;\n };\n this._disableJSONLD = !!options.disableJSONLD;\n this._allowedVideoRegex = options.allowedVideoRegex || this.REGEXPS.videos;\n\n // Start with all flags set\n this._flags = this.FLAG_STRIP_UNLIKELYS |\n this.FLAG_WEIGHT_CLASSES |\n this.FLAG_CLEAN_CONDITIONALLY;\n\n\n // Control whether log messages are sent to the console\n if (this._debug) {\n let logNode = function(node) {\n if (node.nodeType == node.TEXT_NODE) {\n return `${node.nodeName} (\"${node.textContent}\")`;\n }\n let attrPairs = Array.from(node.attributes || [], function(attr) {\n return `${attr.name}=\"${attr.value}\"`;\n }).join(\" \");\n return `<${node.localName} ${attrPairs}>`;\n };\n this.log = function () {\n if (typeof console !== \"undefined\") {\n let args = Array.from(arguments, arg => {\n if (arg && arg.nodeType == this.ELEMENT_NODE) {\n return logNode(arg);\n }\n return arg;\n });\n args.unshift(\"Reader: (Readability)\");\n console.log.apply(console, args);\n } else if (typeof dump !== \"undefined\") {\n /* global dump */\n var msg = Array.prototype.map.call(arguments, function(x) {\n return (x && x.nodeName) ? logNode(x) : x;\n }).join(\" \");\n dump(\"Reader: (Readability) \" + msg + \"\\n\");\n }\n };\n } else {\n this.log = function () {};\n }\n}\n\nReadability.prototype = {\n FLAG_STRIP_UNLIKELYS: 0x1,\n FLAG_WEIGHT_CLASSES: 0x2,\n FLAG_CLEAN_CONDITIONALLY: 0x4,\n\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\n ELEMENT_NODE: 1,\n TEXT_NODE: 3,\n\n // Max number of nodes supported by this parser. Default: 0 (no limit)\n DEFAULT_MAX_ELEMS_TO_PARSE: 0,\n\n // The number of top candidates to consider when analysing how\n // tight the competition is among candidates.\n DEFAULT_N_TOP_CANDIDATES: 5,\n\n // Element tags to score by default.\n DEFAULT_TAGS_TO_SCORE: \"section,h2,h3,h4,h5,h6,p,td,pre\".toUpperCase().split(\",\"),\n\n // The default number of chars an article must have in order to return a result\n DEFAULT_CHAR_THRESHOLD: 500,\n\n // All of the regular expressions in use within readability.\n // Defined up here so we don't instantiate them repeatedly in loops.\n REGEXPS: {\n // NOTE: These two regular expressions are duplicated in\n // Readability-readerable.js. Please keep both copies in sync.\n unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,\n okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,\n\n positive: /article|body|content|entry|hentry|h-entry|main|page|pagination|post|text|blog|story/i,\n negative: /-ad-|hidden|^hid$| hid$| hid |^hid |banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i,\n extraneous: /print|archive|comment|discuss|e[\\-]?mail|share|reply|all|login|sign|single|utility/i,\n byline: /byline|author|dateline|writtenby|p-author/i,\n replaceFonts: /<(\\/?)font[^>]*>/gi,\n normalize: /\\s{2,}/g,\n videos: /\\/\\/(www\\.)?((dailymotion|youtube|youtube-nocookie|player\\.vimeo|v\\.qq)\\.com|(archive|upload\\.wikimedia)\\.org|player\\.twitch\\.tv)/i,\n shareElements: /(\\b|_)(share|sharedaddy)(\\b|_)/i,\n nextLink: /(next|weiter|continue|>([^\\|]|$)|»([^\\|]|$))/i,\n prevLink: /(prev|earl|old|new|<|«)/i,\n tokenize: /\\W+/g,\n whitespace: /^\\s*$/,\n hasContent: /\\S$/,\n hashUrl: /^#.+/,\n srcsetUrl: /(\\S+)(\\s+[\\d.]+[xw])?(\\s*(?:,|$))/g,\n b64DataUrl: /^data:\\s*([^\\s;,]+)\\s*;\\s*base64\\s*,/i,\n // Commas as used in Latin, Sindhi, Chinese and various other scripts.\n // see: https://en.wikipedia.org/wiki/Comma#Comma_variants\n commas: /\\u002C|\\u060C|\\uFE50|\\uFE10|\\uFE11|\\u2E41|\\u2E34|\\u2E32|\\uFF0C/g,\n // See: https://schema.org/Article\n jsonLdArticleTypes: /^Article|AdvertiserContentArticle|NewsArticle|AnalysisNewsArticle|AskPublicNewsArticle|BackgroundNewsArticle|OpinionNewsArticle|ReportageNewsArticle|ReviewNewsArticle|Report|SatiricalArticle|ScholarlyArticle|MedicalScholarlyArticle|SocialMediaPosting|BlogPosting|LiveBlogPosting|DiscussionForumPosting|TechArticle|APIReference$/\n },\n\n UNLIKELY_ROLES: [ \"menu\", \"menubar\", \"complementary\", \"navigation\", \"alert\", \"alertdialog\", \"dialog\" ],\n\n DIV_TO_P_ELEMS: new Set([ \"BLOCKQUOTE\", \"DL\", \"DIV\", \"IMG\", \"OL\", \"P\", \"PRE\", \"TABLE\", \"UL\" ]),\n\n ALTER_TO_DIV_EXCEPTIONS: [\"DIV\", \"ARTICLE\", \"SECTION\", \"P\"],\n\n PRESENTATIONAL_ATTRIBUTES: [ \"align\", \"background\", \"bgcolor\", \"border\", \"cellpadding\", \"cellspacing\", \"frame\", \"hspace\", \"rules\", \"style\", \"valign\", \"vspace\" ],\n\n DEPRECATED_SIZE_ATTRIBUTE_ELEMS: [ \"TABLE\", \"TH\", \"TD\", \"HR\", \"PRE\" ],\n\n // The commented out elements qualify as phrasing content but tend to be\n // removed by readability when put into paragraphs, so we ignore them here.\n PHRASING_ELEMS: [\n // \"CANVAS\", \"IFRAME\", \"SVG\", \"VIDEO\",\n \"ABBR\", \"AUDIO\", \"B\", \"BDO\", \"BR\", \"BUTTON\", \"CITE\", \"CODE\", \"DATA\",\n \"DATALIST\", \"DFN\", \"EM\", \"EMBED\", \"I\", \"IMG\", \"INPUT\", \"KBD\", \"LABEL\",\n \"MARK\", \"MATH\", \"METER\", \"NOSCRIPT\", \"OBJECT\", \"OUTPUT\", \"PROGRESS\", \"Q\",\n \"RUBY\", \"SAMP\", \"SCRIPT\", \"SELECT\", \"SMALL\", \"SPAN\", \"STRONG\", \"SUB\",\n \"SUP\", \"TEXTAREA\", \"TIME\", \"VAR\", \"WBR\"\n ],\n\n // These are the classes that readability sets itself.\n CLASSES_TO_PRESERVE: [ \"page\" ],\n\n // These are the list of HTML entities that need to be escaped.\n HTML_ESCAPE_MAP: {\n \"lt\": \"<\",\n \"gt\": \">\",\n \"amp\": \"&\",\n \"quot\": '\"',\n \"apos\": \"'\",\n },\n\n /**\n * Run any post-process modifications to article content as necessary.\n *\n * @param Element\n * @return void\n **/\n _postProcessContent: function(articleContent) {\n // Readability cannot open relative uris so we convert them to absolute uris.\n this._fixRelativeUris(articleContent);\n\n this._simplifyNestedElements(articleContent);\n\n if (!this._keepClasses) {\n // Remove classes.\n this._cleanClasses(articleContent);\n }\n },\n\n /**\n * Iterates over a NodeList, calls `filterFn` for each node and removes node\n * if function returned `true`.\n *\n * If function is not passed, removes all the nodes in node list.\n *\n * @param NodeList nodeList The nodes to operate on\n * @param Function filterFn the function to use as a filter\n * @return void\n */\n _removeNodes: function(nodeList, filterFn) {\n // Avoid ever operating on live node lists.\n if (this._docJSDOMParser && nodeList._isLiveNodeList) {\n throw new Error(\"Do not pass live node lists to _removeNodes\");\n }\n for (var i = nodeList.length - 1; i >= 0; i--) {\n var node = nodeList[i];\n var parentNode = node.parentNode;\n if (parentNode) {\n if (!filterFn || filterFn.call(this, node, i, nodeList)) {\n parentNode.removeChild(node);\n }\n }\n }\n },\n\n /**\n * Iterates over a NodeList, and calls _setNodeTag for each node.\n *\n * @param NodeList nodeList The nodes to operate on\n * @param String newTagName the new tag name to use\n * @return void\n */\n _replaceNodeTags: function(nodeList, newTagName) {\n // Avoid ever operating on live node lists.\n if (this._docJSDOMParser && nodeList._isLiveNodeList) {\n throw new Error(\"Do not pass live node lists to _replaceNodeTags\");\n }\n for (const node of nodeList) {\n this._setNodeTag(node, newTagName);\n }\n },\n\n /**\n * Iterate over a NodeList, which doesn't natively fully implement the Array\n * interface.\n *\n * For convenience, the current object context is applied to the provided\n * iterate function.\n *\n * @param NodeList nodeList The NodeList.\n * @param Function fn The iterate function.\n * @return void\n */\n _forEachNode: function(nodeList, fn) {\n Array.prototype.forEach.call(nodeList, fn, this);\n },\n\n /**\n * Iterate over a NodeList, and return the first node that passes\n * the supplied test function\n *\n * For convenience, the current object context is applied to the provided\n * test function.\n *\n * @param NodeList nodeList The NodeList.\n * @param Function fn The test function.\n * @return void\n */\n _findNode: function(nodeList, fn) {\n return Array.prototype.find.call(nodeList, fn, this);\n },\n\n /**\n * Iterate over a NodeList, return true if any of the provided iterate\n * function calls returns true, false otherwise.\n *\n * For convenience, the current object context is applied to the\n * provided iterate function.\n *\n * @param NodeList nodeList The NodeList.\n * @param Function fn The iterate function.\n * @return Boolean\n */\n _someNode: function(nodeList, fn) {\n return Array.prototype.some.call(nodeList, fn, this);\n },\n\n /**\n * Iterate over a NodeList, return true if all of the provided iterate\n * function calls return true, false otherwise.\n *\n * For convenience, the current object context is applied to the\n * provided iterate function.\n *\n * @param NodeList nodeList The NodeList.\n * @param Function fn The iterate function.\n * @return Boolean\n */\n _everyNode: function(nodeList, fn) {\n return Array.prototype.every.call(nodeList, fn, this);\n },\n\n /**\n * Concat all nodelists passed as arguments.\n *\n * @return ...NodeList\n * @return Array\n */\n _concatNodeLists: function() {\n var slice = Array.prototype.slice;\n var args = slice.call(arguments);\n var nodeLists = args.map(function(list) {\n return slice.call(list);\n });\n return Array.prototype.concat.apply([], nodeLists);\n },\n\n _getAllNodesWithTag: function(node, tagNames) {\n if (node.querySelectorAll) {\n return node.querySelectorAll(tagNames.join(\",\"));\n }\n return [].concat.apply([], tagNames.map(function(tag) {\n var collection = node.getElementsByTagName(tag);\n return Array.isArray(collection) ? collection : Array.from(collection);\n }));\n },\n\n /**\n * Removes the class=\"\" attribute from every element in the given\n * subtree, except those that match CLASSES_TO_PRESERVE and\n * the classesToPreserve array from the options object.\n *\n * @param Element\n * @return void\n */\n _cleanClasses: function(node) {\n var classesToPreserve = this._classesToPreserve;\n var className = (node.getAttribute(\"class\") || \"\")\n .split(/\\s+/)\n .filter(function(cls) {\n return classesToPreserve.indexOf(cls) != -1;\n })\n .join(\" \");\n\n if (className) {\n node.setAttribute(\"class\", className);\n } else {\n node.removeAttribute(\"class\");\n }\n\n for (node = node.firstElementChild; node; node = node.nextElementSibling) {\n this._cleanClasses(node);\n }\n },\n\n /**\n * Converts each
and uri in the given element to an absolute URI,\n * ignoring #ref URIs.\n *\n * @param Element\n * @return void\n */\n _fixRelativeUris: function(articleContent) {\n var baseURI = this._doc.baseURI;\n var documentURI = this._doc.documentURI;\n function toAbsoluteURI(uri) {\n // Leave hash links alone if the base URI matches the document URI:\n if (baseURI == documentURI && uri.charAt(0) == \"#\") {\n return uri;\n }\n\n // Otherwise, resolve against base URI:\n try {\n return new URL(uri, baseURI).href;\n } catch (ex) {\n // Something went wrong, just return the original:\n }\n return uri;\n }\n\n var links = this._getAllNodesWithTag(articleContent, [\"a\"]);\n this._forEachNode(links, function(link) {\n var href = link.getAttribute(\"href\");\n if (href) {\n // Remove links with javascript: URIs, since\n // they won't work after scripts have been removed from the page.\n if (href.indexOf(\"javascript:\") === 0) {\n // if the link only contains simple text content, it can be converted to a text node\n if (link.childNodes.length === 1 && link.childNodes[0].nodeType === this.TEXT_NODE) {\n var text = this._doc.createTextNode(link.textContent);\n link.parentNode.replaceChild(text, link);\n } else {\n // if the link has multiple children, they should all be preserved\n var container = this._doc.createElement(\"span\");\n while (link.firstChild) {\n container.appendChild(link.firstChild);\n }\n link.parentNode.replaceChild(container, link);\n }\n } else {\n link.setAttribute(\"href\", toAbsoluteURI(href));\n }\n }\n });\n\n var medias = this._getAllNodesWithTag(articleContent, [\n \"img\", \"picture\", \"figure\", \"video\", \"audio\", \"source\"\n ]);\n\n this._forEachNode(medias, function(media) {\n var src = media.getAttribute(\"src\");\n var poster = media.getAttribute(\"poster\");\n var srcset = media.getAttribute(\"srcset\");\n\n if (src) {\n media.setAttribute(\"src\", toAbsoluteURI(src));\n }\n\n if (poster) {\n media.setAttribute(\"poster\", toAbsoluteURI(poster));\n }\n\n if (srcset) {\n var newSrcset = srcset.replace(this.REGEXPS.srcsetUrl, function(_, p1, p2, p3) {\n return toAbsoluteURI(p1) + (p2 || \"\") + p3;\n });\n\n media.setAttribute(\"srcset\", newSrcset);\n }\n });\n },\n\n _simplifyNestedElements: function(articleContent) {\n var node = articleContent;\n\n while (node) {\n if (node.parentNode && [\"DIV\", \"SECTION\"].includes(node.tagName) && !(node.id && node.id.startsWith(\"readability\"))) {\n if (this._isElementWithoutContent(node)) {\n node = this._removeAndGetNext(node);\n continue;\n } else if (this._hasSingleTagInsideElement(node, \"DIV\") || this._hasSingleTagInsideElement(node, \"SECTION\")) {\n var child = node.children[0];\n for (var i = 0; i < node.attributes.length; i++) {\n child.setAttribute(node.attributes[i].name, node.attributes[i].value);\n }\n node.parentNode.replaceChild(child, node);\n node = child;\n continue;\n }\n }\n\n node = this._getNextNode(node);\n }\n },\n\n /**\n * Get the article title as an H1.\n *\n * @return string\n **/\n _getArticleTitle: function() {\n var doc = this._doc;\n var curTitle = \"\";\n var origTitle = \"\";\n\n try {\n curTitle = origTitle = doc.title.trim();\n\n // If they had an element with id \"title\" in their HTML\n if (typeof curTitle !== \"string\")\n curTitle = origTitle = this._getInnerText(doc.getElementsByTagName(\"title\")[0]);\n } catch (e) {/* ignore exceptions setting the title. */}\n\n var titleHadHierarchicalSeparators = false;\n function wordCount(str) {\n return str.split(/\\s+/).length;\n }\n\n // If there's a separator in the title, first remove the final part\n if ((/ [\\|\\-\\\\\\/>»] /).test(curTitle)) {\n titleHadHierarchicalSeparators = / [\\\\\\/>»] /.test(curTitle);\n curTitle = origTitle.replace(/(.*)[\\|\\-\\\\\\/>»] .*/gi, \"$1\");\n\n // If the resulting title is too short (3 words or fewer), remove\n // the first part instead:\n if (wordCount(curTitle) < 3)\n curTitle = origTitle.replace(/[^\\|\\-\\\\\\/>»]*[\\|\\-\\\\\\/>»](.*)/gi, \"$1\");\n } else if (curTitle.indexOf(\": \") !== -1) {\n // Check if we have an heading containing this exact string, so we\n // could assume it's the full title.\n var headings = this._concatNodeLists(\n doc.getElementsByTagName(\"h1\"),\n doc.getElementsByTagName(\"h2\")\n );\n var trimmedTitle = curTitle.trim();\n var match = this._someNode(headings, function(heading) {\n return heading.textContent.trim() === trimmedTitle;\n });\n\n // If we don't, let's extract the title out of the original title string.\n if (!match) {\n curTitle = origTitle.substring(origTitle.lastIndexOf(\":\") + 1);\n\n // If the title is now too short, try the first colon instead:\n if (wordCount(curTitle) < 3) {\n curTitle = origTitle.substring(origTitle.indexOf(\":\") + 1);\n // But if we have too many words before the colon there's something weird\n // with the titles and the H tags so let's just use the original title instead\n } else if (wordCount(origTitle.substr(0, origTitle.indexOf(\":\"))) > 5) {\n curTitle = origTitle;\n }\n }\n } else if (curTitle.length > 150 || curTitle.length < 15) {\n var hOnes = doc.getElementsByTagName(\"h1\");\n\n if (hOnes.length === 1)\n curTitle = this._getInnerText(hOnes[0]);\n }\n\n curTitle = curTitle.trim().replace(this.REGEXPS.normalize, \" \");\n // If we now have 4 words or fewer as our title, and either no\n // 'hierarchical' separators (\\, /, > or ») were found in the original\n // title or we decreased the number of words by more than 1 word, use\n // the original title.\n var curTitleWordCount = wordCount(curTitle);\n if (curTitleWordCount <= 4 &&\n (!titleHadHierarchicalSeparators ||\n curTitleWordCount != wordCount(origTitle.replace(/[\\|\\-\\\\\\/>»]+/g, \"\")) - 1)) {\n curTitle = origTitle;\n }\n\n return curTitle;\n },\n\n /**\n * Prepare the HTML document for readability to scrape it.\n * This includes things like stripping javascript, CSS, and handling terrible markup.\n *\n * @return void\n **/\n _prepDocument: function() {\n var doc = this._doc;\n\n // Remove all style tags in head\n this._removeNodes(this._getAllNodesWithTag(doc, [\"style\"]));\n\n if (doc.body) {\n this._replaceBrs(doc.body);\n }\n\n this._replaceNodeTags(this._getAllNodesWithTag(doc, [\"font\"]), \"SPAN\");\n },\n\n /**\n * Finds the next node, starting from the given node, and ignoring\n * whitespace in between. If the given node is an element, the same node is\n * returned.\n */\n _nextNode: function (node) {\n var next = node;\n while (next\n && (next.nodeType != this.ELEMENT_NODE)\n && this.REGEXPS.whitespace.test(next.textContent)) {\n next = next.nextSibling;\n }\n return next;\n },\n\n /**\n * Replaces 2 or more successive elements with a single .\n * Whitespace between elements are ignored. For example:\n *
foo bar abc
\n * will become:\n * \n */\n _replaceBrs: function (elem) {\n this._forEachNode(this._getAllNodesWithTag(elem, [\"br\"]), function(br) {\n var next = br.nextSibling;\n\n // Whether 2 or more elements have been found and replaced with a\n // block.\n var replaced = false;\n\n // If we find a chain, remove the s until we hit another node\n // or non-whitespace. This leaves behind the first in the chain\n // (which will be replaced with a
later).\n while ((next = this._nextNode(next)) && (next.tagName == \"BR\")) {\n replaced = true;\n var brSibling = next.nextSibling;\n next.parentNode.removeChild(next);\n next = brSibling;\n }\n\n // If we removed a chain, replace the remaining with a
. Add\n // all sibling nodes as children of the
until we hit another \n // chain.\n if (replaced) {\n var p = this._doc.createElement(\"p\");\n br.parentNode.replaceChild(p, br);\n\n next = p.nextSibling;\n while (next) {\n // If we've hit another , we're done adding children to this
.\n if (next.tagName == \"BR\") {\n var nextElem = this._nextNode(next.nextSibling);\n if (nextElem && nextElem.tagName == \"BR\")\n break;\n }\n\n if (!this._isPhrasingContent(next))\n break;\n\n // Otherwise, make this node a child of the new
.\n var sibling = next.nextSibling;\n p.appendChild(next);\n next = sibling;\n }\n\n while (p.lastChild && this._isWhitespace(p.lastChild)) {\n p.removeChild(p.lastChild);\n }\n\n if (p.parentNode.tagName === \"P\")\n this._setNodeTag(p.parentNode, \"DIV\");\n }\n });\n },\n\n _setNodeTag: function (node, tag) {\n this.log(\"_setNodeTag\", node, tag);\n if (this._docJSDOMParser) {\n node.localName = tag.toLowerCase();\n node.tagName = tag.toUpperCase();\n return node;\n }\n\n var replacement = node.ownerDocument.createElement(tag);\n while (node.firstChild) {\n replacement.appendChild(node.firstChild);\n }\n node.parentNode.replaceChild(replacement, node);\n if (node.readability)\n replacement.readability = node.readability;\n\n for (var i = 0; i < node.attributes.length; i++) {\n try {\n replacement.setAttribute(node.attributes[i].name, node.attributes[i].value);\n } catch (ex) {\n /* it's possible for setAttribute() to throw if the attribute name\n * isn't a valid XML Name. Such attributes can however be parsed from\n * source in HTML docs, see https://github.com/whatwg/html/issues/4275,\n * so we can hit them here and then throw. We don't care about such\n * attributes so we ignore them.\n */\n }\n }\n return replacement;\n },\n\n /**\n * Prepare the article node for display. Clean out any inline styles,\n * iframes, forms, strip extraneous
tags, etc.\n *\n * @param Element\n * @return void\n **/\n _prepArticle: function(articleContent) {\n this._cleanStyles(articleContent);\n\n // Check for data tables before we continue, to avoid removing items in\n // those tables, which will often be isolated even though they're\n // visually linked to other content-ful elements (text, images, etc.).\n this._markDataTables(articleContent);\n\n this._fixLazyImages(articleContent);\n\n // Clean out junk from the article content\n this._cleanConditionally(articleContent, \"form\");\n this._cleanConditionally(articleContent, \"fieldset\");\n this._clean(articleContent, \"object\");\n this._clean(articleContent, \"embed\");\n this._clean(articleContent, \"footer\");\n this._clean(articleContent, \"link\");\n this._clean(articleContent, \"aside\");\n\n // Clean out elements with little content that have \"share\" in their id/class combinations from final top candidates,\n // which means we don't remove the top candidates even they have \"share\".\n\n var shareElementThreshold = this.DEFAULT_CHAR_THRESHOLD;\n\n this._forEachNode(articleContent.children, function (topCandidate) {\n this._cleanMatchedNodes(topCandidate, function (node, matchString) {\n return this.REGEXPS.shareElements.test(matchString) && node.textContent.length < shareElementThreshold;\n });\n });\n\n this._clean(articleContent, \"iframe\");\n this._clean(articleContent, \"input\");\n this._clean(articleContent, \"textarea\");\n this._clean(articleContent, \"select\");\n this._clean(articleContent, \"button\");\n this._cleanHeaders(articleContent);\n\n // Do these last as the previous stuff may have removed junk\n // that will affect these\n this._cleanConditionally(articleContent, \"table\");\n this._cleanConditionally(articleContent, \"ul\");\n this._cleanConditionally(articleContent, \"div\");\n\n // replace H1 with H2 as H1 should be only title that is displayed separately\n this._replaceNodeTags(this._getAllNodesWithTag(articleContent, [\"h1\"]), \"h2\");\n\n // Remove extra paragraphs\n this._removeNodes(this._getAllNodesWithTag(articleContent, [\"p\"]), function (paragraph) {\n var imgCount = paragraph.getElementsByTagName(\"img\").length;\n var embedCount = paragraph.getElementsByTagName(\"embed\").length;\n var objectCount = paragraph.getElementsByTagName(\"object\").length;\n // At this point, nasty iframes have been removed, only remain embedded video ones.\n var iframeCount = paragraph.getElementsByTagName(\"iframe\").length;\n var totalCount = imgCount + embedCount + objectCount + iframeCount;\n\n return totalCount === 0 && !this._getInnerText(paragraph, false);\n });\n\n this._forEachNode(this._getAllNodesWithTag(articleContent, [\"br\"]), function(br) {\n var next = this._nextNode(br.nextSibling);\n if (next && next.tagName == \"P\")\n br.parentNode.removeChild(br);\n });\n\n // Remove single-cell tables\n this._forEachNode(this._getAllNodesWithTag(articleContent, [\"table\"]), function(table) {\n var tbody = this._hasSingleTagInsideElement(table, \"TBODY\") ? table.firstElementChild : table;\n if (this._hasSingleTagInsideElement(tbody, \"TR\")) {\n var row = tbody.firstElementChild;\n if (this._hasSingleTagInsideElement(row, \"TD\")) {\n var cell = row.firstElementChild;\n cell = this._setNodeTag(cell, this._everyNode(cell.childNodes, this._isPhrasingContent) ? \"P\" : \"DIV\");\n table.parentNode.replaceChild(cell, table);\n }\n }\n });\n },\n\n /**\n * Initialize a node with the readability object. Also checks the\n * className/id for special names to add to its score.\n *\n * @param Element\n * @return void\n **/\n _initializeNode: function(node) {\n node.readability = {\"contentScore\": 0};\n\n switch (node.tagName) {\n case \"DIV\":\n node.readability.contentScore += 5;\n break;\n\n case \"PRE\":\n case \"TD\":\n case \"BLOCKQUOTE\":\n node.readability.contentScore += 3;\n break;\n\n case \"ADDRESS\":\n case \"OL\":\n case \"UL\":\n case \"DL\":\n case \"DD\":\n case \"DT\":\n case \"LI\":\n case \"FORM\":\n node.readability.contentScore -= 3;\n break;\n\n case \"H1\":\n case \"H2\":\n case \"H3\":\n case \"H4\":\n case \"H5\":\n case \"H6\":\n case \"TH\":\n node.readability.contentScore -= 5;\n break;\n }\n\n node.readability.contentScore += this._getClassWeight(node);\n },\n\n _removeAndGetNext: function(node) {\n var nextNode = this._getNextNode(node, true);\n node.parentNode.removeChild(node);\n return nextNode;\n },\n\n /**\n * Traverse the DOM from node to node, starting at the node passed in.\n * Pass true for the second parameter to indicate this node itself\n * (and its kids) are going away, and we want the next node over.\n *\n * Calling this in a loop will traverse the DOM depth-first.\n */\n _getNextNode: function(node, ignoreSelfAndKids) {\n // First check for kids if those aren't being ignored\n if (!ignoreSelfAndKids && node.firstElementChild) {\n return node.firstElementChild;\n }\n // Then for siblings...\n if (node.nextElementSibling) {\n return node.nextElementSibling;\n }\n // And finally, move up the parent chain *and* find a sibling\n // (because this is depth-first traversal, we will have already\n // seen the parent nodes themselves).\n do {\n node = node.parentNode;\n } while (node && !node.nextElementSibling);\n return node && node.nextElementSibling;\n },\n\n // compares second text to first one\n // 1 = same text, 0 = completely different text\n // works the way that it splits both texts into words and then finds words that are unique in second text\n // the result is given by the lower length of unique parts\n _textSimilarity: function(textA, textB) {\n var tokensA = textA.toLowerCase().split(this.REGEXPS.tokenize).filter(Boolean);\n var tokensB = textB.toLowerCase().split(this.REGEXPS.tokenize).filter(Boolean);\n if (!tokensA.length || !tokensB.length) {\n return 0;\n }\n var uniqTokensB = tokensB.filter(token => !tokensA.includes(token));\n var distanceB = uniqTokensB.join(\" \").length / tokensB.join(\" \").length;\n return 1 - distanceB;\n },\n\n _checkByline: function(node, matchString) {\n if (this._articleByline) {\n return false;\n }\n\n if (node.getAttribute !== undefined) {\n var rel = node.getAttribute(\"rel\");\n var itemprop = node.getAttribute(\"itemprop\");\n }\n\n if ((rel === \"author\" || (itemprop && itemprop.indexOf(\"author\") !== -1) || this.REGEXPS.byline.test(matchString)) && this._isValidByline(node.textContent)) {\n this._articleByline = node.textContent.trim();\n return true;\n }\n\n return false;\n },\n\n _getNodeAncestors: function(node, maxDepth) {\n maxDepth = maxDepth || 0;\n var i = 0, ancestors = [];\n while (node.parentNode) {\n ancestors.push(node.parentNode);\n if (maxDepth && ++i === maxDepth)\n break;\n node = node.parentNode;\n }\n return ancestors;\n },\n\n /***\n * grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is\n * most likely to be the stuff a user wants to read. Then return it wrapped up in a div.\n *\n * @param page a document to run upon. Needs to be a full document, complete with body.\n * @return Element\n **/\n _grabArticle: function (page) {\n this.log(\"**** grabArticle ****\");\n var doc = this._doc;\n var isPaging = page !== null;\n page = page ? page : this._doc.body;\n\n // We can't grab an article if we don't have a page!\n if (!page) {\n this.log(\"No body found in document. Abort.\");\n return null;\n }\n\n var pageCacheHtml = page.innerHTML;\n\n while (true) {\n this.log(\"Starting grabArticle loop\");\n var stripUnlikelyCandidates = this._flagIsActive(this.FLAG_STRIP_UNLIKELYS);\n\n // First, node prepping. Trash nodes that look cruddy (like ones with the\n // class name \"comment\", etc), and turn divs into P tags where they have been\n // used inappropriately (as in, where they contain no other block level elements.)\n var elementsToScore = [];\n var node = this._doc.documentElement;\n\n let shouldRemoveTitleHeader = true;\n\n while (node) {\n\n if (node.tagName === \"HTML\") {\n this._articleLang = node.getAttribute(\"lang\");\n }\n\n var matchString = node.className + \" \" + node.id;\n\n if (!this._isProbablyVisible(node)) {\n this.log(\"Removing hidden node - \" + matchString);\n node = this._removeAndGetNext(node);\n continue;\n }\n\n // User is not able to see elements applied with both \"aria-modal = true\" and \"role = dialog\"\n if (node.getAttribute(\"aria-modal\") == \"true\" && node.getAttribute(\"role\") == \"dialog\") {\n node = this._removeAndGetNext(node);\n continue;\n }\n\n // Check to see if this node is a byline, and remove it if it is.\n if (this._checkByline(node, matchString)) {\n node = this._removeAndGetNext(node);\n continue;\n }\n\n if (shouldRemoveTitleHeader && this._headerDuplicatesTitle(node)) {\n this.log(\"Removing header: \", node.textContent.trim(), this._articleTitle.trim());\n shouldRemoveTitleHeader = false;\n node = this._removeAndGetNext(node);\n continue;\n }\n\n // Remove unlikely candidates\n if (stripUnlikelyCandidates) {\n if (this.REGEXPS.unlikelyCandidates.test(matchString) &&\n !this.REGEXPS.okMaybeItsACandidate.test(matchString) &&\n !this._hasAncestorTag(node, \"table\") &&\n !this._hasAncestorTag(node, \"code\") &&\n node.tagName !== \"BODY\" &&\n node.tagName !== \"A\") {\n this.log(\"Removing unlikely candidate - \" + matchString);\n node = this._removeAndGetNext(node);\n continue;\n }\n\n if (this.UNLIKELY_ROLES.includes(node.getAttribute(\"role\"))) {\n this.log(\"Removing content with role \" + node.getAttribute(\"role\") + \" - \" + matchString);\n node = this._removeAndGetNext(node);\n continue;\n }\n }\n\n // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).\n if ((node.tagName === \"DIV\" || node.tagName === \"SECTION\" || node.tagName === \"HEADER\" ||\n node.tagName === \"H1\" || node.tagName === \"H2\" || node.tagName === \"H3\" ||\n node.tagName === \"H4\" || node.tagName === \"H5\" || node.tagName === \"H6\") &&\n this._isElementWithoutContent(node)) {\n node = this._removeAndGetNext(node);\n continue;\n }\n\n if (this.DEFAULT_TAGS_TO_SCORE.indexOf(node.tagName) !== -1) {\n elementsToScore.push(node);\n }\n\n // Turn all divs that don't have children block level elements into p's\n if (node.tagName === \"DIV\") {\n // Put phrasing content into paragraphs.\n var p = null;\n var childNode = node.firstChild;\n while (childNode) {\n var nextSibling = childNode.nextSibling;\n if (this._isPhrasingContent(childNode)) {\n if (p !== null) {\n p.appendChild(childNode);\n } else if (!this._isWhitespace(childNode)) {\n p = doc.createElement(\"p\");\n node.replaceChild(p, childNode);\n p.appendChild(childNode);\n }\n } else if (p !== null) {\n while (p.lastChild && this._isWhitespace(p.lastChild)) {\n p.removeChild(p.lastChild);\n }\n p = null;\n }\n childNode = nextSibling;\n }\n\n // Sites like http://mobile.slate.com encloses each paragraph with a DIV\n // element. DIVs with only a P element inside and no text content can be\n // safely converted into plain P elements to avoid confusing the scoring\n // algorithm with DIVs with are, in practice, paragraphs.\n if (this._hasSingleTagInsideElement(node, \"P\") && this._getLinkDensity(node) < 0.25) {\n var newNode = node.children[0];\n node.parentNode.replaceChild(newNode, node);\n node = newNode;\n elementsToScore.push(node);\n } else if (!this._hasChildBlockElement(node)) {\n node = this._setNodeTag(node, \"P\");\n elementsToScore.push(node);\n }\n }\n node = this._getNextNode(node);\n }\n\n /**\n * Loop through all paragraphs, and assign a score to them based on how content-y they look.\n * Then add their score to their parent node.\n *\n * A score is determined by things like number of commas, class names, etc. Maybe eventually link density.\n **/\n var candidates = [];\n this._forEachNode(elementsToScore, function(elementToScore) {\n if (!elementToScore.parentNode || typeof(elementToScore.parentNode.tagName) === \"undefined\")\n return;\n\n // If this paragraph is less than 25 characters, don't even count it.\n var innerText = this._getInnerText(elementToScore);\n if (innerText.length < 25)\n return;\n\n // Exclude nodes with no ancestor.\n var ancestors = this._getNodeAncestors(elementToScore, 5);\n if (ancestors.length === 0)\n return;\n\n var contentScore = 0;\n\n // Add a point for the paragraph itself as a base.\n contentScore += 1;\n\n // Add points for any commas within this paragraph.\n contentScore += innerText.split(this.REGEXPS.commas).length;\n\n // For every 100 characters in this paragraph, add another point. Up to 3 points.\n contentScore += Math.min(Math.floor(innerText.length / 100), 3);\n\n // Initialize and score ancestors.\n this._forEachNode(ancestors, function(ancestor, level) {\n if (!ancestor.tagName || !ancestor.parentNode || typeof(ancestor.parentNode.tagName) === \"undefined\")\n return;\n\n if (typeof(ancestor.readability) === \"undefined\") {\n this._initializeNode(ancestor);\n candidates.push(ancestor);\n }\n\n // Node score divider:\n // - parent: 1 (no division)\n // - grandparent: 2\n // - great grandparent+: ancestor level * 3\n if (level === 0)\n var scoreDivider = 1;\n else if (level === 1)\n scoreDivider = 2;\n else\n scoreDivider = level * 3;\n ancestor.readability.contentScore += contentScore / scoreDivider;\n });\n });\n\n // After we've calculated scores, loop through all of the possible\n // candidate nodes we found and find the one with the highest score.\n var topCandidates = [];\n for (var c = 0, cl = candidates.length; c < cl; c += 1) {\n var candidate = candidates[c];\n\n // Scale the final candidates score based on link density. Good content\n // should have a relatively small link density (5% or less) and be mostly\n // unaffected by this operation.\n var candidateScore = candidate.readability.contentScore * (1 - this._getLinkDensity(candidate));\n candidate.readability.contentScore = candidateScore;\n\n this.log(\"Candidate:\", candidate, \"with score \" + candidateScore);\n\n for (var t = 0; t < this._nbTopCandidates; t++) {\n var aTopCandidate = topCandidates[t];\n\n if (!aTopCandidate || candidateScore > aTopCandidate.readability.contentScore) {\n topCandidates.splice(t, 0, candidate);\n if (topCandidates.length > this._nbTopCandidates)\n topCandidates.pop();\n break;\n }\n }\n }\n\n var topCandidate = topCandidates[0] || null;\n var neededToCreateTopCandidate = false;\n var parentOfTopCandidate;\n\n // If we still have no top candidate, just use the body as a last resort.\n // We also have to copy the body node so it is something we can modify.\n if (topCandidate === null || topCandidate.tagName === \"BODY\") {\n // Move all of the page's children into topCandidate\n topCandidate = doc.createElement(\"DIV\");\n neededToCreateTopCandidate = true;\n // Move everything (not just elements, also text nodes etc.) into the container\n // so we even include text directly in the body:\n while (page.firstChild) {\n this.log(\"Moving child out:\", page.firstChild);\n topCandidate.appendChild(page.firstChild);\n }\n\n page.appendChild(topCandidate);\n\n this._initializeNode(topCandidate);\n } else if (topCandidate) {\n // Find a better top candidate node if it contains (at least three) nodes which belong to `topCandidates` array\n // and whose scores are quite closed with current `topCandidate` node.\n var alternativeCandidateAncestors = [];\n for (var i = 1; i < topCandidates.length; i++) {\n if (topCandidates[i].readability.contentScore / topCandidate.readability.contentScore >= 0.75) {\n alternativeCandidateAncestors.push(this._getNodeAncestors(topCandidates[i]));\n }\n }\n var MINIMUM_TOPCANDIDATES = 3;\n if (alternativeCandidateAncestors.length >= MINIMUM_TOPCANDIDATES) {\n parentOfTopCandidate = topCandidate.parentNode;\n while (parentOfTopCandidate.tagName !== \"BODY\") {\n var listsContainingThisAncestor = 0;\n for (var ancestorIndex = 0; ancestorIndex < alternativeCandidateAncestors.length && listsContainingThisAncestor < MINIMUM_TOPCANDIDATES; ancestorIndex++) {\n listsContainingThisAncestor += Number(alternativeCandidateAncestors[ancestorIndex].includes(parentOfTopCandidate));\n }\n if (listsContainingThisAncestor >= MINIMUM_TOPCANDIDATES) {\n topCandidate = parentOfTopCandidate;\n break;\n }\n parentOfTopCandidate = parentOfTopCandidate.parentNode;\n }\n }\n if (!topCandidate.readability) {\n this._initializeNode(topCandidate);\n }\n\n // Because of our bonus system, parents of candidates might have scores\n // themselves. They get half of the node. There won't be nodes with higher\n // scores than our topCandidate, but if we see the score going *up* in the first\n // few steps up the tree, that's a decent sign that there might be more content\n // lurking in other places that we want to unify in. The sibling stuff\n // below does some of that - but only if we've looked high enough up the DOM\n // tree.\n parentOfTopCandidate = topCandidate.parentNode;\n var lastScore = topCandidate.readability.contentScore;\n // The scores shouldn't get too low.\n var scoreThreshold = lastScore / 3;\n while (parentOfTopCandidate.tagName !== \"BODY\") {\n if (!parentOfTopCandidate.readability) {\n parentOfTopCandidate = parentOfTopCandidate.parentNode;\n continue;\n }\n var parentScore = parentOfTopCandidate.readability.contentScore;\n if (parentScore < scoreThreshold)\n break;\n if (parentScore > lastScore) {\n // Alright! We found a better parent to use.\n topCandidate = parentOfTopCandidate;\n break;\n }\n lastScore = parentOfTopCandidate.readability.contentScore;\n parentOfTopCandidate = parentOfTopCandidate.parentNode;\n }\n\n // If the top candidate is the only child, use parent instead. This will help sibling\n // joining logic when adjacent content is actually located in parent's sibling node.\n parentOfTopCandidate = topCandidate.parentNode;\n while (parentOfTopCandidate.tagName != \"BODY\" && parentOfTopCandidate.children.length == 1) {\n topCandidate = parentOfTopCandidate;\n parentOfTopCandidate = topCandidate.parentNode;\n }\n if (!topCandidate.readability) {\n this._initializeNode(topCandidate);\n }\n }\n\n // Now that we have the top candidate, look through its siblings for content\n // that might also be related. Things like preambles, content split by ads\n // that we removed, etc.\n var articleContent = doc.createElement(\"DIV\");\n if (isPaging)\n articleContent.id = \"readability-content\";\n\n var siblingScoreThreshold = Math.max(10, topCandidate.readability.contentScore * 0.2);\n // Keep potential top candidate's parent node to try to get text direction of it later.\n parentOfTopCandidate = topCandidate.parentNode;\n var siblings = parentOfTopCandidate.children;\n\n for (var s = 0, sl = siblings.length; s < sl; s++) {\n var sibling = siblings[s];\n var append = false;\n\n this.log(\"Looking at sibling node:\", sibling, sibling.readability ? (\"with score \" + sibling.readability.contentScore) : \"\");\n this.log(\"Sibling has score\", sibling.readability ? sibling.readability.contentScore : \"Unknown\");\n\n if (sibling === topCandidate) {\n append = true;\n } else {\n var contentBonus = 0;\n\n // Give a bonus if sibling nodes and top candidates have the example same classname\n if (sibling.className === topCandidate.className && topCandidate.className !== \"\")\n contentBonus += topCandidate.readability.contentScore * 0.2;\n\n if (sibling.readability &&\n ((sibling.readability.contentScore + contentBonus) >= siblingScoreThreshold)) {\n append = true;\n } else if (sibling.nodeName === \"P\") {\n var linkDensity = this._getLinkDensity(sibling);\n var nodeContent = this._getInnerText(sibling);\n var nodeLength = nodeContent.length;\n\n if (nodeLength > 80 && linkDensity < 0.25) {\n append = true;\n } else if (nodeLength < 80 && nodeLength > 0 && linkDensity === 0 &&\n nodeContent.search(/\\.( |$)/) !== -1) {\n append = true;\n }\n }\n }\n\n if (append) {\n this.log(\"Appending node:\", sibling);\n\n if (this.ALTER_TO_DIV_EXCEPTIONS.indexOf(sibling.nodeName) === -1) {\n // We have a node that isn't a common block level element, like a form or td tag.\n // Turn it into a div so it doesn't get filtered out later by accident.\n this.log(\"Altering sibling:\", sibling, \"to div.\");\n\n sibling = this._setNodeTag(sibling, \"DIV\");\n }\n\n articleContent.appendChild(sibling);\n // Fetch children again to make it compatible\n // with DOM parsers without live collection support.\n siblings = parentOfTopCandidate.children;\n // siblings is a reference to the children array, and\n // sibling is removed from the array when we call appendChild().\n // As a result, we must revisit this index since the nodes\n // have been shifted.\n s -= 1;\n sl -= 1;\n }\n }\n\n if (this._debug)\n this.log(\"Article content pre-prep: \" + articleContent.innerHTML);\n // So we have all of the content that we need. Now we clean it up for presentation.\n this._prepArticle(articleContent);\n if (this._debug)\n this.log(\"Article content post-prep: \" + articleContent.innerHTML);\n\n if (neededToCreateTopCandidate) {\n // We already created a fake div thing, and there wouldn't have been any siblings left\n // for the previous loop, so there's no point trying to create a new div, and then\n // move all the children over. Just assign IDs and class names here. No need to append\n // because that already happened anyway.\n topCandidate.id = \"readability-page-1\";\n topCandidate.className = \"page\";\n } else {\n var div = doc.createElement(\"DIV\");\n div.id = \"readability-page-1\";\n div.className = \"page\";\n while (articleContent.firstChild) {\n div.appendChild(articleContent.firstChild);\n }\n articleContent.appendChild(div);\n }\n\n if (this._debug)\n this.log(\"Article content after paging: \" + articleContent.innerHTML);\n\n var parseSuccessful = true;\n\n // Now that we've gone through the full algorithm, check to see if\n // we got any meaningful content. If we didn't, we may need to re-run\n // grabArticle with different flags set. This gives us a higher likelihood of\n // finding the content, and the sieve approach gives us a higher likelihood of\n // finding the -right- content.\n var textLength = this._getInnerText(articleContent, true).length;\n if (textLength < this._charThreshold) {\n parseSuccessful = false;\n page.innerHTML = pageCacheHtml;\n\n if (this._flagIsActive(this.FLAG_STRIP_UNLIKELYS)) {\n this._removeFlag(this.FLAG_STRIP_UNLIKELYS);\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n } else if (this._flagIsActive(this.FLAG_WEIGHT_CLASSES)) {\n this._removeFlag(this.FLAG_WEIGHT_CLASSES);\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n } else if (this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY)) {\n this._removeFlag(this.FLAG_CLEAN_CONDITIONALLY);\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n } else {\n this._attempts.push({articleContent: articleContent, textLength: textLength});\n // No luck after removing flags, just return the longest text we found during the different loops\n this._attempts.sort(function (a, b) {\n return b.textLength - a.textLength;\n });\n\n // But first check if we actually have something\n if (!this._attempts[0].textLength) {\n return null;\n }\n\n articleContent = this._attempts[0].articleContent;\n parseSuccessful = true;\n }\n }\n\n if (parseSuccessful) {\n // Find out text direction from ancestors of final top candidate.\n var ancestors = [parentOfTopCandidate, topCandidate].concat(this._getNodeAncestors(parentOfTopCandidate));\n this._someNode(ancestors, function(ancestor) {\n if (!ancestor.tagName)\n return false;\n var articleDir = ancestor.getAttribute(\"dir\");\n if (articleDir) {\n this._articleDir = articleDir;\n return true;\n }\n return false;\n });\n return articleContent;\n }\n }\n },\n\n /**\n * Check whether the input string could be a byline.\n * This verifies that the input is a string, and that the length\n * is less than 100 chars.\n *\n * @param possibleByline {string} - a string to check whether its a byline.\n * @return Boolean - whether the input string is a byline.\n */\n _isValidByline: function(byline) {\n if (typeof byline == \"string\" || byline instanceof String) {\n byline = byline.trim();\n return (byline.length > 0) && (byline.length < 100);\n }\n return false;\n },\n\n /**\n * Converts some of the common HTML entities in string to their corresponding characters.\n *\n * @param str {string} - a string to unescape.\n * @return string without HTML entity.\n */\n _unescapeHtmlEntities: function(str) {\n if (!str) {\n return str;\n }\n\n var htmlEscapeMap = this.HTML_ESCAPE_MAP;\n return str.replace(/&(quot|amp|apos|lt|gt);/g, function(_, tag) {\n return htmlEscapeMap[tag];\n }).replace(/(?:x([0-9a-z]{1,4})|([0-9]{1,4}));/gi, function(_, hex, numStr) {\n var num = parseInt(hex || numStr, hex ? 16 : 10);\n return String.fromCharCode(num);\n });\n },\n\n /**\n * Try to extract metadata from JSON-LD object.\n * For now, only Schema.org objects of type Article or its subtypes are supported.\n * @return Object with any metadata that could be extracted (possibly none)\n */\n _getJSONLD: function (doc) {\n var scripts = this._getAllNodesWithTag(doc, [\"script\"]);\n\n var metadata;\n\n this._forEachNode(scripts, function(jsonLdElement) {\n if (!metadata && jsonLdElement.getAttribute(\"type\") === \"application/ld+json\") {\n try {\n // Strip CDATA markers if present\n var content = jsonLdElement.textContent.replace(/^\\s*\\s*$/g, \"\");\n var parsed = JSON.parse(content);\n if (\n !parsed[\"@context\"] ||\n !parsed[\"@context\"].match(/^https?\\:\\/\\/schema\\.org$/)\n ) {\n return;\n }\n\n if (!parsed[\"@type\"] && Array.isArray(parsed[\"@graph\"])) {\n parsed = parsed[\"@graph\"].find(function(it) {\n return (it[\"@type\"] || \"\").match(\n this.REGEXPS.jsonLdArticleTypes\n );\n });\n }\n\n if (\n !parsed ||\n !parsed[\"@type\"] ||\n !parsed[\"@type\"].match(this.REGEXPS.jsonLdArticleTypes)\n ) {\n return;\n }\n\n metadata = {};\n\n if (typeof parsed.name === \"string\" && typeof parsed.headline === \"string\" && parsed.name !== parsed.headline) {\n // we have both name and headline element in the JSON-LD. They should both be the same but some websites like aktualne.cz\n // put their own name into \"name\" and the article title to \"headline\" which confuses Readability. So we try to check if either\n // \"name\" or \"headline\" closely matches the html title, and if so, use that one. If not, then we use \"name\" by default.\n\n var title = this._getArticleTitle();\n var nameMatches = this._textSimilarity(parsed.name, title) > 0.75;\n var headlineMatches = this._textSimilarity(parsed.headline, title) > 0.75;\n\n if (headlineMatches && !nameMatches) {\n metadata.title = parsed.headline;\n } else {\n metadata.title = parsed.name;\n }\n } else if (typeof parsed.name === \"string\") {\n metadata.title = parsed.name.trim();\n } else if (typeof parsed.headline === \"string\") {\n metadata.title = parsed.headline.trim();\n }\n if (parsed.author) {\n if (typeof parsed.author.name === \"string\") {\n metadata.byline = parsed.author.name.trim();\n } else if (Array.isArray(parsed.author) && parsed.author[0] && typeof parsed.author[0].name === \"string\") {\n metadata.byline = parsed.author\n .filter(function(author) {\n return author && typeof author.name === \"string\";\n })\n .map(function(author) {\n return author.name.trim();\n })\n .join(\", \");\n }\n }\n if (typeof parsed.description === \"string\") {\n metadata.excerpt = parsed.description.trim();\n }\n if (\n parsed.publisher &&\n typeof parsed.publisher.name === \"string\"\n ) {\n metadata.siteName = parsed.publisher.name.trim();\n }\n if (typeof parsed.datePublished === \"string\") {\n metadata.datePublished = parsed.datePublished.trim();\n }\n return;\n } catch (err) {\n this.log(err.message);\n }\n }\n });\n return metadata ? metadata : {};\n },\n\n /**\n * Attempts to get excerpt and byline metadata for the article.\n *\n * @param {Object} jsonld — object containing any metadata that\n * could be extracted from JSON-LD object.\n *\n * @return Object with optional \"excerpt\" and \"byline\" properties\n */\n _getArticleMetadata: function(jsonld) {\n var metadata = {};\n var values = {};\n var metaElements = this._doc.getElementsByTagName(\"meta\");\n\n // property is a space-separated list of values\n var propertyPattern = /\\s*(article|dc|dcterm|og|twitter)\\s*:\\s*(author|creator|description|published_time|title|site_name)\\s*/gi;\n\n // name is a single value\n var namePattern = /^\\s*(?:(dc|dcterm|og|twitter|weibo:(article|webpage))\\s*[\\.:]\\s*)?(author|creator|description|title|site_name)\\s*$/i;\n\n // Find description tags.\n this._forEachNode(metaElements, function(element) {\n var elementName = element.getAttribute(\"name\");\n var elementProperty = element.getAttribute(\"property\");\n var content = element.getAttribute(\"content\");\n if (!content) {\n return;\n }\n var matches = null;\n var name = null;\n\n if (elementProperty) {\n matches = elementProperty.match(propertyPattern);\n if (matches) {\n // Convert to lowercase, and remove any whitespace\n // so we can match below.\n name = matches[0].toLowerCase().replace(/\\s/g, \"\");\n // multiple authors\n values[name] = content.trim();\n }\n }\n if (!matches && elementName && namePattern.test(elementName)) {\n name = elementName;\n if (content) {\n // Convert to lowercase, remove any whitespace, and convert dots\n // to colons so we can match below.\n name = name.toLowerCase().replace(/\\s/g, \"\").replace(/\\./g, \":\");\n values[name] = content.trim();\n }\n }\n });\n\n // get title\n metadata.title = jsonld.title ||\n values[\"dc:title\"] ||\n values[\"dcterm:title\"] ||\n values[\"og:title\"] ||\n values[\"weibo:article:title\"] ||\n values[\"weibo:webpage:title\"] ||\n values[\"title\"] ||\n values[\"twitter:title\"];\n\n if (!metadata.title) {\n metadata.title = this._getArticleTitle();\n }\n\n // get author\n metadata.byline = jsonld.byline ||\n values[\"dc:creator\"] ||\n values[\"dcterm:creator\"] ||\n values[\"author\"];\n\n // get description\n metadata.excerpt = jsonld.excerpt ||\n values[\"dc:description\"] ||\n values[\"dcterm:description\"] ||\n values[\"og:description\"] ||\n values[\"weibo:article:description\"] ||\n values[\"weibo:webpage:description\"] ||\n values[\"description\"] ||\n values[\"twitter:description\"];\n\n // get site name\n metadata.siteName = jsonld.siteName ||\n values[\"og:site_name\"];\n\n // get article published time\n metadata.publishedTime = jsonld.datePublished ||\n values[\"article:published_time\"] || null;\n\n // in many sites the meta value is escaped with HTML entities,\n // so here we need to unescape it\n metadata.title = this._unescapeHtmlEntities(metadata.title);\n metadata.byline = this._unescapeHtmlEntities(metadata.byline);\n metadata.excerpt = this._unescapeHtmlEntities(metadata.excerpt);\n metadata.siteName = this._unescapeHtmlEntities(metadata.siteName);\n metadata.publishedTime = this._unescapeHtmlEntities(metadata.publishedTime);\n\n return metadata;\n },\n\n /**\n * Check if node is image, or if node contains exactly only one image\n * whether as a direct child or as its descendants.\n *\n * @param Element\n **/\n _isSingleImage: function(node) {\n if (node.tagName === \"IMG\") {\n return true;\n }\n\n if (node.children.length !== 1 || node.textContent.trim() !== \"\") {\n return false;\n }\n\n return this._isSingleImage(node.children[0]);\n },\n\n /**\n * Find all that are located after nodes, and which contain only one\n * element. Replace the first image with the image from inside the tag,\n * and remove the tag. This improves the quality of the images we use on\n * some sites (e.g. Medium).\n *\n * @param Element\n **/\n _unwrapNoscriptImages: function(doc) {\n // Find img without source or attributes that might contains image, and remove it.\n // This is done to prevent a placeholder img is replaced by img from noscript in next step.\n var imgs = Array.from(doc.getElementsByTagName(\"img\"));\n this._forEachNode(imgs, function(img) {\n for (var i = 0; i < img.attributes.length; i++) {\n var attr = img.attributes[i];\n switch (attr.name) {\n case \"src\":\n case \"srcset\":\n case \"data-src\":\n case \"data-srcset\":\n return;\n }\n\n if (/\\.(jpg|jpeg|png|webp)/i.test(attr.value)) {\n return;\n }\n }\n\n img.parentNode.removeChild(img);\n });\n\n // Next find noscript and try to extract its image\n var noscripts = Array.from(doc.getElementsByTagName(\"noscript\"));\n this._forEachNode(noscripts, function(noscript) {\n // Parse content of noscript and make sure it only contains image\n var tmp = doc.createElement(\"div\");\n tmp.innerHTML = noscript.innerHTML;\n if (!this._isSingleImage(tmp)) {\n return;\n }\n\n // If noscript has previous sibling and it only contains image,\n // replace it with noscript content. However we also keep old\n // attributes that might contains image.\n var prevElement = noscript.previousElementSibling;\n if (prevElement && this._isSingleImage(prevElement)) {\n var prevImg = prevElement;\n if (prevImg.tagName !== \"IMG\") {\n prevImg = prevElement.getElementsByTagName(\"img\")[0];\n }\n\n var newImg = tmp.getElementsByTagName(\"img\")[0];\n for (var i = 0; i < prevImg.attributes.length; i++) {\n var attr = prevImg.attributes[i];\n if (attr.value === \"\") {\n continue;\n }\n\n if (attr.name === \"src\" || attr.name === \"srcset\" || /\\.(jpg|jpeg|png|webp)/i.test(attr.value)) {\n if (newImg.getAttribute(attr.name) === attr.value) {\n continue;\n }\n\n var attrName = attr.name;\n if (newImg.hasAttribute(attrName)) {\n attrName = \"data-old-\" + attrName;\n }\n\n newImg.setAttribute(attrName, attr.value);\n }\n }\n\n noscript.parentNode.replaceChild(tmp.firstElementChild, prevElement);\n }\n });\n },\n\n /**\n * Removes script tags from the document.\n *\n * @param Element\n **/\n _removeScripts: function(doc) {\n this._removeNodes(this._getAllNodesWithTag(doc, [\"script\", \"noscript\"]));\n },\n\n /**\n * Check if this node has only whitespace and a single element with given tag\n * Returns false if the DIV node contains non-empty text nodes\n * or if it contains no element with given tag or more than 1 element.\n *\n * @param Element\n * @param string tag of child element\n **/\n _hasSingleTagInsideElement: function(element, tag) {\n // There should be exactly 1 element child with given tag\n if (element.children.length != 1 || element.children[0].tagName !== tag) {\n return false;\n }\n\n // And there should be no text nodes with real content\n return !this._someNode(element.childNodes, function(node) {\n return node.nodeType === this.TEXT_NODE &&\n this.REGEXPS.hasContent.test(node.textContent);\n });\n },\n\n _isElementWithoutContent: function(node) {\n return node.nodeType === this.ELEMENT_NODE &&\n node.textContent.trim().length == 0 &&\n (node.children.length == 0 ||\n node.children.length == node.getElementsByTagName(\"br\").length + node.getElementsByTagName(\"hr\").length);\n },\n\n /**\n * Determine whether element has any children block level elements.\n *\n * @param Element\n */\n _hasChildBlockElement: function (element) {\n return this._someNode(element.childNodes, function(node) {\n return this.DIV_TO_P_ELEMS.has(node.tagName) ||\n this._hasChildBlockElement(node);\n });\n },\n\n /***\n * Determine if a node qualifies as phrasing content.\n * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n **/\n _isPhrasingContent: function(node) {\n return node.nodeType === this.TEXT_NODE || this.PHRASING_ELEMS.indexOf(node.tagName) !== -1 ||\n ((node.tagName === \"A\" || node.tagName === \"DEL\" || node.tagName === \"INS\") &&\n this._everyNode(node.childNodes, this._isPhrasingContent));\n },\n\n _isWhitespace: function(node) {\n return (node.nodeType === this.TEXT_NODE && node.textContent.trim().length === 0) ||\n (node.nodeType === this.ELEMENT_NODE && node.tagName === \"BR\");\n },\n\n /**\n * Get the inner text of a node - cross browser compatibly.\n * This also strips out any excess whitespace to be found.\n *\n * @param Element\n * @param Boolean normalizeSpaces (default: true)\n * @return string\n **/\n _getInnerText: function(e, normalizeSpaces) {\n normalizeSpaces = (typeof normalizeSpaces === \"undefined\") ? true : normalizeSpaces;\n var textContent = e.textContent.trim();\n\n if (normalizeSpaces) {\n return textContent.replace(this.REGEXPS.normalize, \" \");\n }\n return textContent;\n },\n\n /**\n * Get the number of times a string s appears in the node e.\n *\n * @param Element\n * @param string - what to split on. Default is \",\"\n * @return number (integer)\n **/\n _getCharCount: function(e, s) {\n s = s || \",\";\n return this._getInnerText(e).split(s).length - 1;\n },\n\n /**\n * Remove the style attribute on every e and under.\n * TODO: Test if getElementsByTagName(*) is faster.\n *\n * @param Element\n * @return void\n **/\n _cleanStyles: function(e) {\n if (!e || e.tagName.toLowerCase() === \"svg\")\n return;\n\n // Remove `style` and deprecated presentational attributes\n for (var i = 0; i < this.PRESENTATIONAL_ATTRIBUTES.length; i++) {\n e.removeAttribute(this.PRESENTATIONAL_ATTRIBUTES[i]);\n }\n\n if (this.DEPRECATED_SIZE_ATTRIBUTE_ELEMS.indexOf(e.tagName) !== -1) {\n e.removeAttribute(\"width\");\n e.removeAttribute(\"height\");\n }\n\n var cur = e.firstElementChild;\n while (cur !== null) {\n this._cleanStyles(cur);\n cur = cur.nextElementSibling;\n }\n },\n\n /**\n * Get the density of links as a percentage of the content\n * This is the amount of text that is inside a link divided by the total text in the node.\n *\n * @param Element\n * @return number (float)\n **/\n _getLinkDensity: function(element) {\n var textLength = this._getInnerText(element).length;\n if (textLength === 0)\n return 0;\n\n var linkLength = 0;\n\n // XXX implement _reduceNodeList?\n this._forEachNode(element.getElementsByTagName(\"a\"), function(linkNode) {\n var href = linkNode.getAttribute(\"href\");\n var coefficient = href && this.REGEXPS.hashUrl.test(href) ? 0.3 : 1;\n linkLength += this._getInnerText(linkNode).length * coefficient;\n });\n\n return linkLength / textLength;\n },\n\n /**\n * Get an elements class/id weight. Uses regular expressions to tell if this\n * element looks good or bad.\n *\n * @param Element\n * @return number (Integer)\n **/\n _getClassWeight: function(e) {\n if (!this._flagIsActive(this.FLAG_WEIGHT_CLASSES))\n return 0;\n\n var weight = 0;\n\n // Look for a special classname\n if (typeof(e.className) === \"string\" && e.className !== \"\") {\n if (this.REGEXPS.negative.test(e.className))\n weight -= 25;\n\n if (this.REGEXPS.positive.test(e.className))\n weight += 25;\n }\n\n // Look for a special ID\n if (typeof(e.id) === \"string\" && e.id !== \"\") {\n if (this.REGEXPS.negative.test(e.id))\n weight -= 25;\n\n if (this.REGEXPS.positive.test(e.id))\n weight += 25;\n }\n\n return weight;\n },\n\n /**\n * Clean a node of all elements of type \"tag\".\n * (Unless it's a youtube/vimeo video. People love movies.)\n *\n * @param Element\n * @param string tag to clean\n * @return void\n **/\n _clean: function(e, tag) {\n var isEmbed = [\"object\", \"embed\", \"iframe\"].indexOf(tag) !== -1;\n\n this._removeNodes(this._getAllNodesWithTag(e, [tag]), function(element) {\n // Allow youtube and vimeo videos through as people usually want to see those.\n if (isEmbed) {\n // First, check the elements attributes to see if any of them contain youtube or vimeo\n for (var i = 0; i < element.attributes.length; i++) {\n if (this._allowedVideoRegex.test(element.attributes[i].value)) {\n return false;\n }\n }\n\n // For embed with tag, check inner HTML as well.\n if (element.tagName === \"object\" && this._allowedVideoRegex.test(element.innerHTML)) {\n return false;\n }\n }\n\n return true;\n });\n },\n\n /**\n * Check if a given node has one of its ancestor tag name matching the\n * provided one.\n * @param HTMLElement node\n * @param String tagName\n * @param Number maxDepth\n * @param Function filterFn a filter to invoke to determine whether this node 'counts'\n * @return Boolean\n */\n _hasAncestorTag: function(node, tagName, maxDepth, filterFn) {\n maxDepth = maxDepth || 3;\n tagName = tagName.toUpperCase();\n var depth = 0;\n while (node.parentNode) {\n if (maxDepth > 0 && depth > maxDepth)\n return false;\n if (node.parentNode.tagName === tagName && (!filterFn || filterFn(node.parentNode)))\n return true;\n node = node.parentNode;\n depth++;\n }\n return false;\n },\n\n /**\n * Return an object indicating how many rows and columns this table has.\n */\n _getRowAndColumnCount: function(table) {\n var rows = 0;\n var columns = 0;\n var trs = table.getElementsByTagName(\"tr\");\n for (var i = 0; i < trs.length; i++) {\n var rowspan = trs[i].getAttribute(\"rowspan\") || 0;\n if (rowspan) {\n rowspan = parseInt(rowspan, 10);\n }\n rows += (rowspan || 1);\n\n // Now look for column-related info\n var columnsInThisRow = 0;\n var cells = trs[i].getElementsByTagName(\"td\");\n for (var j = 0; j < cells.length; j++) {\n var colspan = cells[j].getAttribute(\"colspan\") || 0;\n if (colspan) {\n colspan = parseInt(colspan, 10);\n }\n columnsInThisRow += (colspan || 1);\n }\n columns = Math.max(columns, columnsInThisRow);\n }\n return {rows: rows, columns: columns};\n },\n\n /**\n * Look for 'data' (as opposed to 'layout') tables, for which we use\n * similar checks as\n * https://searchfox.org/mozilla-central/rev/f82d5c549f046cb64ce5602bfd894b7ae807c8f8/accessible/generic/TableAccessible.cpp#19\n */\n _markDataTables: function(root) {\n var tables = root.getElementsByTagName(\"table\");\n for (var i = 0; i < tables.length; i++) {\n var table = tables[i];\n var role = table.getAttribute(\"role\");\n if (role == \"presentation\") {\n table._readabilityDataTable = false;\n continue;\n }\n var datatable = table.getAttribute(\"datatable\");\n if (datatable == \"0\") {\n table._readabilityDataTable = false;\n continue;\n }\n var summary = table.getAttribute(\"summary\");\n if (summary) {\n table._readabilityDataTable = true;\n continue;\n }\n\n var caption = table.getElementsByTagName(\"caption\")[0];\n if (caption && caption.childNodes.length > 0) {\n table._readabilityDataTable = true;\n continue;\n }\n\n // If the table has a descendant with any of these tags, consider a data table:\n var dataTableDescendants = [\"col\", \"colgroup\", \"tfoot\", \"thead\", \"th\"];\n var descendantExists = function(tag) {\n return !!table.getElementsByTagName(tag)[0];\n };\n if (dataTableDescendants.some(descendantExists)) {\n this.log(\"Data table because found data-y descendant\");\n table._readabilityDataTable = true;\n continue;\n }\n\n // Nested tables indicate a layout table:\n if (table.getElementsByTagName(\"table\")[0]) {\n table._readabilityDataTable = false;\n continue;\n }\n\n var sizeInfo = this._getRowAndColumnCount(table);\n if (sizeInfo.rows >= 10 || sizeInfo.columns > 4) {\n table._readabilityDataTable = true;\n continue;\n }\n // Now just go by size entirely:\n table._readabilityDataTable = sizeInfo.rows * sizeInfo.columns > 10;\n }\n },\n\n /* convert images and figures that have properties like data-src into images that can be loaded without JS */\n _fixLazyImages: function (root) {\n this._forEachNode(this._getAllNodesWithTag(root, [\"img\", \"picture\", \"figure\"]), function (elem) {\n // In some sites (e.g. Kotaku), they put 1px square image as base64 data uri in the src attribute.\n // So, here we check if the data uri is too short, just might as well remove it.\n if (elem.src && this.REGEXPS.b64DataUrl.test(elem.src)) {\n // Make sure it's not SVG, because SVG can have a meaningful image in under 133 bytes.\n var parts = this.REGEXPS.b64DataUrl.exec(elem.src);\n if (parts[1] === \"image/svg+xml\") {\n return;\n }\n\n // Make sure this element has other attributes which contains image.\n // If it doesn't, then this src is important and shouldn't be removed.\n var srcCouldBeRemoved = false;\n for (var i = 0; i < elem.attributes.length; i++) {\n var attr = elem.attributes[i];\n if (attr.name === \"src\") {\n continue;\n }\n\n if (/\\.(jpg|jpeg|png|webp)/i.test(attr.value)) {\n srcCouldBeRemoved = true;\n break;\n }\n }\n\n // Here we assume if image is less than 100 bytes (or 133B after encoded to base64)\n // it will be too small, therefore it might be placeholder image.\n if (srcCouldBeRemoved) {\n var b64starts = elem.src.search(/base64\\s*/i) + 7;\n var b64length = elem.src.length - b64starts;\n if (b64length < 133) {\n elem.removeAttribute(\"src\");\n }\n }\n }\n\n // also check for \"null\" to work around https://github.com/jsdom/jsdom/issues/2580\n if ((elem.src || (elem.srcset && elem.srcset != \"null\")) && elem.className.toLowerCase().indexOf(\"lazy\") === -1) {\n return;\n }\n\n for (var j = 0; j < elem.attributes.length; j++) {\n attr = elem.attributes[j];\n if (attr.name === \"src\" || attr.name === \"srcset\" || attr.name === \"alt\") {\n continue;\n }\n var copyTo = null;\n if (/\\.(jpg|jpeg|png|webp)\\s+\\d/.test(attr.value)) {\n copyTo = \"srcset\";\n } else if (/^\\s*\\S+\\.(jpg|jpeg|png|webp)\\S*\\s*$/.test(attr.value)) {\n copyTo = \"src\";\n }\n if (copyTo) {\n //if this is an img or picture, set the attribute directly\n if (elem.tagName === \"IMG\" || elem.tagName === \"PICTURE\") {\n elem.setAttribute(copyTo, attr.value);\n } else if (elem.tagName === \"FIGURE\" && !this._getAllNodesWithTag(elem, [\"img\", \"picture\"]).length) {\n //if the item is a that does not contain an image or picture, create one and place it inside the figure\n //see the nytimes-3 testcase for an example\n var img = this._doc.createElement(\"img\");\n img.setAttribute(copyTo, attr.value);\n elem.appendChild(img);\n }\n }\n }\n });\n },\n\n _getTextDensity: function(e, tags) {\n var textLength = this._getInnerText(e, true).length;\n if (textLength === 0) {\n return 0;\n }\n var childrenLength = 0;\n var children = this._getAllNodesWithTag(e, tags);\n this._forEachNode(children, (child) => childrenLength += this._getInnerText(child, true).length);\n return childrenLength / textLength;\n },\n\n /**\n * Clean an element of all tags of type \"tag\" if they look fishy.\n * \"Fishy\" is an algorithm based on content length, classnames, link density, number of images & embeds, etc.\n *\n * @return void\n **/\n _cleanConditionally: function(e, tag) {\n if (!this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY))\n return;\n\n // Gather counts for other typical elements embedded within.\n // Traverse backwards so we can remove nodes at the same time\n // without effecting the traversal.\n //\n // TODO: Consider taking into account original contentScore here.\n this._removeNodes(this._getAllNodesWithTag(e, [tag]), function(node) {\n // First check if this node IS data table, in which case don't remove it.\n var isDataTable = function(t) {\n return t._readabilityDataTable;\n };\n\n var isList = tag === \"ul\" || tag === \"ol\";\n if (!isList) {\n var listLength = 0;\n var listNodes = this._getAllNodesWithTag(node, [\"ul\", \"ol\"]);\n this._forEachNode(listNodes, (list) => listLength += this._getInnerText(list).length);\n isList = listLength / this._getInnerText(node).length > 0.9;\n }\n\n if (tag === \"table\" && isDataTable(node)) {\n return false;\n }\n\n // Next check if we're inside a data table, in which case don't remove it as well.\n if (this._hasAncestorTag(node, \"table\", -1, isDataTable)) {\n return false;\n }\n\n if (this._hasAncestorTag(node, \"code\")) {\n return false;\n }\n\n var weight = this._getClassWeight(node);\n\n this.log(\"Cleaning Conditionally\", node);\n\n var contentScore = 0;\n\n if (weight + contentScore < 0) {\n return true;\n }\n\n if (this._getCharCount(node, \",\") < 10) {\n // If there are not very many commas, and the number of\n // non-paragraph elements is more than paragraphs or other\n // ominous signs, remove the element.\n var p = node.getElementsByTagName(\"p\").length;\n var img = node.getElementsByTagName(\"img\").length;\n var li = node.getElementsByTagName(\"li\").length - 100;\n var input = node.getElementsByTagName(\"input\").length;\n var headingDensity = this._getTextDensity(node, [\"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\"]);\n\n var embedCount = 0;\n var embeds = this._getAllNodesWithTag(node, [\"object\", \"embed\", \"iframe\"]);\n\n for (var i = 0; i < embeds.length; i++) {\n // If this embed has attribute that matches video regex, don't delete it.\n for (var j = 0; j < embeds[i].attributes.length; j++) {\n if (this._allowedVideoRegex.test(embeds[i].attributes[j].value)) {\n return false;\n }\n }\n\n // For embed with tag, check inner HTML as well.\n if (embeds[i].tagName === \"object\" && this._allowedVideoRegex.test(embeds[i].innerHTML)) {\n return false;\n }\n\n embedCount++;\n }\n\n var linkDensity = this._getLinkDensity(node);\n var contentLength = this._getInnerText(node).length;\n\n var haveToRemove =\n (img > 1 && p / img < 0.5 && !this._hasAncestorTag(node, \"figure\")) ||\n (!isList && li > p) ||\n (input > Math.floor(p/3)) ||\n (!isList && headingDensity < 0.9 && contentLength < 25 && (img === 0 || img > 2) && !this._hasAncestorTag(node, \"figure\")) ||\n (!isList && weight < 25 && linkDensity > 0.2) ||\n (weight >= 25 && linkDensity > 0.5) ||\n ((embedCount === 1 && contentLength < 75) || embedCount > 1);\n // Allow simple lists of images to remain in pages\n if (isList && haveToRemove) {\n for (var x = 0; x < node.children.length; x++) {\n let child = node.children[x];\n // Don't filter in lists with li's that contain more than one child\n if (child.children.length > 1) {\n return haveToRemove;\n }\n }\n let li_count = node.getElementsByTagName(\"li\").length;\n // Only allow the list to remain if every li contains an image\n if (img == li_count) {\n return false;\n }\n }\n return haveToRemove;\n }\n return false;\n });\n },\n\n /**\n * Clean out elements that match the specified conditions\n *\n * @param Element\n * @param Function determines whether a node should be removed\n * @return void\n **/\n _cleanMatchedNodes: function(e, filter) {\n var endOfSearchMarkerNode = this._getNextNode(e, true);\n var next = this._getNextNode(e);\n while (next && next != endOfSearchMarkerNode) {\n if (filter.call(this, next, next.className + \" \" + next.id)) {\n next = this._removeAndGetNext(next);\n } else {\n next = this._getNextNode(next);\n }\n }\n },\n\n /**\n * Clean out spurious headers from an Element.\n *\n * @param Element\n * @return void\n **/\n _cleanHeaders: function(e) {\n let headingNodes = this._getAllNodesWithTag(e, [\"h1\", \"h2\"]);\n this._removeNodes(headingNodes, function(node) {\n let shouldRemove = this._getClassWeight(node) < 0;\n if (shouldRemove) {\n this.log(\"Removing header with low class weight:\", node);\n }\n return shouldRemove;\n });\n },\n\n /**\n * Check if this node is an H1 or H2 element whose content is mostly\n * the same as the article title.\n *\n * @param Element the node to check.\n * @return boolean indicating whether this is a title-like header.\n */\n _headerDuplicatesTitle: function(node) {\n if (node.tagName != \"H1\" && node.tagName != \"H2\") {\n return false;\n }\n var heading = this._getInnerText(node, false);\n this.log(\"Evaluating similarity of header:\", heading, this._articleTitle);\n return this._textSimilarity(this._articleTitle, heading) > 0.75;\n },\n\n _flagIsActive: function(flag) {\n return (this._flags & flag) > 0;\n },\n\n _removeFlag: function(flag) {\n this._flags = this._flags & ~flag;\n },\n\n _isProbablyVisible: function(node) {\n // Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.\n return (!node.style || node.style.display != \"none\")\n && (!node.style || node.style.visibility != \"hidden\")\n && !node.hasAttribute(\"hidden\")\n //check for \"fallback-image\" so that wikimedia math images are displayed\n && (!node.hasAttribute(\"aria-hidden\") || node.getAttribute(\"aria-hidden\") != \"true\" || (node.className && node.className.indexOf && node.className.indexOf(\"fallback-image\") !== -1));\n },\n\n /**\n * Runs readability.\n *\n * Workflow:\n * 1. Prep the document by removing script tags, css, etc.\n * 2. Build readability's DOM tree.\n * 3. Grab the article content from the current dom tree.\n * 4. Replace the current DOM tree with the new one.\n * 5. Read peacefully.\n *\n * @return void\n **/\n parse: function () {\n // Avoid parsing too large documents, as per configuration option\n if (this._maxElemsToParse > 0) {\n var numTags = this._doc.getElementsByTagName(\"*\").length;\n if (numTags > this._maxElemsToParse) {\n throw new Error(\"Aborting parsing document; \" + numTags + \" elements found\");\n }\n }\n\n // Unwrap image from noscript\n this._unwrapNoscriptImages(this._doc);\n\n // Extract JSON-LD metadata before removing scripts\n var jsonLd = this._disableJSONLD ? {} : this._getJSONLD(this._doc);\n\n // Remove script tags from the document.\n this._removeScripts(this._doc);\n\n this._prepDocument();\n\n var metadata = this._getArticleMetadata(jsonLd);\n this._articleTitle = metadata.title;\n\n var articleContent = this._grabArticle();\n if (!articleContent)\n return null;\n\n this.log(\"Grabbed: \" + articleContent.innerHTML);\n\n this._postProcessContent(articleContent);\n\n // If we haven't found an excerpt in the article's metadata, use the article's\n // first paragraph as the excerpt. This is used for displaying a preview of\n // the article's content.\n if (!metadata.excerpt) {\n var paragraphs = articleContent.getElementsByTagName(\"p\");\n if (paragraphs.length > 0) {\n metadata.excerpt = paragraphs[0].textContent.trim();\n }\n }\n\n var textContent = articleContent.textContent;\n return {\n title: this._articleTitle,\n byline: metadata.byline || this._articleByline,\n dir: this._articleDir,\n lang: this._articleLang,\n content: this._serializer(articleContent),\n textContent: textContent,\n length: textContent.length,\n excerpt: metadata.excerpt,\n siteName: metadata.siteName || this._articleSiteName,\n publishedTime: metadata.publishedTime\n };\n }\n};\n\nif (typeof module === \"object\") {\n /* global module */\n module.exports = Readability;\n}\n","/* eslint-env node */\nvar Readability = require(\"./Readability\");\nvar isProbablyReaderable = require(\"./Readability-readerable\");\n\nmodule.exports = {\n Readability: Readability,\n isProbablyReaderable: isProbablyReaderable\n};\n","/*\n * Copyright (c) 2010 Arc90 Inc\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This code is heavily based on Arc90's readability.js (1.7.1) script\n * available at: http://code.google.com/p/arc90labs-readability\n */\n\nvar REGEXPS = {\n // NOTE: These two regular expressions are duplicated in\n // Readability.js. Please keep both copies in sync.\n unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,\n okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,\n};\n\nfunction isNodeVisible(node) {\n // Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.\n return (!node.style || node.style.display != \"none\")\n && !node.hasAttribute(\"hidden\")\n //check for \"fallback-image\" so that wikimedia math images are displayed\n && (!node.hasAttribute(\"aria-hidden\") || node.getAttribute(\"aria-hidden\") != \"true\" || (node.className && node.className.indexOf && node.className.indexOf(\"fallback-image\") !== -1));\n}\n\n/**\n * Decides whether or not the document is reader-able without parsing the whole thing.\n * @param {Object} options Configuration object.\n * @param {number} [options.minContentLength=140] The minimum node content length used to decide if the document is readerable.\n * @param {number} [options.minScore=20] The minumum cumulated 'score' used to determine if the document is readerable.\n * @param {Function} [options.visibilityChecker=isNodeVisible] The function used to determine if a node is visible.\n * @return {boolean} Whether or not we suspect Readability.parse() will suceeed at returning an article object.\n */\nfunction isProbablyReaderable(doc, options = {}) {\n // For backward compatibility reasons 'options' can either be a configuration object or the function used\n // to determine if a node is visible.\n if (typeof options == \"function\") {\n options = { visibilityChecker: options };\n }\n\n var defaultOptions = { minScore: 20, minContentLength: 140, visibilityChecker: isNodeVisible };\n options = Object.assign(defaultOptions, options);\n\n var nodes = doc.querySelectorAll(\"p, pre, article\");\n\n // Get nodes which have
node(s) and append them into the `nodes` variable.\n // Some articles' DOM structures might look like\n //
\n // Sentences \n // \n // Sentences \n //
\n var brNodes = doc.querySelectorAll(\"div > br\");\n if (brNodes.length) {\n var set = new Set(nodes);\n [].forEach.call(brNodes, function (node) {\n set.add(node.parentNode);\n });\n nodes = Array.from(set);\n }\n\n var score = 0;\n // This is a little cheeky, we use the accumulator 'score' to decide what to return from\n // this callback:\n return [].some.call(nodes, function (node) {\n if (!options.visibilityChecker(node)) {\n return false;\n }\n\n var matchString = node.className + \" \" + node.id;\n if (REGEXPS.unlikelyCandidates.test(matchString) &&\n !REGEXPS.okMaybeItsACandidate.test(matchString)) {\n return false;\n }\n\n if (node.matches(\"li p\")) {\n return false;\n }\n\n var textContentLength = node.textContent.trim().length;\n if (textContentLength < options.minContentLength) {\n return false;\n }\n\n score += Math.sqrt(textContentLength - options.minContentLength);\n\n if (score > options.minScore) {\n return true;\n }\n return false;\n });\n}\n\nif (typeof module === \"object\") {\n /* global module */\n module.exports = isProbablyReaderable;\n}\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { Readability } from '@mozilla/readability';\nimport { JSDOM, VirtualConsole } from 'jsdom';\nconst verifyMessages = [\n \"you are human\",\n \"are you human\",\n \"i'm not a robot\",\n \"recaptcha\"\n];\nconst getArticleContent = (_a) => __awaiter(void 0, [_a], void 0, function* ({ articles, browser, filterWords, logger }) {\n try {\n const processedArticlesPromises = articles.map(article => extractArticleContentAndFavicon({ article, browser, filterWords, logger }));\n const processedArticles = yield Promise.all(processedArticlesPromises);\n return processedArticles;\n }\n catch (err) {\n logger.error(\"getArticleContent ERROR:\", err);\n return articles;\n }\n});\nconst extractArticleContentAndFavicon = (_a) => __awaiter(void 0, [_a], void 0, function* ({ article, browser, filterWords, logger }) {\n var _b;\n try {\n const page = yield browser.newPage();\n yield page.goto(article.link, { waitUntil: 'networkidle2' });\n const content = yield page.evaluate(() => document.documentElement.innerHTML);\n const favicon = (_b = yield page.evaluate(() => {\n const link = document.querySelector('link[rel=\"icon\"], link[rel=\"shortcut icon\"]');\n return link ? link.getAttribute('href') : '';\n })) !== null && _b !== void 0 ? _b : \"\";\n const virtualConsole = new VirtualConsole();\n virtualConsole.on(\"error\", logger.error);\n const dom = new JSDOM(content, { url: article.link, virtualConsole });\n let reader = new Readability(dom.window.document);\n const articleContent = reader.parse();\n if (!articleContent || !articleContent.textContent) {\n logger.warn(\"Article content could not be parsed or is empty.\", { article });\n return Object.assign(Object.assign({}, article), { content: '', favicon });\n }\n const hasVerifyMessage = verifyMessages.find(w => articleContent.textContent.toLowerCase().includes(w));\n if (hasVerifyMessage) {\n logger.warn(\"Article requires human verification.\", { article });\n return Object.assign(Object.assign({}, article), { content: '', favicon });\n }\n const cleanedText = cleanText(articleContent.textContent, filterWords);\n if (cleanedText.split(' ').length < 100) { // Example threshold: 100 words\n logger.warn(\"Article content is too short and likely not valuable.\", { article });\n return Object.assign(Object.assign({}, article), { content: '', favicon });\n }\n logger.info(\"SUCCESSFULLY SCRAPED ARTICLE CONTENT:\", cleanedText);\n return Object.assign(Object.assign({}, article), { content: cleanedText, favicon });\n }\n catch (error) {\n logger.error(error);\n return Object.assign(Object.assign({}, article), { content: '', favicon: '' });\n }\n});\nconst cleanText = (text, filterWords) => {\n const unwantedKeywords = [\n \"subscribe now\",\n \"sign up\",\n \"newsletter\",\n \"subscribe now\",\n \"sign up for our newsletter\",\n \"exclusive offer\",\n \"limited time offer\",\n \"free trial\",\n \"download now\",\n \"join now\",\n \"register today\",\n \"special promotion\",\n \"promotional offer\",\n \"discount code\",\n \"early access\",\n \"sneak peek\",\n \"save now\",\n \"don't miss out\",\n \"act now\",\n \"last chance\",\n \"expires soon\",\n \"giveaway\",\n \"free access\",\n \"premium access\",\n \"unlock full access\",\n \"buy now\",\n \"learn more\",\n \"click here\",\n \"follow us on\",\n \"share this article\",\n \"connect with us\",\n \"advertisement\",\n \"sponsored content\",\n \"partner content\",\n \"affiliate links\",\n \"click here\",\n \"for more information\",\n \"you may also like\",\n \"we think you'll like\",\n \"from our network\",\n ...filterWords\n ];\n return text\n .split('\\n')\n .map(line => line.trim())\n .filter(line => line.split(' ').length > 4)\n .filter(line => !unwantedKeywords.some(keyword => line.toLowerCase().includes(keyword)))\n .join('\\n');\n};\nexport default getArticleContent;\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport puppeteer from 'puppeteer';\nimport * as cheerio from 'cheerio';\nimport getLogger from './getLogger';\nimport getTitle from './getTitle';\nimport getArticleType from './getArticleType';\nimport getPrettyUrl from './getPrettyUrl';\nimport buildQueryString from './buildQueryString';\nimport getArticleContent from './getArticleContent';\nconst googleNewsScraper = (userConfig) => __awaiter(void 0, void 0, void 0, function* () {\n var _a, _b;\n const config = Object.assign({\n prettyURLs: true,\n getArticleContent: false,\n puppeteerArgs: [],\n puppeteerHeadlessMode: true,\n logLevel: 'error',\n timeframe: '7d',\n queryVars: {},\n limit: 99\n }, userConfig);\n const logger = getLogger(config.logLevel);\n const queryVars = config.queryVars\n ? Object.assign(Object.assign({}, config.queryVars), { when: config.timeframe }) : { when: config.timeframe };\n if (userConfig.searchTerm) {\n queryVars.q = userConfig.searchTerm;\n }\n const queryString = (_a = buildQueryString(queryVars)) !== null && _a !== void 0 ? _a : '';\n const baseUrl = (_b = config.baseUrl) !== null && _b !== void 0 ? _b : `https://news.google.com/search`;\n const url = `${baseUrl}${queryString}`;\n logger.info(`📰 SCRAPING NEWS FROM: ${url}`);\n const requiredArgs = [\n '--disable-extensions-except=/path/to/manifest/folder/',\n '--load-extension=/path/to/manifest/folder/',\n ];\n const puppeteerConfig = {\n headless: userConfig.puppeteerHeadlessMode,\n args: puppeteer.defaultArgs().concat(config.puppeteerArgs).filter(Boolean).concat(requiredArgs)\n };\n const browser = yield puppeteer.launch(puppeteerConfig);\n const page = yield browser.newPage();\n page.setViewport({ width: 1366, height: 768 });\n page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');\n page.setRequestInterception(true);\n page.on('request', request => {\n if (!request.isNavigationRequest()) {\n request.continue();\n return;\n }\n const headers = request.headers();\n headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3';\n headers['Accept-Encoding'] = 'gzip';\n headers['Accept-Language'] = 'en-US,en;q=0.9,es;q=0.8';\n headers['Upgrade-Insecure-Requests'] = \"1\";\n headers['Referer'] = 'https://www.google.com/';\n request.continue({ headers });\n });\n yield page.setCookie({\n name: \"CONSENT\",\n value: `YES+cb.${new Date().toISOString().split('T')[0].replace(/-/g, '')}-04-p0.en-GB+FX+667`,\n domain: \".google.com\"\n });\n yield page.goto(url, { waitUntil: 'networkidle2' });\n try {\n yield page.$(`[aria-label=\"Reject all\"]`);\n yield Promise.all([\n page.click(`[aria-label=\"Reject all\"]`),\n page.waitForNavigation({ waitUntil: 'networkidle2' })\n ]);\n }\n catch (err) { }\n const content = yield page.content();\n const $ = cheerio.load(content);\n const articles = $('article');\n let results = [];\n let i = 0;\n const urlChecklist = [];\n $(articles).each(function () {\n var _a, _b, _c, _d, _e, _f, _g, _h, _j;\n const link = ((_c = (_b = (_a = $(this)) === null || _a === void 0 ? void 0 : _a.find('a[href^=\"./article\"]')) === null || _b === void 0 ? void 0 : _b.attr('href')) === null || _c === void 0 ? void 0 : _c.replace('./', 'https://news.google.com/')) || ((_f = (_e = (_d = $(this)) === null || _d === void 0 ? void 0 : _d.find('a[href^=\"./read\"]')) === null || _e === void 0 ? void 0 : _e.attr('href')) === null || _f === void 0 ? void 0 : _f.replace('./', 'https://news.google.com/')) || \"\";\n link && urlChecklist.push(link);\n const srcset = (_g = $(this).find('figure').find('img').attr('srcset')) === null || _g === void 0 ? void 0 : _g.split(' ');\n const image = srcset && srcset.length\n ? srcset[srcset.length - 2]\n : $(this).find('figure').find('img').attr('src');\n const articleType = getArticleType($(this));\n const title = getTitle($(this), articleType);\n const mainArticle = {\n title,\n \"link\": link,\n \"image\": (image === null || image === void 0 ? void 0 : image.startsWith(\"/\")) ? `https://news.google.com${image}` : image || \"\",\n \"source\": $(this).find('div[data-n-tid]').text() || \"\",\n \"datetime\": ((_j = new Date(((_h = $(this).find('div:last-child time')) === null || _h === void 0 ? void 0 : _h.attr('datetime')) || \"\")) === null || _j === void 0 ? void 0 : _j.toISOString()) || \"\",\n \"time\": $(this).find('div:last-child time').text() || \"\",\n articleType\n };\n results.push(mainArticle);\n i++;\n });\n if (config.prettyURLs) {\n results = yield Promise.all(results.map(article => {\n const url = getPrettyUrl(article.link, logger);\n if (url) {\n article.link = url;\n }\n return article;\n }));\n }\n if (config.getArticleContent) {\n const filterWords = config.filterWords || [];\n results = yield getArticleContent({ articles: results, browser, filterWords, logger });\n }\n yield page.close();\n yield browser.close();\n const filtered = results.filter(result => result.title);\n return config.limit < results.length ? filtered.slice(0, config.limit) : filtered;\n});\nexport * from \"./types\";\nexport default googleNewsScraper;\n","const buildQueryString = (query) => {\n // Bail if there's nothing in the Object\n if (Object.keys(query).length === 0)\n return \"\";\n // Build query string\n // Example: { q: 'zapatos', gl: 'ES', ceid: \"es:es\" } => '?q=zapatos&gl=ES&ceid=ES:es'\n const queryString = Object.keys(query).reduce((acc, key, index) => {\n const prefix = index === 0 ? '?' : '&';\n return `${acc}${prefix}${key}=${query[key]}`;\n }, '');\n return queryString;\n};\nexport default buildQueryString;\n","const getArticleType = (article) => {\n if (article.find('h4').text() ||\n article.find('div > div + div > div a').text())\n return \"regular\";\n if (article.find('figure').length) {\n return \"topicFeatured\";\n }\n if (article.find('> a').text())\n return \"topicSmall\";\n return \"\";\n};\nexport default getArticleType;\n","const getTitle = (article, articleType) => {\n var _a, _b;\n try {\n switch (articleType) {\n case \"regular\":\n return article.find('h4').text() || article.find('div > div + div > div a').text() || \"\";\n case \"topicFeatured\":\n return article.find('a[target=_blank]').text() || ((_a = article.find('button').attr('aria-label')) === null || _a === void 0 ? void 0 : _a.replace('More - ', '')) || \"\";\n case \"topicSmall\":\n return article.find('a[target=_blank]').text() || ((_b = article.find('button').attr('aria-label')) === null || _b === void 0 ? void 0 : _b.replace('More - ', '')) || \"\";\n default:\n return \"\";\n }\n }\n catch (err) {\n return \"\";\n }\n};\nexport default getTitle;\n","// const getPrettyUrl = (uglyUrl: string, logger: winston.Logger): string | null => {\n// const base64Match = uglyUrl.match(/\\/read\\/([A-Za-z0-9-_]+)/);\n// if (!base64Match) {\n// return null;\n// }\n// const base64String = base64Match[1];\n// try {\n// const decodedString = Buffer.from(base64String, \"base64\").toString(\"ascii\");\n// const urlPattern = /https?:\\/\\/[^\\s\"']+/g;\n// const matches = decodedString.match(urlPattern) || [];\n// const urls = matches.flatMap(match => {\n// const splitUrls = match.split(/(? {\n// const cleanUrl = url.trim().replace(/[^\\w\\-\\/:.]+$/, '').replace(/\\\\x[0-9A-Fa-f]{2}/g, '');\n// return cleanUrl;\n// });\n// });\n// const uniqueUrls = [...new Set(urls)];\n// const finalUrl = uniqueUrls.length ? uniqueUrls[0] : uglyUrl;\n// logger.info(finalUrl);\n// return finalUrl;\n// } catch (error) {\n// logger.error(error);\n// return null;\n// }\n// }\nconst getPrettyUrl = (uglyUrl, logger) => {\n var _a, _b;\n try {\n // Step 1: Extract the encoded portion between 'read/' and '?'\n let encodedPart = uglyUrl.split('read/')[1].split('?')[0];\n // Step 2: Remove 'CB' prefix if present\n if (encodedPart.startsWith('CB')) {\n encodedPart = encodedPart.substring(2);\n }\n // Step 3: Replace URL-safe Base64 characters\n encodedPart = encodedPart.replace(/-/g, '+').replace(/_/g, '/');\n // Step 4: Add padding if necessary\n const padding = '='.repeat((4 - (encodedPart.length % 4)) % 4);\n encodedPart += padding;\n // Step 5: First Base64 decode\n const firstDecodedBytes = atob(encodedPart);\n // Step 6: Extract the second encoded string (Base64 URL-safe characters)\n const secondEncodedPart = (_b = (_a = firstDecodedBytes === null || firstDecodedBytes === void 0 ? void 0 : firstDecodedBytes.match(/[A-Za-z0-9\\-_]+/g)) === null || _a === void 0 ? void 0 : _a.join('')) !== null && _b !== void 0 ? _b : '';\n // Step 7: Replace URL-safe characters in the second string\n let secondEncoded = secondEncodedPart.replace(/-/g, '+').replace(/_/g, '/');\n const secondPadding = '='.repeat((4 - (secondEncoded.length % 4)) % 4);\n secondEncoded += secondPadding;\n // Step 8: Second Base64 decode to get the final URL\n const finalURL = atob(secondEncoded);\n console.log('Final URL:', finalURL);\n return finalURL;\n }\n catch (error) {\n console.error('Error decoding URL:', error);\n return null;\n }\n};\nexport default getPrettyUrl;\n"],"names":["config","levels","none","error","warn","info","verbose","colors","winston","addColors","getLogger","level","createLogger","format","combine","colorize","simple","transports","Console","Readability","doc","options","documentElement","arguments","Error","this","_doc","_docJSDOMParser","firstChild","__JSDOMParser__","_articleTitle","_articleByline","_articleDir","_articleSiteName","_attempts","_debug","debug","_maxElemsToParse","maxElemsToParse","DEFAULT_MAX_ELEMS_TO_PARSE","_nbTopCandidates","nbTopCandidates","DEFAULT_N_TOP_CANDIDATES","_charThreshold","charThreshold","DEFAULT_CHAR_THRESHOLD","_classesToPreserve","CLASSES_TO_PRESERVE","concat","classesToPreserve","_keepClasses","keepClasses","_serializer","serializer","el","innerHTML","_disableJSONLD","disableJSONLD","_allowedVideoRegex","allowedVideoRegex","REGEXPS","videos","_flags","FLAG_STRIP_UNLIKELYS","FLAG_WEIGHT_CLASSES","FLAG_CLEAN_CONDITIONALLY","logNode","node","nodeType","TEXT_NODE","nodeName","textContent","attrPairs","Array","from","attributes","attr","name","value","join","localName","log","console","args","arg","ELEMENT_NODE","unshift","apply","dump","msg","prototype","map","call","x","DEFAULT_TAGS_TO_SCORE","toUpperCase","split","unlikelyCandidates","okMaybeItsACandidate","positive","negative","extraneous","byline","replaceFonts","normalize","shareElements","nextLink","prevLink","tokenize","whitespace","hasContent","hashUrl","srcsetUrl","b64DataUrl","commas","jsonLdArticleTypes","UNLIKELY_ROLES","DIV_TO_P_ELEMS","Set","ALTER_TO_DIV_EXCEPTIONS","PRESENTATIONAL_ATTRIBUTES","DEPRECATED_SIZE_ATTRIBUTE_ELEMS","PHRASING_ELEMS","HTML_ESCAPE_MAP","lt","gt","amp","quot","apos","_postProcessContent","articleContent","_fixRelativeUris","_simplifyNestedElements","_cleanClasses","_removeNodes","nodeList","filterFn","_isLiveNodeList","i","length","parentNode","removeChild","_replaceNodeTags","newTagName","_setNodeTag","_forEachNode","fn","forEach","_findNode","find","_someNode","some","_everyNode","every","_concatNodeLists","slice","nodeLists","list","_getAllNodesWithTag","tagNames","querySelectorAll","tag","collection","getElementsByTagName","isArray","className","getAttribute","filter","cls","indexOf","setAttribute","removeAttribute","firstElementChild","nextElementSibling","baseURI","documentURI","toAbsoluteURI","uri","charAt","URL","href","ex","links","link","childNodes","text","createTextNode","replaceChild","container","createElement","appendChild","medias","media","src","poster","srcset","newSrcset","replace","_","p1","p2","p3","includes","tagName","id","startsWith","_isElementWithoutContent","_removeAndGetNext","_hasSingleTagInsideElement","child","children","_getNextNode","_getArticleTitle","curTitle","origTitle","title","trim","_getInnerText","e","titleHadHierarchicalSeparators","wordCount","str","test","headings","trimmedTitle","heading","substring","lastIndexOf","substr","hOnes","curTitleWordCount","_prepDocument","body","_replaceBrs","_nextNode","next","nextSibling","elem","br","replaced","brSibling","p","nextElem","_isPhrasingContent","sibling","lastChild","_isWhitespace","toLowerCase","replacement","ownerDocument","readability","_prepArticle","_cleanStyles","_markDataTables","_fixLazyImages","_cleanConditionally","_clean","shareElementThreshold","topCandidate","_cleanMatchedNodes","matchString","_cleanHeaders","paragraph","table","tbody","row","cell","_initializeNode","contentScore","_getClassWeight","nextNode","ignoreSelfAndKids","_textSimilarity","textA","textB","tokensA","Boolean","tokensB","token","_checkByline","undefined","rel","itemprop","_isValidByline","_getNodeAncestors","maxDepth","ancestors","push","_grabArticle","page","isPaging","pageCacheHtml","stripUnlikelyCandidates","_flagIsActive","elementsToScore","shouldRemoveTitleHeader","_articleLang","_isProbablyVisible","_headerDuplicatesTitle","_hasAncestorTag","childNode","_getLinkDensity","newNode","_hasChildBlockElement","candidates","elementToScore","innerText","Math","min","floor","ancestor","scoreDivider","topCandidates","c","cl","candidate","candidateScore","t","aTopCandidate","splice","pop","parentOfTopCandidate","neededToCreateTopCandidate","alternativeCandidateAncestors","listsContainingThisAncestor","ancestorIndex","Number","lastScore","scoreThreshold","parentScore","siblingScoreThreshold","max","siblings","s","sl","append","contentBonus","linkDensity","nodeContent","nodeLength","search","div","parseSuccessful","textLength","_removeFlag","sort","a","b","articleDir","String","_unescapeHtmlEntities","htmlEscapeMap","hex","numStr","num","parseInt","fromCharCode","_getJSONLD","metadata","scripts","jsonLdElement","content","parsed","JSON","parse","match","it","headline","nameMatches","headlineMatches","author","description","excerpt","publisher","siteName","datePublished","err","message","_getArticleMetadata","jsonld","values","metaElements","propertyPattern","namePattern","element","elementName","elementProperty","matches","publishedTime","_isSingleImage","_unwrapNoscriptImages","imgs","img","noscripts","noscript","tmp","prevElement","previousElementSibling","prevImg","newImg","attrName","hasAttribute","_removeScripts","has","normalizeSpaces","_getCharCount","cur","linkLength","linkNode","coefficient","weight","isEmbed","depth","_getRowAndColumnCount","rows","columns","trs","rowspan","columnsInThisRow","cells","j","colspan","root","tables","_readabilityDataTable","caption","sizeInfo","exec","srcCouldBeRemoved","b64starts","copyTo","_getTextDensity","tags","childrenLength","isDataTable","isList","listLength","listNodes","li","input","headingDensity","embedCount","embeds","contentLength","haveToRemove","endOfSearchMarkerNode","headingNodes","shouldRemove","flag","style","display","visibility","numTags","jsonLd","paragraphs","dir","lang","module","require$$0","isProbablyReaderable","isNodeVisible","visibilityChecker","defaultOptions","minScore","minContentLength","Object","assign","nodes","brNodes","set","add","score","textContentLength","sqrt","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","rejected","result","done","then","verifyMessages","extractArticleContentAndFavicon","_a","article","browser","filterWords","logger","_b","newPage","goto","waitUntil","evaluate","document","favicon","querySelector","virtualConsole","VirtualConsole","on","dom","JSDOM","url","window","w","cleanedText","cleanText","unwantedKeywords","line","keyword","googleNewsScraper","userConfig","prettyURLs","getArticleContent","puppeteerArgs","puppeteerHeadlessMode","logLevel","timeframe","queryVars","limit","when","searchTerm","q","queryString","query","keys","reduce","acc","key","index","baseUrl","puppeteerConfig","headless","puppeteer","defaultArgs","launch","setViewport","width","height","setUserAgent","setRequestInterception","request","isNavigationRequest","continue","headers","setCookie","Date","toISOString","domain","$","all","click","waitForNavigation","cheerio","load","articles","results","each","_c","_d","_e","_f","_g","_h","_j","image","articleType","getTitle","mainArticle","source","datetime","time","uglyUrl","encodedPart","repeat","firstDecodedBytes","atob","secondEncoded","finalURL","getPrettyUrl","processedArticlesPromises","close","filtered"],"mappings":"4HACA,MAAMA,EAAS,CACXC,OAAQ,CACJC,KAAM,EACNC,MAAO,EACPC,KAAM,EACNC,KAAM,EACNC,QAAS,GAEbC,OAAQ,CACJL,KAAM,QACNC,MAAO,MACPC,KAAM,SACNC,KAAM,OACNC,QAAS,UAGjBE,EAAQC,UAAUT,EAAOO,QACzB,MAAMG,EAAaC,GAAWH,EAAQI,aAAa,CAC/CX,OAAQD,EAAOC,OACfY,OAAQL,EAAQK,OAAOC,QAAQN,EAAQK,OAAOE,WAAYP,EAAQK,OAAOG,UACzEC,WAAY,CACR,IAAIT,EAAQS,WAAWC,SAE3BP,uECEJ,SAASQ,EAAYC,EAAKC,GA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AAK,GAAQ,WAAWuE,SAAEA,EAAQrE,QAAEA,EAAOC,YAAEA,EAAWC,OAAEA,IAC3G,IACI,MAAM4F,EAA4BzB,EAAStd,KAAIgZ,GAAWF,EAAgC,CAAEE,UAASC,UAASC,cAAaC,aAE3H,aADgCf,QAAQ6E,IAAI8B,EAE/C,CACD,MAAOlN,GAEH,OADAsH,EAAO3e,MAAM,2BAA4BqX,GAClCyL,CACV,CACL,IC2FwB1C,CAAkB,CAAE0C,SAAUC,EAAStE,UAASC,cAAaC,UAChF,OACK7M,EAAK0S,cACL/F,EAAQ+F,QACd,MAAMC,EAAW1B,EAAQ3Y,QAAO8T,GAAUA,EAAO9Q,QACjD,OAAOvN,EAAO6gB,MAAQqC,EAAQva,OAASic,EAASjb,MAAM,EAAG3J,EAAO6gB,OAAS+D,CAC7E","x_google_ignoreList":[1,2,3]}
\ No newline at end of file
diff --git a/dist/tsc/buildQueryString.js b/dist/tsc/buildQueryString.js
index d8dfa06..0348597 100644
--- a/dist/tsc/buildQueryString.js
+++ b/dist/tsc/buildQueryString.js
@@ -3,7 +3,7 @@ const buildQueryString = (query) => {
if (Object.keys(query).length === 0)
return "";
// Build query string
- // Example: { q: 'puppies', hl: 'en', gl: 'US' } => '?q=puppies&hl=en&gl=US'
+ // Example: { q: 'zapatos', gl: 'ES', ceid: "es:es" } => '?q=zapatos&gl=ES&ceid=ES:es'
const queryString = Object.keys(query).reduce((acc, key, index) => {
const prefix = index === 0 ? '?' : '&';
return `${acc}${prefix}${key}=${query[key]}`;
diff --git a/dist/tsc/getPrettyUrl.js b/dist/tsc/getPrettyUrl.js
index c977324..c44f0b1 100644
--- a/dist/tsc/getPrettyUrl.js
+++ b/dist/tsc/getPrettyUrl.js
@@ -1,27 +1,58 @@
+// const getPrettyUrl = (uglyUrl: string, logger: winston.Logger): string | null => {
+// const base64Match = uglyUrl.match(/\/read\/([A-Za-z0-9-_]+)/);
+// if (!base64Match) {
+// return null;
+// }
+// const base64String = base64Match[1];
+// try {
+// const decodedString = Buffer.from(base64String, "base64").toString("ascii");
+// const urlPattern = /https?:\/\/[^\s"']+/g;
+// const matches = decodedString.match(urlPattern) || [];
+// const urls = matches.flatMap(match => {
+// const splitUrls = match.split(/(? {
+// const cleanUrl = url.trim().replace(/[^\w\-\/:.]+$/, '').replace(/\\x[0-9A-Fa-f]{2}/g, '');
+// return cleanUrl;
+// });
+// });
+// const uniqueUrls = [...new Set(urls)];
+// const finalUrl = uniqueUrls.length ? uniqueUrls[0] : uglyUrl;
+// logger.info(finalUrl);
+// return finalUrl;
+// } catch (error) {
+// logger.error(error);
+// return null;
+// }
+// }
const getPrettyUrl = (uglyUrl, logger) => {
- const base64Match = uglyUrl.match(/\/read\/([A-Za-z0-9-_]+)/);
- if (!base64Match) {
- return null;
- }
- const base64String = base64Match[1];
+ var _a, _b;
try {
- const decodedString = Buffer.from(base64String, "base64").toString("ascii");
- const urlPattern = /https?:\/\/[^\s"']+/g;
- const matches = decodedString.match(urlPattern) || [];
- const urls = matches.flatMap(match => {
- const splitUrls = match.split(/(? {
- const cleanUrl = url.trim().replace(/[^\w\-\/:.]+$/, '').replace(/\\x[0-9A-Fa-f]{2}/g, '');
- return cleanUrl;
- });
- });
- const uniqueUrls = [...new Set(urls)];
- const finalUrl = uniqueUrls.length ? uniqueUrls[0] : uglyUrl;
- logger.info(finalUrl);
- return finalUrl;
+ // Step 1: Extract the encoded portion between 'read/' and '?'
+ let encodedPart = uglyUrl.split('read/')[1].split('?')[0];
+ // Step 2: Remove 'CB' prefix if present
+ if (encodedPart.startsWith('CB')) {
+ encodedPart = encodedPart.substring(2);
+ }
+ // Step 3: Replace URL-safe Base64 characters
+ encodedPart = encodedPart.replace(/-/g, '+').replace(/_/g, '/');
+ // Step 4: Add padding if necessary
+ const padding = '='.repeat((4 - (encodedPart.length % 4)) % 4);
+ encodedPart += padding;
+ // Step 5: First Base64 decode
+ const firstDecodedBytes = atob(encodedPart);
+ // Step 6: Extract the second encoded string (Base64 URL-safe characters)
+ const secondEncodedPart = (_b = (_a = firstDecodedBytes === null || firstDecodedBytes === void 0 ? void 0 : firstDecodedBytes.match(/[A-Za-z0-9\-_]+/g)) === null || _a === void 0 ? void 0 : _a.join('')) !== null && _b !== void 0 ? _b : '';
+ // Step 7: Replace URL-safe characters in the second string
+ let secondEncoded = secondEncodedPart.replace(/-/g, '+').replace(/_/g, '/');
+ const secondPadding = '='.repeat((4 - (secondEncoded.length % 4)) % 4);
+ secondEncoded += secondPadding;
+ // Step 8: Second Base64 decode to get the final URL
+ const finalURL = atob(secondEncoded);
+ console.log('Final URL:', finalURL);
+ return finalURL;
}
catch (error) {
- logger.error(error);
+ console.error('Error decoding URL:', error);
return null;
}
};
diff --git a/dist/tsc/index.js b/dist/tsc/index.js
index 8a32d8a..d616e98 100644
--- a/dist/tsc/index.js
+++ b/dist/tsc/index.js
@@ -83,7 +83,7 @@ const googleNewsScraper = (userConfig) => __awaiter(void 0, void 0, void 0, func
let results = [];
let i = 0;
const urlChecklist = [];
- $(articles).each(function (i) {
+ $(articles).each(function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const link = ((_c = (_b = (_a = $(this)) === null || _a === void 0 ? void 0 : _a.find('a[href^="./article"]')) === null || _b === void 0 ? void 0 : _b.attr('href')) === null || _c === void 0 ? void 0 : _c.replace('./', 'https://news.google.com/')) || ((_f = (_e = (_d = $(this)) === null || _d === void 0 ? void 0 : _d.find('a[href^="./read"]')) === null || _e === void 0 ? void 0 : _e.attr('href')) === null || _f === void 0 ? void 0 : _f.replace('./', 'https://news.google.com/')) || "";
link && urlChecklist.push(link);
diff --git a/src/buildQueryString.ts b/src/buildQueryString.ts
index edf95a4..9ddff1a 100644
--- a/src/buildQueryString.ts
+++ b/src/buildQueryString.ts
@@ -6,7 +6,7 @@ const buildQueryString = ( query: QueryVars ) => {
if (Object.keys(query).length === 0) return "";
// Build query string
- // Example: { q: 'puppies', hl: 'en', gl: 'US' } => '?q=puppies&hl=en&gl=US'
+ // Example: { q: 'zapatos', gl: 'ES', ceid: "es:es" } => '?q=zapatos&gl=ES&ceid=ES:es'
const queryString = Object.keys(query).reduce((acc, key, index) => {
const prefix = index === 0 ? '?' : '&'
return `${acc}${prefix}${key}=${query[key]}`