Update Novelbin to include subsite fallback (#1408)
* novelbin subsite * prettier fix
This commit is contained in:
@@ -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) => {
|
||||||
|
const chapterName = loadedCheerio(el).find('a').attr('title');
|
||||||
loadedCheerio = parseHTML(chapterdata);
|
const chapterUrl = loadedCheerio(el).find('a').attr('href');
|
||||||
|
const segments = chapterUrl?.split('/').filter(Boolean);
|
||||||
const chapter: Plugin.ChapterItem[] = [];
|
return chapterName && segments
|
||||||
|
? {
|
||||||
loadedCheerio('ul.list-chapter > li').each((i, el) => {
|
name: chapterName,
|
||||||
const chapterName = loadedCheerio(el).find('a').attr('title');
|
path: segments.slice(2).join('/'),
|
||||||
const chapterUrl = loadedCheerio(el).find('a').attr('href');
|
}
|
||||||
|
: null;
|
||||||
if (!chapterName || !chapterUrl) return;
|
})
|
||||||
|
.get()
|
||||||
chapter.push({
|
.filter(Boolean);
|
||||||
name: chapterName,
|
|
||||||
path: chapterUrl.replace(this.site, ''),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return chapter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user