Fix grammar issues in comments

pull/607/head
Radhi Fadlillah 4 years ago committed by Gijs
parent 89572ad29a
commit adc6accaec

@ -1317,10 +1317,10 @@ Readability.prototype = {
}, },
/** /**
* Find all <noscript> that located after <img> node, and contains exactly * Find all <noscript> that are located after <img> nodes, and which contain only one
* single <img> element. Once it found, this method will replace the previous <img> * <img> element. Replace the first image with the image from inside the <noscript> tag,
* with <img> inside <noscript>, then finally remove the <noscript> tag. This is * and remove the <noscript> tag. This improves the quality of the images we use on
* done because in some website (e.g. Medium), they use lazy load method like this. * some sites (e.g. Medium).
* *
* @param Element * @param Element
**/ **/
@ -1341,7 +1341,7 @@ Readability.prototype = {
srcset = img.getAttribute("srcset") || "", srcset = img.getAttribute("srcset") || "",
dataSrc = img.getAttribute("data-src") || "", dataSrc = img.getAttribute("data-src") || "",
dataSrcset = img.getAttribute("data-srcset") || ""; dataSrcset = img.getAttribute("data-srcset") || "";
if (src === "" && srcset === "" && dataSrc === "" && dataSrcset === "") { if (src === "" && srcset === "" && dataSrc === "" && dataSrcset === "") {
img.parentNode.removeChild(img); img.parentNode.removeChild(img);
} }
@ -1350,22 +1350,23 @@ Readability.prototype = {
// Next find noscript and try to extract its image // Next find noscript and try to extract its image
var noscripts = doc.getElementsByTagName("noscript"); var noscripts = doc.getElementsByTagName("noscript");
this._forEachNode(noscripts, function(noscript) { this._forEachNode(noscripts, function(noscript) {
// Make sure prev sibling is exist and it's image // Make sure prev sibling exists and it's image
var prevElement = noscript.previousElementSibling; var prevElement = noscript.previousElementSibling;
if (prevElement == null || prevElement.tagName !== "IMG") { if (prevElement == null || prevElement.tagName !== "IMG") {
return; return;
} }
// In jsdom content of noscript is treated as string, so here we parse it. // In spec-compliant browser, content of noscript is treated as
// string so here we parse it.
var tmp = doc.createElement("div"); var tmp = doc.createElement("div");
tmp.innerHTML = noscript.innerHTML; tmp.innerHTML = noscript.innerHTML;
// Make sure noscript only has one children, and it's <img> element // Make sure noscript only has one child, and it's <img> element
var children = tmp.children; var children = tmp.children;
if (children.length != 1 || children[0].tagName !== "IMG") { if (children.length != 1 || children[0].tagName !== "IMG") {
return; return;
} }
// At this point, just replace the previous img with img from noscript. // At this point, just replace the previous img with img from noscript.
noscript.parentNode.replaceChild(children[0], prevElement); noscript.parentNode.replaceChild(children[0], prevElement);
}); });

Loading…
Cancel
Save