Plugins fixed (#903)

* test

* fast fix

* fix

* fix

* Update ranobelib.ts
This commit is contained in:
Rider21
2024-04-25 17:53:16 +03:00
committed by GitHub
parent 2c4490e5bd
commit 9bc558936d
24 changed files with 63683 additions and 62335 deletions
+18 -12
View File
@@ -25,7 +25,7 @@ class IfreedomPlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/ifreedom/${metadata.id.toLowerCase()}/icon.png`;
this.site = metadata.sourceSite;
this.version = '1.0.0';
this.version = '1.0.1';
this.filters = metadata.filters;
}
@@ -139,20 +139,26 @@ class IfreedomPlugin implements Plugin.PluginBase {
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
let chapterText =
body.match(/<article id="([\s\S]*?)<\/article>/g)?.[0] || '';
chapterText = chapterText.replace(/<script[^>]*>[\s\S]*?<\/script>/gim, '');
loadedCheerio('.entry-content img').each((index, element) => {
const srcset = loadedCheerio(element).attr('srcset')?.split?.(' ');
if (srcset?.length) {
loadedCheerio(element).removeAttr('srcset');
const bestlink: string[] = srcset.filter(url => url.startsWith('http'));
if (bestlink[bestlink.length - 1]) {
loadedCheerio(element).attr('src', bestlink[bestlink.length - 1]);
if (chapterText.includes('<img')) {
return chapterText.replace(/srcset="([^"]+)"/g, (match, src) => {
if (!src) return match;
const bestlink = src
.split(' ')
.filter((url: string) => url.startsWith('http'))
.pop();
if (bestlink) {
if (bestlink.startsWith('http')) return `src="${bestlink}"`;
return `src="${this.site}${bestlink}"`;
}
}
});
return match;
});
}
const chapterText = loadedCheerio('.entry-content').html() || '';
return chapterText;
}