mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 10:33:33 +00:00
backout 1dbf52164ffe for bc1 failures on a CLOSED TREE
--HG-- extra : amend_source : 5f9977341e412cb0de22dfc099430aae516bc21e
This commit is contained in:
parent
f3d1e8093a
commit
c6a82ac4da
@ -63,47 +63,14 @@ this.ReaderMode = {
|
||||
|
||||
/**
|
||||
* Decides whether or not a document is reader-able without parsing the whole thing.
|
||||
* XXX: In the future, this should be smarter (bug 1143844).
|
||||
*
|
||||
* @param doc A document to parse.
|
||||
* @return boolean Whether or not we should show the reader mode button.
|
||||
*/
|
||||
isProbablyReaderable: function(doc) {
|
||||
let uri = Services.io.newURI(doc.documentURI, null, null);
|
||||
|
||||
if (!this._shouldCheckUri(uri)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let REGEXPS = {
|
||||
unlikelyCandidates: /combx|comment|community|disqus|extra|foot|header|menu|remark|rss|shoutbox|sidebar|sponsor|ad-break|agegate|pagination|pager|popup|tweet|twitter/i,
|
||||
okMaybeItsACandidate: /and|article|body|column|main|shadow/i,
|
||||
};
|
||||
|
||||
let nodes = doc.getElementsByTagName("p");
|
||||
if (nodes.length < 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let possibleParagraphs = 0;
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
let node = nodes[i];
|
||||
let matchString = node.className + " " + node.id;
|
||||
|
||||
if (REGEXPS.unlikelyCandidates.test(matchString) &&
|
||||
!REGEXPS.okMaybeItsACandidate.test(matchString)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.textContent.trim().length < 200) {
|
||||
continue;
|
||||
}
|
||||
|
||||
possibleParagraphs++;
|
||||
if (possibleParagraphs >= 5) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return this._shouldCheckUri(uri);
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user