Gildas 1 год назад
Родитель
Сommit
b886085d12
2 измененных файлов с 395 добавлено и 205 удалено
  1. 25 11
      src/lib/readability/Readability-readerable.js
  2. 370 194
      src/lib/readability/Readability.js

+ 25 - 11
src/lib/readability/Readability-readerable.js

@@ -1,4 +1,3 @@
-/* eslint-env es6:false */
 /*
  * Copyright (c) 2010 Arc90 Inc
  *
@@ -23,25 +22,32 @@
 var REGEXPS = {
   // NOTE: These two regular expressions are duplicated in
   // Readability.js. Please keep both copies in sync.
-  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,
+  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,
   okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,
 };
 
 function isNodeVisible(node) {
-  // Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.
-  return (!node.style || node.style.display != "none")
-    && !node.hasAttribute("hidden")
+  // Have to null-check node.style and node.className.includes to deal with SVG and MathML nodes.
+  return (
+    (!node.style || node.style.display != "none") &&
+    !node.hasAttribute("hidden") &&
     //check for "fallback-image" so that wikimedia math images are displayed
-    && (!node.hasAttribute("aria-hidden") || node.getAttribute("aria-hidden") != "true" || (node.className && node.className.indexOf && node.className.indexOf("fallback-image") !== -1));
+    (!node.hasAttribute("aria-hidden") ||
+      node.getAttribute("aria-hidden") != "true" ||
+      (node.className &&
+        node.className.includes &&
+        node.className.includes("fallback-image")))
+  );
 }
 
 /**
  * Decides whether or not the document is reader-able without parsing the whole thing.
  * @param {Object} options Configuration object.
  * @param {number} [options.minContentLength=140] The minimum node content length used to decide if the document is readerable.
- * @param {number} [options.minScore=20] The minimum cumulated 'score' used to determine if the document is readerable.
+ * @param {number} [options.minScore=20] The minumum cumulated 'score' used to determine if the document is readerable.
  * @param {Function} [options.visibilityChecker=isNodeVisible] The function used to determine if a node is visible.
- * @return {boolean} Whether or not we suspect Readability.parse() will succeed at returning an article object.
+ * @return {boolean} Whether or not we suspect Readability.parse() will suceeed at returning an article object.
  */
 function isProbablyReaderable(doc, options = {}) {
   // For backward compatibility reasons 'options' can either be a configuration object or the function used
@@ -50,7 +56,11 @@ function isProbablyReaderable(doc, options = {}) {
     options = { visibilityChecker: options };
   }
 
-  var defaultOptions = { minScore: 20, minContentLength: 140, visibilityChecker: isNodeVisible };
+  var defaultOptions = {
+    minScore: 20,
+    minContentLength: 140,
+    visibilityChecker: isNodeVisible,
+  };
   options = Object.assign(defaultOptions, options);
 
   var nodes = doc.querySelectorAll("p, pre, article");
@@ -80,8 +90,10 @@ function isProbablyReaderable(doc, options = {}) {
     }
 
     var matchString = node.className + " " + node.id;
-    if (REGEXPS.unlikelyCandidates.test(matchString) &&
-        !REGEXPS.okMaybeItsACandidate.test(matchString)) {
+    if (
+      REGEXPS.unlikelyCandidates.test(matchString) &&
+      !REGEXPS.okMaybeItsACandidate.test(matchString)
+    ) {
       return false;
     }
 
@@ -104,5 +116,7 @@ function isProbablyReaderable(doc, options = {}) {
 }
 
 if (typeof module === "object") {
+  /* eslint-disable-next-line no-redeclare */
+  /* global module */
   module.exports = isProbablyReaderable;
 }

Разница между файлами не показана из-за своего большого размера
+ 370 - 194
src/lib/readability/Readability.js


Некоторые файлы не были показаны из-за большого количества измененных файлов