formattign pass
This commit is contained in:
parent
99ad21b850
commit
f5a03f4d05
7
makefile
7
makefile
|
@ -22,7 +22,8 @@ ADBLOCK='-L/usr/lib/wyebrowser/adblock.so' # optional adblocking; depends on htt
|
||||||
|
|
||||||
## Formatter
|
## Formatter
|
||||||
STYLE_BLUEPRINT="{BasedOnStyle: webkit, AllowShortIfStatementsOnASingleLine: true, IndentCaseLabels: true, AllowShortEnumsOnASingleLine: true}"
|
STYLE_BLUEPRINT="{BasedOnStyle: webkit, AllowShortIfStatementsOnASingleLine: true, IndentCaseLabels: true, AllowShortEnumsOnASingleLine: true}"
|
||||||
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
FORMATTER_C=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
FORMATTER_JS=npx prettier -w
|
||||||
|
|
||||||
# Runtime files
|
# Runtime files
|
||||||
MAINTAINER_CACHE_DIR=/home/nuno/.cache/rosenrot
|
MAINTAINER_CACHE_DIR=/home/nuno/.cache/rosenrot
|
||||||
|
@ -68,7 +69,9 @@ clean:
|
||||||
rm $(USER_CACHE_DIR)
|
rm $(USER_CACHE_DIR)
|
||||||
|
|
||||||
format: $(SRC) $(PLUGINS)
|
format: $(SRC) $(PLUGINS)
|
||||||
$(FORMATTER) $(SRC) $(PLUGINS) $(rosenrot.h)
|
$(FORMATTER_C) $(SRC) $(PLUGINS) $(rosenrot.h)
|
||||||
|
$(FORMATTER_JS) plugins/readability/readability.js
|
||||||
|
$(FORMATTER_JS) plugins/style/style.js
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
clang-tidy $(SRC) $(PLUGINS) -- -Wall -O3 $(INCS) -o rosenrot $(LIBS)
|
clang-tidy $(SRC) $(PLUGINS) -- -Wall -O3 $(INCS) -o rosenrot $(LIBS)
|
||||||
|
|
|
@ -32,7 +32,7 @@ function Readability(doc, options) {
|
||||||
options = arguments[2];
|
options = arguments[2];
|
||||||
} else if (!doc || !doc.documentElement) {
|
} else if (!doc || !doc.documentElement) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"First argument to Readability constructor should be a document object."
|
"First argument to Readability constructor should be a document object.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
@ -53,7 +53,7 @@ function Readability(doc, options) {
|
||||||
options.nbTopCandidates || this.DEFAULT_N_TOP_CANDIDATES;
|
options.nbTopCandidates || this.DEFAULT_N_TOP_CANDIDATES;
|
||||||
this._charThreshold = options.charThreshold || this.DEFAULT_CHAR_THRESHOLD;
|
this._charThreshold = options.charThreshold || this.DEFAULT_CHAR_THRESHOLD;
|
||||||
this._classesToPreserve = this.CLASSES_TO_PRESERVE.concat(
|
this._classesToPreserve = this.CLASSES_TO_PRESERVE.concat(
|
||||||
options.classesToPreserve || []
|
options.classesToPreserve || [],
|
||||||
);
|
);
|
||||||
this._keepClasses = !!options.keepClasses;
|
this._keepClasses = !!options.keepClasses;
|
||||||
this._serializer =
|
this._serializer =
|
||||||
|
@ -405,7 +405,7 @@ Readability.prototype = {
|
||||||
tagNames.map(function (tag) {
|
tagNames.map(function (tag) {
|
||||||
var collection = node.getElementsByTagName(tag);
|
var collection = node.getElementsByTagName(tag);
|
||||||
return Array.isArray(collection) ? collection : Array.from(collection);
|
return Array.isArray(collection) ? collection : Array.from(collection);
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ Readability.prototype = {
|
||||||
this.REGEXPS.srcsetUrl,
|
this.REGEXPS.srcsetUrl,
|
||||||
function (_, p1, p2, p3) {
|
function (_, p1, p2, p3) {
|
||||||
return toAbsoluteURI(p1) + (p2 || "") + p3;
|
return toAbsoluteURI(p1) + (p2 || "") + p3;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
media.setAttribute("srcset", newSrcset);
|
media.setAttribute("srcset", newSrcset);
|
||||||
|
@ -545,7 +545,7 @@ Readability.prototype = {
|
||||||
for (var i = 0; i < node.attributes.length; i++) {
|
for (var i = 0; i < node.attributes.length; i++) {
|
||||||
child.setAttribute(
|
child.setAttribute(
|
||||||
node.attributes[i].name,
|
node.attributes[i].name,
|
||||||
node.attributes[i].value
|
node.attributes[i].value,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
node.parentNode.replaceChild(child, node);
|
node.parentNode.replaceChild(child, node);
|
||||||
|
@ -574,7 +574,7 @@ Readability.prototype = {
|
||||||
// If they had an element with id "title" in their HTML
|
// If they had an element with id "title" in their HTML
|
||||||
if (typeof curTitle !== "string")
|
if (typeof curTitle !== "string")
|
||||||
curTitle = origTitle = this._getInnerText(
|
curTitle = origTitle = this._getInnerText(
|
||||||
doc.getElementsByTagName("title")[0]
|
doc.getElementsByTagName("title")[0],
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/* ignore exceptions setting the title. */
|
/* ignore exceptions setting the title. */
|
||||||
|
@ -599,7 +599,7 @@ Readability.prototype = {
|
||||||
// could assume it's the full title.
|
// could assume it's the full title.
|
||||||
var headings = this._concatNodeLists(
|
var headings = this._concatNodeLists(
|
||||||
doc.getElementsByTagName("h1"),
|
doc.getElementsByTagName("h1"),
|
||||||
doc.getElementsByTagName("h2")
|
doc.getElementsByTagName("h2"),
|
||||||
);
|
);
|
||||||
var trimmedTitle = curTitle.trim();
|
var trimmedTitle = curTitle.trim();
|
||||||
var match = this._someNode(headings, function (heading) {
|
var match = this._someNode(headings, function (heading) {
|
||||||
|
@ -755,7 +755,7 @@ Readability.prototype = {
|
||||||
try {
|
try {
|
||||||
replacement.setAttribute(
|
replacement.setAttribute(
|
||||||
node.attributes[i].name,
|
node.attributes[i].name,
|
||||||
node.attributes[i].value
|
node.attributes[i].value,
|
||||||
);
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
/* it's possible for setAttribute() to throw if the attribute name
|
/* it's possible for setAttribute() to throw if the attribute name
|
||||||
|
@ -825,7 +825,7 @@ Readability.prototype = {
|
||||||
// replace H1 with H2 as H1 should be only title that is displayed separately
|
// replace H1 with H2 as H1 should be only title that is displayed separately
|
||||||
this._replaceNodeTags(
|
this._replaceNodeTags(
|
||||||
this._getAllNodesWithTag(articleContent, ["h1"]),
|
this._getAllNodesWithTag(articleContent, ["h1"]),
|
||||||
"h2"
|
"h2",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove extra paragraphs
|
// Remove extra paragraphs
|
||||||
|
@ -840,7 +840,7 @@ Readability.prototype = {
|
||||||
var totalCount = imgCount + embedCount + objectCount + iframeCount;
|
var totalCount = imgCount + embedCount + objectCount + iframeCount;
|
||||||
|
|
||||||
return totalCount === 0 && !this._getInnerText(paragraph, false);
|
return totalCount === 0 && !this._getInnerText(paragraph, false);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
this._forEachNode(
|
this._forEachNode(
|
||||||
|
@ -848,7 +848,7 @@ Readability.prototype = {
|
||||||
function (br) {
|
function (br) {
|
||||||
var next = this._nextNode(br.nextSibling);
|
var next = this._nextNode(br.nextSibling);
|
||||||
if (next && next.tagName == "P") br.parentNode.removeChild(br);
|
if (next && next.tagName == "P") br.parentNode.removeChild(br);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove single-cell tables
|
// Remove single-cell tables
|
||||||
|
@ -866,12 +866,12 @@ Readability.prototype = {
|
||||||
cell,
|
cell,
|
||||||
this._everyNode(cell.childNodes, this._isPhrasingContent)
|
this._everyNode(cell.childNodes, this._isPhrasingContent)
|
||||||
? "P"
|
? "P"
|
||||||
: "DIV"
|
: "DIV",
|
||||||
);
|
);
|
||||||
table.parentNode.replaceChild(cell, table);
|
table.parentNode.replaceChild(cell, table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1032,7 +1032,7 @@ Readability.prototype = {
|
||||||
while (true) {
|
while (true) {
|
||||||
this.log("Starting grabArticle loop");
|
this.log("Starting grabArticle loop");
|
||||||
var stripUnlikelyCandidates = this._flagIsActive(
|
var stripUnlikelyCandidates = this._flagIsActive(
|
||||||
this.FLAG_STRIP_UNLIKELYS
|
this.FLAG_STRIP_UNLIKELYS,
|
||||||
);
|
);
|
||||||
|
|
||||||
// First, node prepping. Trash nodes that look cruddy (like ones with the
|
// First, node prepping. Trash nodes that look cruddy (like ones with the
|
||||||
|
@ -1066,7 +1066,7 @@ Readability.prototype = {
|
||||||
this.log(
|
this.log(
|
||||||
"Removing header: ",
|
"Removing header: ",
|
||||||
node.textContent.trim(),
|
node.textContent.trim(),
|
||||||
this._articleTitle.trim()
|
this._articleTitle.trim(),
|
||||||
);
|
);
|
||||||
shouldRemoveTitleHeader = false;
|
shouldRemoveTitleHeader = false;
|
||||||
node = this._removeAndGetNext(node);
|
node = this._removeAndGetNext(node);
|
||||||
|
@ -1093,7 +1093,7 @@ Readability.prototype = {
|
||||||
"Removing content with role " +
|
"Removing content with role " +
|
||||||
node.getAttribute("role") +
|
node.getAttribute("role") +
|
||||||
" - " +
|
" - " +
|
||||||
matchString
|
matchString,
|
||||||
);
|
);
|
||||||
node = this._removeAndGetNext(node);
|
node = this._removeAndGetNext(node);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1285,7 +1285,7 @@ Readability.prototype = {
|
||||||
0.75
|
0.75
|
||||||
) {
|
) {
|
||||||
alternativeCandidateAncestors.push(
|
alternativeCandidateAncestors.push(
|
||||||
this._getNodeAncestors(topCandidates[i])
|
this._getNodeAncestors(topCandidates[i]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1302,8 +1302,8 @@ Readability.prototype = {
|
||||||
) {
|
) {
|
||||||
listsContainingThisAncestor += Number(
|
listsContainingThisAncestor += Number(
|
||||||
alternativeCandidateAncestors[ancestorIndex].includes(
|
alternativeCandidateAncestors[ancestorIndex].includes(
|
||||||
parentOfTopCandidate
|
parentOfTopCandidate,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (listsContainingThisAncestor >= MINIMUM_TOPCANDIDATES) {
|
if (listsContainingThisAncestor >= MINIMUM_TOPCANDIDATES) {
|
||||||
|
@ -1367,7 +1367,7 @@ Readability.prototype = {
|
||||||
|
|
||||||
var siblingScoreThreshold = Math.max(
|
var siblingScoreThreshold = Math.max(
|
||||||
10,
|
10,
|
||||||
topCandidate.readability.contentScore * 0.2
|
topCandidate.readability.contentScore * 0.2,
|
||||||
);
|
);
|
||||||
// Keep potential top candidate's parent node to try to get text direction of it later.
|
// Keep potential top candidate's parent node to try to get text direction of it later.
|
||||||
parentOfTopCandidate = topCandidate.parentNode;
|
parentOfTopCandidate = topCandidate.parentNode;
|
||||||
|
@ -1382,11 +1382,11 @@ Readability.prototype = {
|
||||||
sibling,
|
sibling,
|
||||||
sibling.readability
|
sibling.readability
|
||||||
? "with score " + sibling.readability.contentScore
|
? "with score " + sibling.readability.contentScore
|
||||||
: ""
|
: "",
|
||||||
);
|
);
|
||||||
this.log(
|
this.log(
|
||||||
"Sibling has score",
|
"Sibling has score",
|
||||||
sibling.readability ? sibling.readability.contentScore : "Unknown"
|
sibling.readability ? sibling.readability.contentScore : "Unknown",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (sibling === topCandidate) {
|
if (sibling === topCandidate) {
|
||||||
|
@ -1529,7 +1529,7 @@ Readability.prototype = {
|
||||||
if (parseSuccessful) {
|
if (parseSuccessful) {
|
||||||
// Find out text direction from ancestors of final top candidate.
|
// Find out text direction from ancestors of final top candidate.
|
||||||
var ancestors = [parentOfTopCandidate, topCandidate].concat(
|
var ancestors = [parentOfTopCandidate, topCandidate].concat(
|
||||||
this._getNodeAncestors(parentOfTopCandidate)
|
this._getNodeAncestors(parentOfTopCandidate),
|
||||||
);
|
);
|
||||||
this._someNode(ancestors, function (ancestor) {
|
this._someNode(ancestors, function (ancestor) {
|
||||||
if (!ancestor.tagName) return false;
|
if (!ancestor.tagName) return false;
|
||||||
|
@ -1582,7 +1582,7 @@ Readability.prototype = {
|
||||||
function (_, hex, numStr) {
|
function (_, hex, numStr) {
|
||||||
var num = parseInt(hex || numStr, hex ? 16 : 10);
|
var num = parseInt(hex || numStr, hex ? 16 : 10);
|
||||||
return String.fromCharCode(num);
|
return String.fromCharCode(num);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1605,7 +1605,7 @@ Readability.prototype = {
|
||||||
// Strip CDATA markers if present
|
// Strip CDATA markers if present
|
||||||
var content = jsonLdElement.textContent.replace(
|
var content = jsonLdElement.textContent.replace(
|
||||||
/^\s*<!\[CDATA\[|\]\]>\s*$/g,
|
/^\s*<!\[CDATA\[|\]\]>\s*$/g,
|
||||||
""
|
"",
|
||||||
);
|
);
|
||||||
var parsed = JSON.parse(content);
|
var parsed = JSON.parse(content);
|
||||||
if (
|
if (
|
||||||
|
@ -1898,7 +1898,7 @@ Readability.prototype = {
|
||||||
scriptNode.nodeValue = "";
|
scriptNode.nodeValue = "";
|
||||||
scriptNode.removeAttribute("src");
|
scriptNode.removeAttribute("src");
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
this._removeNodes(this._getAllNodesWithTag(doc, ["noscript"]));
|
this._removeNodes(this._getAllNodesWithTag(doc, ["noscript"]));
|
||||||
},
|
},
|
||||||
|
@ -2310,7 +2310,7 @@ Readability.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2323,7 +2323,7 @@ Readability.prototype = {
|
||||||
var children = this._getAllNodesWithTag(e, tags);
|
var children = this._getAllNodesWithTag(e, tags);
|
||||||
this._forEachNode(
|
this._forEachNode(
|
||||||
children,
|
children,
|
||||||
(child) => (childrenLength += this._getInnerText(child, true).length)
|
(child) => (childrenLength += this._getInnerText(child, true).length),
|
||||||
);
|
);
|
||||||
return childrenLength / textLength;
|
return childrenLength / textLength;
|
||||||
},
|
},
|
||||||
|
@ -2354,7 +2354,7 @@ Readability.prototype = {
|
||||||
var listNodes = this._getAllNodesWithTag(node, ["ul", "ol"]);
|
var listNodes = this._getAllNodesWithTag(node, ["ul", "ol"]);
|
||||||
this._forEachNode(
|
this._forEachNode(
|
||||||
listNodes,
|
listNodes,
|
||||||
(list) => (listLength += this._getInnerText(list).length)
|
(list) => (listLength += this._getInnerText(list).length),
|
||||||
);
|
);
|
||||||
isList = listLength / this._getInnerText(node).length > 0.9;
|
isList = listLength / this._getInnerText(node).length > 0.9;
|
||||||
}
|
}
|
||||||
|
@ -2554,7 +2554,7 @@ Readability.prototype = {
|
||||||
var numTags = this._doc.getElementsByTagName("*").length;
|
var numTags = this._doc.getElementsByTagName("*").length;
|
||||||
if (numTags > this._maxElemsToParse) {
|
if (numTags > this._maxElemsToParse) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Aborting parsing document; " + numTags + " elements found"
|
"Aborting parsing document; " + numTags + " elements found",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// Main part of the code: switch on the domain and select the corresponding style
|
// Main part of the code: switch on the domain and select the corresponding style
|
||||||
var styles = null;
|
var styles = null;
|
||||||
console.log(document.domain)
|
console.log(document.domain);
|
||||||
switch (document.domain) {
|
switch (document.domain) {
|
||||||
case "forum.effectivealtruism.org":
|
case "forum.effectivealtruism.org":
|
||||||
styles = `
|
styles = `
|
||||||
|
|
Loading…
Reference in New Issue
Block a user