Update Novelbin to include subsite fallback (#1408)

* novelbin subsite

* prettier fix
This commit is contained in:
K1ngfish3r
2025-01-05 19:47:14 +05:00
committed by GitHub
parent 2c7420e049
commit bf810d8f42
+21 -19
View File
@@ -8,7 +8,8 @@ class NovelBin implements Plugin.PluginBase {
name = 'Novel Bin'; name = 'Novel Bin';
icon = 'src/en/novelbin/icon.png'; icon = 'src/en/novelbin/icon.png';
site = 'https://novelbin.com/'; site = 'https://novelbin.com/';
version = '1.1.0'; subsite = 'https://novelbin.lanovels.net/';
version = '1.2.0';
imageRequestInit?: Plugin.ImageRequestInit | undefined = { imageRequestInit?: Plugin.ImageRequestInit | undefined = {
headers: { headers: {
'referrer': this.site, 'referrer': this.site,
@@ -100,27 +101,25 @@ class NovelBin implements Plugin.PluginBase {
const novelId = loadedCheerio('#rating').attr('data-novel-id'); const novelId = loadedCheerio('#rating').attr('data-novel-id');
const getChapters = async (id: string) => { const getChapters = async (id: string) => {
const chapterListUrl = this.site + 'ajax/chapter-archive?novelId=' + id; const data = await fetchApi(
this.site + 'ajax/chapter-archive?novelId=' + id,
);
loadedCheerio = parseHTML(await data.text());
const data = await fetchApi(chapterListUrl); return loadedCheerio('ul.list-chapter > li')
const chapterdata = await data.text(); .map((i, el) => {
loadedCheerio = parseHTML(chapterdata);
const chapter: Plugin.ChapterItem[] = [];
loadedCheerio('ul.list-chapter > li').each((i, el) => {
const chapterName = loadedCheerio(el).find('a').attr('title'); const chapterName = loadedCheerio(el).find('a').attr('title');
const chapterUrl = loadedCheerio(el).find('a').attr('href'); const chapterUrl = loadedCheerio(el).find('a').attr('href');
const segments = chapterUrl?.split('/').filter(Boolean);
if (!chapterName || !chapterUrl) return; return chapterName && segments
? {
chapter.push({
name: chapterName, name: chapterName,
path: chapterUrl.replace(this.site, ''), path: segments.slice(2).join('/'),
}); }
}); : null;
return chapter; })
.get()
.filter(Boolean);
}; };
if (novelId) { if (novelId) {
@@ -131,7 +130,10 @@ class NovelBin implements Plugin.PluginBase {
} }
async parseChapter(chapterPath: string): Promise<string> { async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then(r => r.text()); const isSubsite = chapterPath.includes('subsite=1');
const path = (isSubsite ? this.subsite : this.site) + chapterPath;
const body = await fetchApi(path).then(r => r.text());
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);