From ef57a986819df5078cedcc44b67b69374f0e6636 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Mon, 12 Jul 2021 09:49:05 +0530 Subject: [PATCH] Minor fixes --- src/components/EmptyView.js | 4 +- src/components/ErrorView.js | 2 +- src/components/ErrorView/ErrorView.js | 0 src/redux/settings/settings.reducer.js | 2 + src/screens/Chapter/Chapter.js | 86 ++++++++++++++++++-------- src/screens/History/History.js | 1 + src/screens/More/DownloadQueue.js | 43 ++++++++++++- src/sources/en/novelupdates.js | 66 +++++++++++++++----- src/sources/helpers/htmlToText.js | 8 +++ src/theme/theme.js | 2 +- 10 files changed, 163 insertions(+), 51 deletions(-) create mode 100644 src/components/ErrorView/ErrorView.js diff --git a/src/components/EmptyView.js b/src/components/EmptyView.js index b6078189..2a660405 100644 --- a/src/components/EmptyView.js +++ b/src/components/EmptyView.js @@ -10,7 +10,7 @@ const EmptyView = ({ icon, description, style, children, iconStyle }) => { { diff --git a/src/components/ErrorView.js b/src/components/ErrorView.js index dc2a3ad3..70cc1dce 100644 --- a/src/components/ErrorView.js +++ b/src/components/ErrorView.js @@ -17,7 +17,7 @@ const ErrorView = ({ theme, onRetry, error, openWebView }) => ( icon="reload" size={25} style={{ margin: 0, marginTop: 24 }} - color={theme.textColorSecondary} + color={theme.text} onPress={onRetry} /> Retry diff --git a/src/components/ErrorView/ErrorView.js b/src/components/ErrorView/ErrorView.js new file mode 100644 index 00000000..e69de29b diff --git a/src/redux/settings/settings.reducer.js b/src/redux/settings/settings.reducer.js index 795f93b1..97c81edb 100644 --- a/src/redux/settings/settings.reducer.js +++ b/src/redux/settings/settings.reducer.js @@ -15,6 +15,7 @@ import { irisBlueTheme, hotPinkTheme, strawberryDaiquiri, + palenightTheme, } from "../../theme/theme"; import { setRippleColor } from "./settings.actions"; @@ -27,6 +28,7 @@ const themes = { 5: irisBlueTheme, 6: hotPinkTheme, 7: strawberryDaiquiri, + 8: palenightTheme, }; /** diff --git a/src/screens/Chapter/Chapter.js b/src/screens/Chapter/Chapter.js index 34c25fd8..13293f79 100644 --- a/src/screens/Chapter/Chapter.js +++ b/src/screens/Chapter/Chapter.js @@ -224,13 +224,10 @@ const Chapter = ({ route, navigation }) => { const readerStyles = [ { - paddingVertical: 16, - paddingBottom: 32, fontSize: reader.textSize, color: reader.textColor || readerTextColor(reader.theme), lineHeight: readerLineHeight(reader.textSize, reader.lineHeight), textAlign: reader.textAlign, - paddingHorizontal: `${reader.padding}%`, }, reader.fontFamily && { fontFamily: reader.fontFamily, @@ -296,11 +293,9 @@ const Chapter = ({ route, navigation }) => { {error ? ( { style={{ flex: 1 }} > {chapter.chapterText - .split(/(\[https.*?\])/g) + .trim() + .split(/(\[https.*?\])|(_.*?_)/g) .map((part, index) => { - if (part.match(/\[https.*?\]/)) { - return ( - - ); - } else { - return ( - - {part} - - ); + if (part) { + const isItalic = + part.match(/_(.*?)_/); + const isImage = + part.match(/\[https.*?\]/); + + if (isImage) { + return ( + + ); + } else if (isItalic) { + return ( + + {isItalic[1]} + + ); + } else { + return ( + + {part} + + ); + } } })} diff --git a/src/screens/History/History.js b/src/screens/History/History.js index 803d7f3c..2c8badf5 100644 --- a/src/screens/History/History.js +++ b/src/screens/History/History.js @@ -87,6 +87,7 @@ const History = ({ navigation }) => { ]} /> item.date} renderItem={({ item }) => ( diff --git a/src/screens/More/DownloadQueue.js b/src/screens/More/DownloadQueue.js index fcbffe06..00da1c89 100644 --- a/src/screens/More/DownloadQueue.js +++ b/src/screens/More/DownloadQueue.js @@ -1,6 +1,11 @@ import React, { useEffect, useState } from "react"; import { FlatList, View, Text, StyleSheet } from "react-native"; -import { FAB, ProgressBar } from "react-native-paper"; +import { + FAB, + ProgressBar, + Appbar as MaterialAppbar, + Menu, +} from "react-native-paper"; import { useDispatch, useSelector } from "react-redux"; import { Appbar } from "../../components/Appbar"; @@ -17,6 +22,7 @@ import { import BackgroundService from "react-native-background-actions"; import { downloadAllChaptersAction } from "../../redux/novel/novel.actions"; +import { showToast } from "../../hooks/showToast"; const DownloadQueue = ({ navigation }) => { const theme = useTheme(); @@ -24,6 +30,10 @@ const DownloadQueue = ({ navigation }) => { const dispatch = useDispatch(); + const [visible, setVisible] = useState(false); + const openMenu = () => setVisible(true); + const closeMenu = () => setVisible(false); + useEffect(() => { // if (!BackgroundService.isRunning() && downloadQueue.length > 0) { // dispatch(cancelDownload()); @@ -35,7 +45,31 @@ const DownloadQueue = ({ navigation }) => { return ( - + + + } + contentStyle={{ backgroundColor: theme.menuColor }} + > + { + dispatch(cancelDownload()); + showToast("Downloads cancelled."); + BackgroundService.stop(); + closeMenu(); + }} + title="Cancel downloads" + titleStyle={{ color: theme.textColorPrimary }} + /> + + item.chapterId.toString()} @@ -46,7 +80,10 @@ const DownloadQueue = ({ navigation }) => { {item.chapterName} diff --git a/src/sources/en/novelupdates.js b/src/sources/en/novelupdates.js index 5005eb2f..962f85cc 100644 --- a/src/sources/en/novelupdates.js +++ b/src/sources/en/novelupdates.js @@ -14,7 +14,7 @@ let headers = new Headers({ const popularNovels = async (page) => { const totalPages = 100; - let url = `${baseUrl}series-ranking/?rank=sixmonths&pg=` + page; + let url = `${baseUrl}series-ranking/?rank=week&pg=` + page; const result = await fetch(url, { method: "GET", @@ -123,61 +123,93 @@ const parseNovelAndChapters = async (novelUrl) => { const parseChapter = async (novelUrl, chapterUrl) => { const url = chapterUrl; - const result = await fetch(url, { - method: "GET", - headers: headers, - }); - let body = await result.text(); + // console.log("Original URL: ", url); + + let result, body; + + try { + result = await fetch(url, { + method: "GET", + headers: headers, + }); + body = await result.text(); + } catch (error) { + chapterText = + "Chapter not available.\n\nReport if it's available in webview."; + } + + // console.log("Redirected URL: ", result.url); $ = cheerio.load(body); let chapterName = ""; - let isWuxiaWorld = $('meta[name="application-name"]').attr("content"); - isWuxiaWorld = - isWuxiaWorld && isWuxiaWorld.includes("Wuxiaworld") ? true : false; + let isWuxiaWorld = result.url.toLowerCase().includes("wuxiaworld"); /** * Checks if its a wwordpress site */ - let isWordPress = $('meta[name="generator"]').attr("content"); + let isWordPress = + $('meta[name="generator"]').attr("content") || $("footer").text(); if (isWordPress) { isWordPress = isWordPress.toLowerCase().includes("wordpress") || isWordPress.toLowerCase().includes("Site Kit by Google 1.36.0") || - $(".powered-by").text().toLowerCase().includes("wordpress") + $(".powered-by").text().toLowerCase().includes("wordpress") || + $(".entry-content").html() || + $("section.content").html() ? true : false; + + // console.log(isWordPress); } - let isWebNovel = - $("header > a").attr("alt") === "Webnovel.com" ? true : false; + let isWebNovel = result.url.toLowerCase().includes("webnovel"); if (isWuxiaWorld) { chapterText = $("#chapter-content").html(); } else if (isWordPress) { + /** + * Remove wordpress bloat tags + */ $(".c-ads").remove(); $("#madara-comments").remove(); $(".sharedaddy").remove(); + chapterText = $(".entry-content").html(); if (!chapterText) { - chapterText = $("#chp_raw").html(); + chapterText = $("section.content").html(); } + + if (!chapterText) { + chapterText = $(".single_post").html(); + } + + /** + * Format anchor tags properly Eg. [title](https://www.example.com) + */ + // .replace( + // /<\s*a[^>]*href=['"](.*?)['"][^>]*>([\s\S]*?)<\/\s*a\s*>/gi, + // "[$2]($1)" + // ); } else if (isWebNovel) { chapterText = $(".cha-words").html(); } else { /** - * Tags and classes to remove + * Remove unnecessary tags */ - const tags = ["nav", "footer"]; + const tags = ["nav", "header", "footer", ".hidden"]; tags.map((tag) => $(tag).remove()); chapterText = $("body").html(); + } - chapterText = htmlToText(chapterText); + if (!chapterText) { + chapterText = + "Chapter not available.\n\nReport if it's available in webview."; } chapterText = htmlToText(chapterText); diff --git a/src/sources/helpers/htmlToText.js b/src/sources/helpers/htmlToText.js index 83842e03..8d79fc76 100644 --- a/src/sources/helpers/htmlToText.js +++ b/src/sources/helpers/htmlToText.js @@ -5,6 +5,7 @@ const htmlToText = (html, options = {}) => { text = html // Turn
's into single line breaks. .replace(/<\s*br[^>]*>/gi, "\n") + .replace(/<\s*hr[^>]*>/gi, `\n\n${"-".repeat(40)}\n\n`) // Turn 's into line breaks. .replace(/<\s*\/li[^>]*>/gi, "\n") // Turn

's into double line breaks. @@ -16,6 +17,13 @@ const htmlToText = (html, options = {}) => { // Remove content in comments. .replace(//gim, "") // Format anchor tags properly. + .replace(/(.*?)<\/em>/gi, "_$1_") + // .replace( + // /<\s*h(\d)[^>]*>(.*?)<\/h(\d)>/gim, + // `${"#".repeat("$1")}$2${"#".repeat("$1")}` + // ) + // .replace(/(.*?)<\/strong>/gi, "*$1*") + .replace( /<\s*a[^>]*href=['"](.*?)['"][^>]*>([\s\S]*?)<\/\s*a\s*>/gi, "$2" diff --git a/src/theme/theme.js b/src/theme/theme.js index 6b8d79c9..afe781e7 100644 --- a/src/theme/theme.js +++ b/src/theme/theme.js @@ -98,7 +98,7 @@ export const greenAppleTheme = { filterColor: "#FFEB3B", dividerColor: "rgba(255,255,255,0.1)", colorDisabled: "rgba(57,57,57,255)", - colorButtonText: "#FFFFFF", + colorButtonText: "#000000", statusBar: StatusBarStyle.LIGHT, };