From dc6b2deddd6eec906c8c9edcac2aff6ea16750c5 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Fri, 16 Jul 2021 22:05:49 +0530 Subject: [PATCH] Minor fixes --- src/screens/Chapter/TextToComponent.js | 6 +-- src/sources/en/novelupdates.js | 53 +++++++++++++++----------- src/sources/helpers/htmlToText.js | 14 +++---- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/screens/Chapter/TextToComponent.js b/src/screens/Chapter/TextToComponent.js index 94b075b5..b52c61d9 100644 --- a/src/screens/Chapter/TextToComponent.js +++ b/src/screens/Chapter/TextToComponent.js @@ -72,8 +72,8 @@ const Link = ({ textStyle, { alignSelf: "flex-start", - fontStyle: "italic", color: theme.colorAccent, + textDecorationLine: "underline", }, ]} selectable={textSelectable} @@ -93,12 +93,12 @@ const TextToComponents = ({ theme, }) => { try { - regex = /(\[.*?\]\(.*?\))/; + regex = /(\[(?:\n|.)*?\]\(.*?\))/; let parseText = text.trim().split(regex); return parseText.map((part, index) => { if (part) { - let match = part.match(/\[(.*?)\]\((.*?)\)/); + let match = part.match(/\[((?:\n|.)*?)\]\((.*?)\)/); if (match) { tag = match[1]; diff --git a/src/sources/en/novelupdates.js b/src/sources/en/novelupdates.js index c629f16b..9d862914 100644 --- a/src/sources/en/novelupdates.js +++ b/src/sources/en/novelupdates.js @@ -155,16 +155,12 @@ const parseChapter = async (novelUrl, chapterUrl) => { if (isWordPress) { isWordPress = isWordPress.toLowerCase().includes("wordpress") || - isWordPress - .toLowerCase() - .includes("Site Kit by Google 1.36.0") || + isWordPress.includes("Site Kit by Google") || $(".powered-by").text().toLowerCase().includes("wordpress") || $(".entry-content").html() || $("section.content").html() ? true : false; - - // console.log(isWordPress); } let isRainOfSnow = result.url.toLowerCase().includes("rainofsnow"); @@ -191,26 +187,30 @@ const parseChapter = async (novelUrl, chapterUrl) => { /** * Remove wordpress bloat tags */ - $(".c-ads").remove(); - $("#madara-comments").remove(); - $(".sharedaddy").remove(); - chapterText = $(".entry-content").html(); + const bloatClasses = [ + ".c-ads", + "#madara-comments", + "#comments", + ".sharedaddy", + ".wp-dark-mode-switcher", + ".wp-next-post-navi", + ".wp-block-buttons", + ".wp-block-columns", + ".post-cats", + ".sidebar", + ".author-avatar", + ]; - if (!chapterText) { - chapterText = $(".single_post").html(); - } - if (!chapterText) { - chapterText = $("article.post").html(); - } + bloatClasses.map((tag) => $(tag).remove()); - if (!chapterText) { - chapterText = $(".content").html() || $("#content").html(); - } - - /** - * Format anchor tags properly Eg. [title](https://www.example.com) - */ + chapterText = + $(".entry-content").html() || + $(".single_post").html() || + $(".post-entry").html() || + $("article.post").html() || + $(".content").html() || + $("#content").html(); } else if (isWebNovel) { chapterText = $(".cha-words").html(); @@ -229,7 +229,16 @@ const parseChapter = async (novelUrl, chapterUrl) => { } if (chapterText) { + /** + * Remove patreon/discord links + */ + chapterText = chapterText.replace( + /<\s*a[^>]*href=['"](https:\/\/(?:www.|patreon|discord).*?)['"][^>]*>([\s\S]*?)<\/\s*a\s*>/gi, + "" + ); + chapterText = htmlToText(chapterText); + console.log(chapterText); } else { if (!chapterText) { chapterText = diff --git a/src/sources/helpers/htmlToText.js b/src/sources/helpers/htmlToText.js index 5dbe5300..b16162a3 100644 --- a/src/sources/helpers/htmlToText.js +++ b/src/sources/helpers/htmlToText.js @@ -50,7 +50,7 @@ const htmlToText = (html, options = {}) => { */ .replace( - /<\s*a[^>]*href=['"](.*?)['"][^>]*>([\s\S]*?)<\/\s*a\s*>/gi, + /<\s*a[^>]*href=['"](http.*?)['"][^>]*>([\s\S]*?)<\/\s*a\s*>/gi, "[Anchor: $2]($1)" ) @@ -79,12 +79,6 @@ const htmlToText = (html, options = {}) => { .replace(/(<([^>]+)>)/gi, "") - /** - * Make sure there are never more than two consecutive linebreaks. - */ - - .replace(/\n{2,}/g, "\n\n") - /** * Remove tabs. */ @@ -103,6 +97,12 @@ const htmlToText = (html, options = {}) => { .replace(/ {2,}/g, " ") + /** + * Make sure there are never more than two consecutive linebreaks. + */ + + .replace(/\n{2,}/g, "\n\n") + /** * Decode HTML entities. */