зеркало из https://github.com/mozilla/gecko-dev.git
Bug 780713 - Disable reader mode logging by default. r=lucasr
This commit is contained in:
Родитель
bf94bc1eaa
Коммит
7fab12d963
|
@ -30,6 +30,8 @@ function dump(s) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var Readability = function(uri, doc) {
|
var Readability = function(uri, doc) {
|
||||||
|
const ENABLE_LOGGING = false;
|
||||||
|
|
||||||
this._uri = uri;
|
this._uri = uri;
|
||||||
this._doc = doc;
|
this._doc = doc;
|
||||||
this._biggestFrame = false;
|
this._biggestFrame = false;
|
||||||
|
@ -49,6 +51,15 @@ var Readability = function(uri, doc) {
|
||||||
|
|
||||||
// Make an AJAX request for each page and append it to the document.
|
// Make an AJAX request for each page and append it to the document.
|
||||||
this._curPageNum = 1;
|
this._curPageNum = 1;
|
||||||
|
|
||||||
|
// Control whether log messages are sent to the console
|
||||||
|
if (ENABLE_LOGGING) {
|
||||||
|
this.log = function (msg) {
|
||||||
|
dump("Reader: (Readability) " + msg);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.log = function () {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Readability.prototype = {
|
Readability.prototype = {
|
||||||
|
@ -222,7 +233,7 @@ Readability.prototype = {
|
||||||
doc.body = body;
|
doc.body = body;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
doc.documentElement.appendChild(body);
|
doc.documentElement.appendChild(body);
|
||||||
dump(e);
|
this.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +255,7 @@ Readability.prototype = {
|
||||||
let frameBody = frames[frameIndex].contentWindow.document.body;
|
let frameBody = frames[frameIndex].contentWindow.document.body;
|
||||||
canAccessFrame = true;
|
canAccessFrame = true;
|
||||||
} catch(eFrames) {
|
} catch(eFrames) {
|
||||||
dump(eFrames);
|
this.log(eFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameSize > biggestFrameSize) {
|
if (frameSize > biggestFrameSize) {
|
||||||
|
@ -512,7 +523,7 @@ Readability.prototype = {
|
||||||
if (unlikelyMatchString.search(this.REGEXPS.unlikelyCandidates) !== -1 &&
|
if (unlikelyMatchString.search(this.REGEXPS.unlikelyCandidates) !== -1 &&
|
||||||
unlikelyMatchString.search(this.REGEXPS.okMaybeItsACandidate) === -1 &&
|
unlikelyMatchString.search(this.REGEXPS.okMaybeItsACandidate) === -1 &&
|
||||||
node.tagName !== "BODY") {
|
node.tagName !== "BODY") {
|
||||||
dump("Removing unlikely candidate - " + unlikelyMatchString);
|
this.log("Removing unlikely candidate - " + unlikelyMatchString);
|
||||||
node.parentNode.removeChild(node);
|
node.parentNode.removeChild(node);
|
||||||
nodeIndex -= 1;
|
nodeIndex -= 1;
|
||||||
continue;
|
continue;
|
||||||
|
@ -618,7 +629,7 @@ Readability.prototype = {
|
||||||
candidates[c].readability.contentScore =
|
candidates[c].readability.contentScore =
|
||||||
candidates[c].readability.contentScore * (1 - this._getLinkDensity(candidates[c]));
|
candidates[c].readability.contentScore * (1 - this._getLinkDensity(candidates[c]));
|
||||||
|
|
||||||
dump('Candidate: ' + candidates[c] + " (" + candidates[c].className + ":" +
|
this.log('Candidate: ' + candidates[c] + " (" + candidates[c].className + ":" +
|
||||||
candidates[c].id + ") with score " +
|
candidates[c].id + ") with score " +
|
||||||
candidates[c].readability.contentScore);
|
candidates[c].readability.contentScore);
|
||||||
|
|
||||||
|
@ -669,8 +680,8 @@ Readability.prototype = {
|
||||||
let siblingNode = siblingNodes[s];
|
let siblingNode = siblingNodes[s];
|
||||||
let append = false;
|
let append = false;
|
||||||
|
|
||||||
dump("Looking at sibling node: " + siblingNode + " (" + siblingNode.className + ":" + siblingNode.id + ")" + ((typeof siblingNode.readability !== 'undefined') ? (" with score " + siblingNode.readability.contentScore) : ''));
|
this.log("Looking at sibling node: " + siblingNode + " (" + siblingNode.className + ":" + siblingNode.id + ")" + ((typeof siblingNode.readability !== 'undefined') ? (" with score " + siblingNode.readability.contentScore) : ''));
|
||||||
dump("Sibling has score " + (siblingNode.readability ? siblingNode.readability.contentScore : 'Unknown'));
|
this.log("Sibling has score " + (siblingNode.readability ? siblingNode.readability.contentScore : 'Unknown'));
|
||||||
|
|
||||||
if (siblingNode === topCandidate)
|
if (siblingNode === topCandidate)
|
||||||
append = true;
|
append = true;
|
||||||
|
@ -699,13 +710,13 @@ Readability.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (append) {
|
if (append) {
|
||||||
dump("Appending node: " + siblingNode);
|
this.log("Appending node: " + siblingNode);
|
||||||
|
|
||||||
let nodeToAppend = null;
|
let nodeToAppend = null;
|
||||||
if (siblingNode.nodeName !== "DIV" && siblingNode.nodeName !== "P") {
|
if (siblingNode.nodeName !== "DIV" && siblingNode.nodeName !== "P") {
|
||||||
// We have a node that isn't a common block level element, like a form or td tag.
|
// We have a node that isn't a common block level element, like a form or td tag.
|
||||||
// Turn it into a div so it doesn't get filtered out later by accident. */
|
// Turn it into a div so it doesn't get filtered out later by accident. */
|
||||||
dump("Altering siblingNode of " + siblingNode.nodeName + ' to div.');
|
this.log("Altering siblingNode of " + siblingNode.nodeName + ' to div.');
|
||||||
|
|
||||||
nodeToAppend = doc.createElement("DIV");
|
nodeToAppend = doc.createElement("DIV");
|
||||||
nodeToAppend.id = siblingNode.id;
|
nodeToAppend.id = siblingNode.id;
|
||||||
|
@ -1079,7 +1090,7 @@ Readability.prototype = {
|
||||||
if (topPage) {
|
if (topPage) {
|
||||||
let nextHref = topPage.href.replace(/\/$/,'');
|
let nextHref = topPage.href.replace(/\/$/,'');
|
||||||
|
|
||||||
dump('NEXT PAGE IS ' + nextHref);
|
this.log('NEXT PAGE IS ' + nextHref);
|
||||||
this._parsedPages[nextHref] = true;
|
this._parsedPages[nextHref] = true;
|
||||||
return nextHref;
|
return nextHref;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1155,7 +1166,7 @@ Readability.prototype = {
|
||||||
let eTag = r.getResponseHeader('ETag');
|
let eTag = r.getResponseHeader('ETag');
|
||||||
if (eTag) {
|
if (eTag) {
|
||||||
if (eTag in this._pageETags) {
|
if (eTag in this._pageETags) {
|
||||||
dump("Exact duplicate page found via ETag. Aborting.");
|
this.log("Exact duplicate page found via ETag. Aborting.");
|
||||||
articlePage.style.display = 'none';
|
articlePage.style.display = 'none';
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1193,7 +1204,7 @@ Readability.prototype = {
|
||||||
let content = this._grabArticle(page);
|
let content = this._grabArticle(page);
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
dump("No content found in page to append. Aborting.");
|
this.log("No content found in page to append. Aborting.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1205,7 +1216,7 @@ Readability.prototype = {
|
||||||
for (let i = 1; i <= this._curPageNum; i += 1) {
|
for (let i = 1; i <= this._curPageNum; i += 1) {
|
||||||
let rPage = doc.getElementById('readability-page-' + i);
|
let rPage = doc.getElementById('readability-page-' + i);
|
||||||
if (rPage && rPage.innerHTML.indexOf(firstP.innerHTML) !== -1) {
|
if (rPage && rPage.innerHTML.indexOf(firstP.innerHTML) !== -1) {
|
||||||
dump('Duplicate of page ' + i + ' - skipping.');
|
this.log('Duplicate of page ' + i + ' - skipping.');
|
||||||
articlePage.style.display = 'none';
|
articlePage.style.display = 'none';
|
||||||
this._parsedPages[pageUrl] = true;
|
this._parsedPages[pageUrl] = true;
|
||||||
return;
|
return;
|
||||||
|
@ -1331,7 +1342,7 @@ Readability.prototype = {
|
||||||
let weight = this._getClassWeight(tagsList[i]);
|
let weight = this._getClassWeight(tagsList[i]);
|
||||||
let contentScore = (typeof tagsList[i].readability !== 'undefined') ? tagsList[i].this._contentScore : 0;
|
let contentScore = (typeof tagsList[i].readability !== 'undefined') ? tagsList[i].this._contentScore : 0;
|
||||||
|
|
||||||
dump("Cleaning Conditionally " + tagsList[i] + " (" + tagsList[i].className + ":" + tagsList[i].id + ")" + ((typeof tagsList[i].readability !== 'undefined') ? (" with score " + tagsList[i].this._contentScore) : ''));
|
this.log("Cleaning Conditionally " + tagsList[i] + " (" + tagsList[i].className + ":" + tagsList[i].id + ")" + ((typeof tagsList[i].readability !== 'undefined') ? (" with score " + tagsList[i].this._contentScore) : ''));
|
||||||
|
|
||||||
if (weight + contentScore < 0) {
|
if (weight + contentScore < 0) {
|
||||||
tagsList[i].parentNode.removeChild(tagsList[i]);
|
tagsList[i].parentNode.removeChild(tagsList[i]);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче