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
This commit is contained in:
alistair3149
2023-07-30 23:37:32 -04:00
committed by GitHub
parent 0d9da26eff
commit d59f95f13a
+13 -3
View File
@@ -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 =