auto line break for faz desktop based on regexp
This commit is contained in:
parent
80f5cda001
commit
82e0cb21ad
@ -26,7 +26,7 @@ extapi.storage.sync.get({ sitesDisabled: [] },
|
||||
|
||||
const downloadDone = (e) => {
|
||||
d.getElementsByClassName("atc-ReadTime_Text")[0].innerText = "unlocked by paywallr";
|
||||
d.getElementsByClassName("atc-TextParagraph")[0].innerText = JSON.parse(mReq.response.getElementById("schemaOrgJson").innerHTML).ArticleBody;
|
||||
d.getElementsByClassName("atc-Text js-atc-Text")[0].innerHTML = FAZify(JSON.parse(mReq.response.getElementById("schemaOrgJson").innerHTML).ArticleBody);
|
||||
console.log(window.isPaidContent);
|
||||
};
|
||||
|
||||
|
27
lib.js
27
lib.js
@ -35,3 +35,30 @@ const shortUrl = (url) => {
|
||||
if (a.length !== 2) a = a.slice(a.length - 2);
|
||||
return a.join('.');
|
||||
};
|
||||
|
||||
// line break heuristics
|
||||
const FAZify = (str) => {
|
||||
let arr = [];
|
||||
str = breakText(str);
|
||||
str.split("\n\n").forEach(
|
||||
(e) => {
|
||||
console.log(e);
|
||||
if (e.length < 100) {
|
||||
arr.push('<h3 class="atc-SubHeadline">' + e + '</h3>');
|
||||
} else {
|
||||
arr.push('<p class="atc-TextParagraph">' + e + '</p>');
|
||||
};
|
||||
}
|
||||
);
|
||||
return arr.join("");
|
||||
};
|
||||
|
||||
const breakText = (str) => {
|
||||
str = str.replace(/(?<=\w)(\.|\?|!)(?=[a-zA-Z])/gm, "$&\n\n");
|
||||
str = str.replace(/(?<=[a-z"])[A-Z]/gm, "\n\n$&")
|
||||
return str;
|
||||
};
|
||||
|
||||
const MADSACKify = (str) => {
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user