From d59f95f13a242fb892af09581cab8bb2422fb6dd Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Sun, 30 Jul 2023 23:37:32 -0400 Subject: [PATCH] fix(source): bypass image CDN in Linovelib (#716) * fix(source): bypass image CDN in Linovelib * fix(source): also check for src attribute in img in Linovelib --- src/sources/ch/linovelib.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/sources/ch/linovelib.js b/src/sources/ch/linovelib.js index 26ec15ea..fc20f61c 100644 --- a/src/sources/ch/linovelib.js +++ b/src/sources/ch/linovelib.js @@ -140,9 +140,19 @@ const parseChapter = async (novelUrl, chapterUrl) => { // Load lazyloaded images loadedCheerio('#acontent img.imagecontent').each(function () { - const imgSrc = loadedCheerio(this).attr('data-src'); + // Sometimes images are either in data-src or src + const imgSrc = + loadedCheerio(this).attr('data-src') || loadedCheerio(this).attr('src'); if (imgSrc) { - loadedCheerio(this).attr('src', imgSrc); + // The original CDN URL is locked behind a CF-like challenge, switch the URL to bypass that + // There are no react-native-url-polyfill lib, can't use URL API + const regex = /\/\/.+\.com\//; + const imgUrl = imgSrc.replace(regex, '//img.linovelib.com/'); + // Clean up img element + loadedCheerio(this) + .attr('src', imgUrl) + .removeAttr('data-src') + .removeClass('lazyload'); } }); @@ -257,7 +267,7 @@ const parseChapter = async (novelUrl, chapterUrl) => { }; Object.entries(mapping_dict).forEach(([key, value]) => { - chapterText.replaceAll(key, value); + chapterText = chapterText.replaceAll(key, value); }); const chapterName =