From 82e0cb21adf693f7c546c25664c280d70284e0b9 Mon Sep 17 00:00:00 2001 From: tobimori Date: Fri, 17 Apr 2020 11:41:06 +0200 Subject: [PATCH] auto line break for faz desktop based on regexp --- components/faz/faz.js | 2 +- lib.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/components/faz/faz.js b/components/faz/faz.js index a3c0db2..dd16a47 100644 --- a/components/faz/faz.js +++ b/components/faz/faz.js @@ -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); }; diff --git a/lib.js b/lib.js index b9814f5..bbc823d 100644 --- a/lib.js +++ b/lib.js @@ -34,4 +34,31 @@ const shortUrl = (url) => { a = new URL(url).hostname.toString().split('.'); 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('

' + e + '

'); + } else { + arr.push('

' + e + '

'); + }; + } + ); + 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) => { + }; \ No newline at end of file