Skip to content

Commit

Permalink
Update Novelbin to include subsite fallback (#1408)
Browse files Browse the repository at this point in the history
* novelbin subsite

* prettier fix
  • Loading branch information
K1ngfish3r authored Jan 5, 2025
1 parent 2c7420e commit bf810d8
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/plugins/english/novelbin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class NovelBin implements Plugin.PluginBase {
name = 'Novel Bin';
icon = 'src/en/novelbin/icon.png';
site = 'https://novelbin.com/';
version = '1.1.0';
subsite = 'https://novelbin.lanovels.net/';
version = '1.2.0';
imageRequestInit?: Plugin.ImageRequestInit | undefined = {
headers: {
'referrer': this.site,
Expand Down Expand Up @@ -100,27 +101,25 @@ class NovelBin implements Plugin.PluginBase {
const novelId = loadedCheerio('#rating').attr('data-novel-id');

const getChapters = async (id: string) => {
const chapterListUrl = this.site + 'ajax/chapter-archive?novelId=' + id;

const data = await fetchApi(chapterListUrl);
const chapterdata = await data.text();

loadedCheerio = parseHTML(chapterdata);

const chapter: Plugin.ChapterItem[] = [];

loadedCheerio('ul.list-chapter > li').each((i, el) => {
const chapterName = loadedCheerio(el).find('a').attr('title');
const chapterUrl = loadedCheerio(el).find('a').attr('href');

if (!chapterName || !chapterUrl) return;

chapter.push({
name: chapterName,
path: chapterUrl.replace(this.site, ''),
});
});
return chapter;
const data = await fetchApi(
this.site + 'ajax/chapter-archive?novelId=' + id,
);
loadedCheerio = parseHTML(await data.text());

return loadedCheerio('ul.list-chapter > li')
.map((i, el) => {
const chapterName = loadedCheerio(el).find('a').attr('title');
const chapterUrl = loadedCheerio(el).find('a').attr('href');
const segments = chapterUrl?.split('/').filter(Boolean);
return chapterName && segments
? {
name: chapterName,
path: segments.slice(2).join('/'),
}
: null;
})
.get()
.filter(Boolean);
};

if (novelId) {
Expand All @@ -131,7 +130,10 @@ class NovelBin implements Plugin.PluginBase {
}

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);

Expand Down

0 comments on commit bf810d8

Please sign in to comment.