diff --git a/docs/docs.md b/docs/docs.md index fb5694b..f74699f 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -29,12 +29,12 @@ class ExamplePlugin implements Plugin.PluginBase {} | [icon](#pluginbasename) | yes | Plugin Icon | | [site](#pluginbasesite) | yes | Plugin site link | | [version](#pluginbaseversion) | yes | Plugin version | +| [imageRequestInit](#pluginbaseimagerequestinit) | no | Plugin Image Request Init | | [filters](#pluginbasefilters) | no | [Filter definition](#filter-definition-object) object | | [popularNovels(page, options)](#pluginbasepopularnovels) | yes | Novel list getter | | [parseNovelAndChapters(url)](#pluginbaseparsenovelandchapters) | yes | Novel info and chapter list getter | | [parseChapter(url)](#pluginbaseparsechapter) | yes | Chapter text getter | | [searchNovels(searchTerm, page)](#pluginbasesearchnovels) | yes | Novel searching getter | -| [fetchImage(url)](#pluginbasefetchimage) | yes | Customizable function for fetching images | #### PluginBase::id @@ -109,6 +109,26 @@ class ExamplePlugin implements Plugin.PluginBase { } ``` +#### PluginBase::imageRequestInit + +The init for request to obtain images + +Used if images failed to load due to site's protection + +###### Example + +```ts +class ExamplePlugin implements Plugin.PluginBase { + ... + imageRequestInit: Plugin.ImageRequestInit = { + headers: { + Referer: 'https://example.com', + }, + }; + ... +} +``` + #### PluginBase::filters A [Filter definition]() object that holds filters used in [popularNovels](#pluginbasepopularnovels) function @@ -312,43 +332,6 @@ class ExamplePlugin implements Plugin.PluginBase { } ``` -#### PluginBase::fetchImage - -Function used if images failed to load due to site's protection - -```ts -async fetchImage(url: string): Promise -``` - -See [Fetch functions]() for detailed list of fetch functions provided by us to help with fetching data - -###### Parameter - -- `url` Image's url to fetch - -###### Returns - -- `string` base64 representation of the image - -or - -- `undefined` on error - -###### Example - -```ts -class ExamplePlugin implements Plugin.PluginBase { - ... - async fetchImage(url: string): Promise { - const headers = { - Referer: "https://ln.hako.vn", - }; - return await fetchFile(url, { headers: headers }); - } - ... -} -``` - --- ### NovelItem diff --git a/docs/plugin-template.ts b/docs/plugin-template.ts index cfdc283..5af22d7 100644 --- a/docs/plugin-template.ts +++ b/docs/plugin-template.ts @@ -14,6 +14,7 @@ class TemplatePlugin implements Plugin.PluginBase { site = 'https://example.com'; version = '1.0.0'; filters: Filters | undefined = undefined; + imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined; async popularNovels( pageNo: number, @@ -80,11 +81,6 @@ class TemplatePlugin implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } } export default new TemplatePlugin(); diff --git a/plugins/chinese/69shu.ts b/plugins/chinese/69shu.ts index 1d1e885..db5e26e 100644 --- a/plugins/chinese/69shu.ts +++ b/plugins/chinese/69shu.ts @@ -180,8 +180,6 @@ class Shu69 implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; - filters = { rank: { label: '排行榜', diff --git a/plugins/chinese/69xinshu.ts b/plugins/chinese/69xinshu.ts index 2e410cf..3f11921 100644 --- a/plugins/chinese/69xinshu.ts +++ b/plugins/chinese/69xinshu.ts @@ -181,8 +181,6 @@ class XinShu69 implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; - filters = { class: { label: '分类', diff --git a/plugins/chinese/linovelib.ts b/plugins/chinese/linovelib.ts index 0139517..a9016f7 100644 --- a/plugins/chinese/linovelib.ts +++ b/plugins/chinese/linovelib.ts @@ -521,13 +521,6 @@ class Linovelib implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - const headers = new Headers({ - 'Referer': `${this.site}/`, - }); - return await fetchFile(url, { headers }); - } - filters = { rank: { label: '排行榜', diff --git a/plugins/english/LibRead.ts b/plugins/english/LibRead.ts index 8e37c35..0992199 100644 --- a/plugins/english/LibRead.ts +++ b/plugins/english/LibRead.ts @@ -148,8 +148,6 @@ class LibReadPlugin implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - fetchImage = fetchFile; - filters = { type_genre: { type: FilterTypes.Picker, diff --git a/plugins/english/NovelOnline.ts b/plugins/english/NovelOnline.ts index fe48e5d..49184d7 100644 --- a/plugins/english/NovelOnline.ts +++ b/plugins/english/NovelOnline.ts @@ -146,10 +146,6 @@ class NovelsOnline implements Plugin.PluginBase { .filter(sr => sr !== null); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { sort: { value: 'top_rated', diff --git a/plugins/english/StorySeedling.ts b/plugins/english/StorySeedling.ts index fd42123..2e9d110 100644 --- a/plugins/english/StorySeedling.ts +++ b/plugins/english/StorySeedling.ts @@ -156,9 +156,6 @@ class StorySeedlingPlugin implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new StorySeedlingPlugin(); diff --git a/plugins/english/allnovelfull.ts b/plugins/english/allnovelfull.ts index 2981af3..781c1d3 100644 --- a/plugins/english/allnovelfull.ts +++ b/plugins/english/allnovelfull.ts @@ -148,10 +148,6 @@ class AllNovelFullPlugin implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { order: { value: '/most-popular', diff --git a/plugins/english/bestlightnovel.ts b/plugins/english/bestlightnovel.ts index cab25bb..f9b1894 100644 --- a/plugins/english/bestlightnovel.ts +++ b/plugins/english/bestlightnovel.ts @@ -169,10 +169,6 @@ class BLN implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { status: { label: 'Status', diff --git a/plugins/english/comrademao.broken.ts b/plugins/english/comrademao.broken.ts index 4826097..b2060bd 100644 --- a/plugins/english/comrademao.broken.ts +++ b/plugins/english/comrademao.broken.ts @@ -157,10 +157,6 @@ class ComradeMaoPlugin implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { category: { value: '', diff --git a/plugins/english/divinedaolibrary.ts b/plugins/english/divinedaolibrary.ts index b80a3da..ffac85a 100644 --- a/plugins/english/divinedaolibrary.ts +++ b/plugins/english/divinedaolibrary.ts @@ -128,10 +128,6 @@ class DDLPlugin implements Plugin.PluginBase { const loadedCheerio = parseHTML(body); return this.parseNovels(loadedCheerio, searchTerm); } - - async fetchImage(url: string): Promise { - return await fetchFile(url); - } } export default new DDLPlugin(); diff --git a/plugins/english/earlynovel.ts b/plugins/english/earlynovel.ts index b16dac8..8abd1c2 100644 --- a/plugins/english/earlynovel.ts +++ b/plugins/english/earlynovel.ts @@ -139,10 +139,6 @@ class EarlyNovelPlugin implements Plugin.PagePlugin { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { order: { value: '/most-popular', diff --git a/plugins/english/faqwikius.ts b/plugins/english/faqwikius.ts index 9eb5be0..7001693 100644 --- a/plugins/english/faqwikius.ts +++ b/plugins/english/faqwikius.ts @@ -161,8 +161,6 @@ class FaqWikiUs implements Plugin.PluginBase { return this.parseNovels(loadedCheerio, searchTerm); } - - fetchImage = fetchFile; } export default new FaqWikiUs(); diff --git a/plugins/english/freewebnovel.ts b/plugins/english/freewebnovel.ts index 518c663..10f9278 100644 --- a/plugins/english/freewebnovel.ts +++ b/plugins/english/freewebnovel.ts @@ -144,8 +144,6 @@ class FreeWebNovel implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - fetchImage = fetchFile; - filters = { genres: { type: FilterTypes.Picker, diff --git a/plugins/english/lightnovelpub.ts b/plugins/english/lightnovelpub.ts index 7693df3..e08383a 100644 --- a/plugins/english/lightnovelpub.ts +++ b/plugins/english/lightnovelpub.ts @@ -19,33 +19,33 @@ class LightNovelPub implements Plugin.PagePlugin { const novels: Plugin.NovelItem[] = []; let tempNovel = {} as Plugin.NovelItem; let isParsingNovel = false; - const parser = new Parser ({ - onopentag(name, attribs){ - if (isParsingNovel){ - if (name === 'a'){ + const parser = new Parser({ + onopentag(name, attribs) { + if (isParsingNovel) { + if (name === 'a') { tempNovel.path = attribs['href'].slice(1); tempNovel.name = attribs['title']; } - if (name === 'img'){ + if (name === 'img') { tempNovel.cover = attribs['data-src'] || attribs['src']; } - if (tempNovel.path && tempNovel.cover){ + if (tempNovel.path && tempNovel.cover) { novels.push(tempNovel); tempNovel = {} as Plugin.NovelItem; } } }, - onattribute(name, value){ - if (name === 'class' && value === 'novel-item'){ + onattribute(name, value) { + if (name === 'class' && value === 'novel-item') { isParsingNovel = true; } }, - onclosetag(name){ - if(name === 'li'){ + onclosetag(name) { + if (name === 'li') { isParsingNovel = false; } - } - }) + }, + }); parser.write(html); parser.end(); return novels; @@ -76,7 +76,7 @@ class LightNovelPub implements Plugin.PagePlugin { summary: '', totalPages: 1, chapters: [], - } + }; let isHeaderStats = false; let isStatus = false; let isTotalChapters = false; @@ -85,95 +85,95 @@ class LightNovelPub implements Plugin.PagePlugin { let isSummary = false; let isGenres = false; let isTags = false; - let genreArray: string[] = [] + let genreArray: string[] = []; let isCover = false; const parser = new Parser({ - onopentag(name, attribs){ - if(name === 'h1' && attribs['class']?.includes('novel-title')){ + onopentag(name, attribs) { + if (name === 'h1' && attribs['class']?.includes('novel-title')) { isNovelName = true; } - if(name === 'div' && attribs['class']?.includes('content')){ + if (name === 'div' && attribs['class']?.includes('content')) { isSummary = true; } - if(name === 'figure' && attribs['class'] === 'cover'){ + if (name === 'figure' && attribs['class'] === 'cover') { isCover = true; } - if(isCover){ - if(name === 'img'){ + if (isCover) { + if (name === 'img') { novel.cover = attribs['data-src'] || attribs['src']; } } }, - onopentagname(name){ - if (isHeaderStats && name === 'strong'){ + onopentagname(name) { + if (isHeaderStats && name === 'strong') { isStatus = true; } - if (isSummary && name === 'br'){ + if (isSummary && name === 'br') { novel.summary += '\n'; } - if (isGenres && name === 'a'){ + if (isGenres && name === 'a') { isTags = true; } }, - onattribute(name,value){ - if (name === 'class' && value === 'header-stats'){ + onattribute(name, value) { + if (name === 'class' && value === 'header-stats') { isTotalChapters = true; isHeaderStats = true; } - if (name === 'itemprop' && value === 'author'){ + if (name === 'itemprop' && value === 'author') { isAuthorName = true; } - if (name === 'class' && value === 'categories'){ + if (name === 'class' && value === 'categories') { isGenres = true; } }, - ontext(data){ - if(isTotalChapters){ + ontext(data) { + if (isTotalChapters) { novel.totalPages = Math.ceil(parseInt(data, 10) / 100); } - if(isStatus){ + if (isStatus) { novel.status = data.trim(); } - if(isNovelName){ + if (isNovelName) { novel.name += data.trim(); } - if(isAuthorName){ + if (isAuthorName) { novel.author = data; } - if(isSummary){ + if (isSummary) { novel.summary += data; } - if(isTags){ + if (isTags) { genreArray.push(data); } }, - onclosetag(name){ - if(name === 'strong'){ + onclosetag(name) { + if (name === 'strong') { isTotalChapters = false; isStatus = false; } - if(name === 'i'){ + if (name === 'i') { isStatus = false; } - if(name === 'h1'){ + if (name === 'h1') { isNovelName = false; } - if(name === 'span'){ + if (name === 'span') { isAuthorName = false; } - if(name === 'div'){ + if (name === 'div') { isHeaderStats = false; isSummary = false; isGenres = false; } - if(name === 'a'){ + if (name === 'a') { isTags = false; } - if(name === 'figure'){ + if (name === 'figure') { isCover = false; } - } - }) + }, + }); parser.write(body); parser.end(); novel.genres = genreArray.join(', '); @@ -184,48 +184,51 @@ class LightNovelPub implements Plugin.PagePlugin { const url = this.site + novelPath + '/chapters/page-' + page; const body = await fetchApi(url).then(res => res.text()); const chapter: Plugin.ChapterItem[] = []; - let tempChapter = {} as Plugin.ChapterItem; + let tempChapter = {} as Plugin.ChapterItem; let isChapterItem = false; let isChapterList = false; - const parser = new Parser ({ - onopentag(name, attribs){ - if(isChapterList){ - if (name === 'li'){ + const parser = new Parser({ + onopentag(name, attribs) { + if (isChapterList) { + if (name === 'li') { isChapterItem = true; tempChapter.chapterNumber = Number(attribs['data-orderno']); } - if (isChapterItem){ - if (name === 'a'){ + if (isChapterItem) { + if (name === 'a') { tempChapter.name = attribs['title']; tempChapter.path = attribs['href'].slice(1); } - if (name === 'time'){ - tempChapter.releaseTime = dayjs(attribs['datetime']).toISOString(); + if (name === 'time') { + tempChapter.releaseTime = dayjs( + attribs['datetime'], + ).toISOString(); } if ( - tempChapter.chapterNumber && - tempChapter.path && - tempChapter.releaseTime){ - chapter.push(tempChapter); - tempChapter = {} as Plugin.ChapterItem; + tempChapter.chapterNumber && + tempChapter.path && + tempChapter.releaseTime + ) { + chapter.push(tempChapter); + tempChapter = {} as Plugin.ChapterItem; } } } }, - onattribute(name, value){ - if (name === 'class' && value === 'chapter-list'){ + onattribute(name, value) { + if (name === 'class' && value === 'chapter-list') { isChapterList = true; } }, - onclosetag(name){ - if (name === 'a'){ + onclosetag(name) { + if (name === 'a') { isChapterItem = false; } - if (name === 'ul'){ + if (name === 'ul') { isChapterList = false; } - } - }) + }, + }); parser.write(body); parser.end(); const chapters = chapter; @@ -240,92 +243,92 @@ class LightNovelPub implements Plugin.PagePlugin { let isPtag = false; let isStyleText = false; const parser = new Parser({ - onopentag(name,attribs){ - if (isChapter && name === 'div'){ - let stylediv = attribs['style'] - if(stylediv){ - chapterText += `
` + onopentag(name, attribs) { + if (isChapter && name === 'div') { + let stylediv = attribs['style']; + if (stylediv) { + chapterText += `
`; isStyleText = true; } else { - chapterText += `
` + chapterText += `
`; } } - if (isChapter && name === 'table'){ + if (isChapter && name === 'table') { let w = attribs['width']; - if(w) { + if (w) { chapterText += ``; } else { chapterText += `
`; } } - if (isChapter && name === 'tbody'){ + if (isChapter && name === 'tbody') { chapterText += ``; } - if (isChapter && name === 'tr'){ + if (isChapter && name === 'tr') { chapterText += ``; } - if (isChapter && name === 'td'){ + if (isChapter && name === 'td') { let w1 = attribs['width']; - if(w1) { + if (w1) { chapterText += ``; } - if (isChapter && name === 'tr'){ + if (isChapter && name === 'tr') { chapterText += ``; } - if (isChapter && name === 'tbody'){ + if (isChapter && name === 'tbody') { chapterText += ``; } - if (isChapter && name === 'table'){ + if (isChapter && name === 'table') { chapterText += `
`; } else { chapterText += ``; } } }, - onattribute(name, value){ - if (name === 'id' && value === 'chapter-container'){ + onattribute(name, value) { + if (name === 'id' && value === 'chapter-container') { isChapter = true; } - if (name === 'class' && value?.includes('chapternav')){ + if (name === 'class' && value?.includes('chapternav')) { isChapter = false; isPtag = false; } }, - onopentagname(name){ - if (isChapter && name === 'p'){ + onopentagname(name) { + if (isChapter && name === 'p') { chapterText += '

'; isPtag = true; - if(isStyleText){ + if (isStyleText) { isStyleText = false; } } - if (isChapter && name === 'br'){ + if (isChapter && name === 'br') { chapterText += `
`; } }, - ontext(data){ - if(isPtag){ + ontext(data) { + if (isPtag) { chapterText += data; } - if(isStyleText){ + if (isStyleText) { chapterText += data; } }, - onclosetag(name){ - if (name === 'p'){ + onclosetag(name) { + if (name === 'p') { isPtag = false; - chapterText += '

' + chapterText += '

'; } - if (isChapter && name === 'td'){ + if (isChapter && name === 'td') { chapterText += `
`; } - if (isChapter && name === 'div'){ + if (isChapter && name === 'div') { isStyleText = false; - chapterText += `
` + chapterText += `
`; } - } - }) - parser.write(body) + }, + }); + parser.write(body); parser.end(); return chapterText; @@ -339,13 +342,16 @@ class LightNovelPub implements Plugin.PagePlugin { const link = `${this.site}search`; const response = await fetchApi(link).then(r => r.text()); let verifytoken = ''; - const parser = new Parser ({ + const parser = new Parser({ onopentag(name, attribs) { - if (name === 'input' && attribs['name']?.includes('LNRequestVerifyToken')){ + if ( + name === 'input' && + attribs['name']?.includes('LNRequestVerifyToken') + ) { verifytoken = attribs['value']; } }, - }) + }); parser.write(response); parser.end(); @@ -358,11 +364,7 @@ class LightNovelPub implements Plugin.PagePlugin { body: formData, }).then(r => r.json()); - return this.parseNovels(body.resultview) - } - - async fetchImage(url: string): Promise { - return fetchFile(url, { headers: this.headers }); + return this.parseNovels(body.resultview); } filters = { diff --git a/plugins/english/lnmtl.ts b/plugins/english/lnmtl.ts index 226795e..d279eb2 100644 --- a/plugins/english/lnmtl.ts +++ b/plugins/english/lnmtl.ts @@ -28,15 +28,15 @@ class LnMTLPlugin implements Plugin.PagePlugin { const html = await body.text(); const baseUrl = this.site; let isParsingNovel = false; - let tempNovel = {} as Plugin.NovelItem; + let tempNovel = {} as Plugin.NovelItem; const novels: Plugin.NovelItem[] = []; - const parser = new Parser ({ + const parser = new Parser({ onopentag(name, attribs) { if (attribs['class']?.includes('media-left')) { isParsingNovel = true; } if (isParsingNovel) { - switch (name){ + switch (name) { case 'a': tempNovel.path = attribs['href'].slice(baseUrl.length); break; @@ -45,14 +45,14 @@ class LnMTLPlugin implements Plugin.PagePlugin { tempNovel.cover = attribs['src']; break; } - if (tempNovel.path && tempNovel.name){ + if (tempNovel.path && tempNovel.name) { novels.push(tempNovel); tempNovel = {} as Plugin.NovelItem; } } }, - onclosetag(name){ - if (name === 'div'){ + onclosetag(name) { + if (name === 'div') { isParsingNovel = false; } }, @@ -83,59 +83,59 @@ class LnMTLPlugin implements Plugin.PagePlugin { let isSource = false; let isPanelKey = false; let isPanelValue = 0; - let isAuthorKey = false - let isStatusKey = false + let isAuthorKey = false; + let isStatusKey = false; let isList = 0; let isGenres = false; - let genreArray: string[] = [] + let genreArray: string[] = []; const parser = new Parser({ - onopentag(name,attribs) { - if (name === 'img' && attribs['class']?.includes('img-rounded')){ + onopentag(name, attribs) { + if (name === 'img' && attribs['class']?.includes('img-rounded')) { novel.name = attribs['title']; novel.cover = attribs['src']; } - if (name === 'ul' && attribs['class']?.includes('list-inline')){ + if (name === 'ul' && attribs['class']?.includes('list-inline')) { isList++; } }, - onopentagname(name){ - if (name === 'dt'){ + onopentagname(name) { + if (name === 'dt') { isPanelKey = true; } - if (name === 'dd'){ + if (name === 'dd') { isPanelValue++; } - if (isList === 1 && name === 'li'){ + if (isList === 1 && name === 'li') { isGenres = true; } }, - onattribute(name, value){ - if (name === 'class' && value === 'description'){ + onattribute(name, value) { + if (name === 'class' && value === 'description') { isDescription = true; } - if (name === 'class' && value === 'source'){ + if (name === 'class' && value === 'source') { isDescription = false; isSource = true; } - if (name === 'class' && value === 'progress'){ + if (name === 'class' && value === 'progress') { isSource = false; } }, - ontext(data){ - if(isScript){ + ontext(data) { + if (isScript) { const volume = JSON.parse( - data.match(/lnmtl.volumes = (.+])(?=;)/)![1] || '' + data.match(/lnmtl.volumes = (.+])(?=;)/)![1] || '', ); novel.totalPages = volume.length; } - if(isDescription){ + if (isDescription) { novel.summary += data.trim() + '\n\n'; } - if(isSource){ + if (isSource) { novel.summary += data; } - if(isPanelKey){ - switch(data){ + if (isPanelKey) { + switch (data) { case 'Authors': isAuthorKey = true; break; @@ -144,32 +144,32 @@ class LnMTLPlugin implements Plugin.PagePlugin { break; } } - if(isAuthorKey && isPanelValue === 1){ + if (isAuthorKey && isPanelValue === 1) { novel.author += data.trim(); isAuthorKey = false; } - if(isStatusKey && isPanelValue === 2){ + if (isStatusKey && isPanelValue === 2) { novel.status += data.trim(); isStatusKey = false; } - if(isGenres){ + if (isGenres) { genreArray.push(data.trim()); novel.genres = genreArray.join(', '); } }, - onclosetag(name){ - if (name === 'ul'){ + onclosetag(name) { + if (name === 'ul') { isGenres = false; } - if(name === 'main'){ + if (name === 'main') { isPanelKey = false; isScript = true; } - if (name === 'script'){ + if (name === 'script') { isScript = false; } }, - }) + }); parser.write(html); parser.end(); return novel; @@ -182,25 +182,25 @@ class LnMTLPlugin implements Plugin.PagePlugin { let volume: VolumeEntry = { id: '', title: '', - } + }; const parser = new Parser({ - ontext(data){ - if(isScript){ + ontext(data) { + if (isScript) { const volumes = JSON.parse( - data.match(/lnmtl.volumes = (.+])(?=;)/)![1] || '' + data.match(/lnmtl.volumes = (.+])(?=;)/)![1] || '', ); - volume = volumes[+page-1] + volume = volumes[+page - 1]; } }, - onclosetag(name){ - if(name === 'main'){ + onclosetag(name) { + if (name === 'main') { isScript = true; } - if (name === 'script'){ + if (name === 'script') { isScript = false; } }, - }) + }); parser.write(html); parser.end(); @@ -243,29 +243,29 @@ class LnMTLPlugin implements Plugin.PagePlugin { let isText = false; let chapterText = ''; const parser = new Parser({ - onopentag(name,attribs){ - if(name === 'sentence' && attribs['class']?.includes('translated')){ + onopentag(name, attribs) { + if (name === 'sentence' && attribs['class']?.includes('translated')) { isText = true; - chapterText += '

' + chapterText += '

'; } }, - onopentagname(name){ - if(name === 'nav'){ + onopentagname(name) { + if (name === 'nav') { isText = false; } }, - ontext(data){ - if(isText){ + ontext(data) { + if (isText) { chapterText += data; } }, - onclosetag(name){ - if (name === 'sentence'){ - chapterText += '

' + onclosetag(name) { + if (name === 'sentence') { + chapterText += '

'; isText = false; } - } - }) + }, + }); parser.write(html); parser.end(); @@ -281,31 +281,34 @@ class LnMTLPlugin implements Plugin.PagePlugin { .then(r => r.replace(/>\s+<')); let isScript = false; let isFooter = false; - let list = '' + let list = ''; const parser = new Parser({ onopentag(name, attribs) { - if(isFooter && name === 'script' && - attribs['type']?.includes('application/javascript')){ + if ( + isFooter && + name === 'script' && + attribs['type']?.includes('application/javascript') + ) { isScript = true; } }, - ontext(data){ - if (isScript){ + ontext(data) { + if (isScript) { list = data.match(/prefetch: '\/(.*json)/)![1]; } }, - onclosetag(name){ - if (name === 'footer'){ + onclosetag(name) { + if (name === 'footer') { isFooter = true; } - if (name === 'script'){ + if (name === 'script') { isScript = false; } - if (name === 'body'){ + if (name === 'body') { isFooter = false; } - } - }) + }, + }); parser.write(html); parser.end(); @@ -332,10 +335,6 @@ class LnMTLPlugin implements Plugin.PagePlugin { return novels; } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { order: { value: 'favourites', diff --git a/plugins/english/mtlnovel.ts b/plugins/english/mtlnovel.ts index 2d52bd5..eb988b3 100644 --- a/plugins/english/mtlnovel.ts +++ b/plugins/english/mtlnovel.ts @@ -145,11 +145,6 @@ class MTLNovel implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - const headers = new Headers(); - headers.append('Alt-Used', 'www.mtlnovel.com'); - return fetchFile(url, { headers }); - } filters = { order: { diff --git a/plugins/english/mtlreader.ts b/plugins/english/mtlreader.ts index 6dc3932..4e82c78 100644 --- a/plugins/english/mtlreader.ts +++ b/plugins/english/mtlreader.ts @@ -103,9 +103,5 @@ class MTLReader implements Plugin.PluginBase { const loadedCheerio = parseHTML(seacrhBody); return this.parseNovels(loadedCheerio); } - - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new MTLReader(); diff --git a/plugins/english/novelbin.ts b/plugins/english/novelbin.ts index 0b0cf4b..e1e8e40 100644 --- a/plugins/english/novelbin.ts +++ b/plugins/english/novelbin.ts @@ -9,6 +9,11 @@ class NovelBin implements Plugin.PluginBase { icon = 'src/en/novelbin/icon.png'; site = 'https://binnovel.com/'; version = '1.0.1'; + imageRequestInit?: Plugin.ImageRequestInit | undefined = { + headers: { + 'referrer': this.site, + }, + }; parseNovels(loadedCheerio: CheerioAPI) { const novels: Plugin.NovelItem[] = []; @@ -143,14 +148,6 @@ class NovelBin implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url, { - headers: { - 'referrer': this.site, - }, - }); - } - filters = { sort: { value: 'popular-novels', diff --git a/plugins/english/novelbuddy.ts b/plugins/english/novelbuddy.ts index f4352df..4f657f5 100644 --- a/plugins/english/novelbuddy.ts +++ b/plugins/english/novelbuddy.ts @@ -169,10 +169,6 @@ class NovelBuddy implements Plugin.PluginBase { const loadedCheerio = parseHTML(body); return this.parseNovels(loadedCheerio); } - - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new NovelBuddy(); diff --git a/plugins/english/novelfull.ts b/plugins/english/novelfull.ts index e0b3c80..22372ec 100644 --- a/plugins/english/novelfull.ts +++ b/plugins/english/novelfull.ts @@ -135,10 +135,6 @@ class NovelFull implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { sort: { value: 'most-popular', diff --git a/plugins/english/novelhall.ts b/plugins/english/novelhall.ts index 1777efb..75ee0c1 100644 --- a/plugins/english/novelhall.ts +++ b/plugins/english/novelhall.ts @@ -126,9 +126,6 @@ class NovelHall implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new NovelHall(); diff --git a/plugins/english/novelupdates.ts b/plugins/english/novelupdates.ts index 9270b8a..f444c0d 100644 --- a/plugins/english/novelupdates.ts +++ b/plugins/english/novelupdates.ts @@ -713,10 +713,6 @@ class NovelUpdates implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { sort: { label: 'Sort Results By', diff --git a/plugins/english/pawread.ts b/plugins/english/pawread.ts index 1aa0629..37ca163 100644 --- a/plugins/english/pawread.ts +++ b/plugins/english/pawread.ts @@ -137,10 +137,6 @@ class PawRead implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { status: { value: '', diff --git a/plugins/english/ranobes.ts b/plugins/english/ranobes.ts index 0bcfbf1..02e8ff1 100644 --- a/plugins/english/ranobes.ts +++ b/plugins/english/ranobes.ts @@ -19,49 +19,51 @@ class RanobesPlugin implements Plugin.PagePlugin { const novels: Plugin.NovelItem[] = []; let tempNovel = {} as Plugin.NovelItem; tempNovel.name = ''; - const baseUrl = this.site + const baseUrl = this.site; let isParsingNovel = false; let isTitleTag = false; let isNovelName = false; const parser = new Parser({ onopentag(name, attribs) { - if (attribs['class']?.includes('short-cont')){ + if (attribs['class']?.includes('short-cont')) { isParsingNovel = true; } - if (isParsingNovel){ - if (name === 'h2' && attribs['class']?.includes('title')){ + if (isParsingNovel) { + if (name === 'h2' && attribs['class']?.includes('title')) { isTitleTag = true; } - if (isTitleTag && name === 'a'){ + if (isTitleTag && name === 'a') { tempNovel.path = attribs['href'].slice(baseUrl.length); isNovelName = true; } - if (name === 'figure'){ - tempNovel.cover = attribs['style'] - .replace(/.*url\((.*?)\)./g, '$1'); + if (name === 'figure') { + tempNovel.cover = attribs['style'].replace( + /.*url\((.*?)\)./g, + '$1', + ); } - if (tempNovel.path && tempNovel.cover){ + if (tempNovel.path && tempNovel.cover) { novels.push(tempNovel); tempNovel = {} as Plugin.NovelItem; tempNovel.name = ''; } } }, - ontext(data){ - if(isNovelName){ + ontext(data) { + if (isNovelName) { tempNovel.name += data; } }, - onclosetag(name){ - if(name === 'h2'){ + onclosetag(name) { + if (name === 'h2') { isNovelName = false; isTitleTag = false; } - if(name === 'figure'){ + if (name === 'figure') { isParsingNovel = false; } - } - }) + }, + }); parser.write(html); parser.end(); return novels; @@ -104,7 +106,7 @@ class RanobesPlugin implements Plugin.PagePlugin { summary: '', chapters: [], totalPages: 1, - } + }; let baseUrl = this.site; let isCover = false; let isAuthor = false; @@ -113,108 +115,102 @@ class RanobesPlugin implements Plugin.PagePlugin { let isStatusText = false; let isGenres = false; let isGenresText = false; - let genreArray: string[] = [] + let genreArray: string[] = []; let novelId = ''; - const parser = new Parser ({ - onopentag(name,attribs){ - if (attribs['class'] === 'poster'){ + const parser = new Parser({ + onopentag(name, attribs) { + if (attribs['class'] === 'poster') { isCover = true; } - if (isCover && name === 'img'){ + if (isCover && name === 'img') { novel.name = attribs['alt']; novel.cover = baseUrl + attribs['src']; } - if (name === 'div' && attribs['class'] === 'moreless'){ + if (name === 'div' && attribs['class'] === 'moreless') { isSummary = true; } - if (name === 'li' && attribs['title']?.includes('Original status')){ + if (name === 'li' && attribs['title']?.includes('Original status')) { isStatus = true; } - if (name === 'input' && attribs['name'] === 'newsid'){ - novelId = attribs['value'] + if (name === 'input' && attribs['name'] === 'newsid') { + novelId = attribs['value']; } }, - onopentagname(name){ - if (isSummary && name === 'br'){ + onopentagname(name) { + if (isSummary && name === 'br') { novel.summary += `/n`; } - if (isStatus && name === 'a'){ + if (isStatus && name === 'a') { isStatusText = true; } - if (isGenres && name === 'a'){ + if (isGenres && name === 'a') { isGenresText = true; } }, - onattribute(name,value){ - if (name === 'itemprop' && value === 'creator'){ + onattribute(name, value) { + if (name === 'itemprop' && value === 'creator') { isAuthor = true; } - if (name === 'id' && value === 'mc-fs-genre'){ + if (name === 'id' && value === 'mc-fs-genre') { isGenres = true; } }, - ontext(data){ - if(isAuthor){ + ontext(data) { + if (isAuthor) { novel.author = data; } - if(isSummary){ + if (isSummary) { novel.summary += data; } - if(isStatusText){ - novel.status = data === 'Ongoing' - ? 'Ongoing' - : 'Completed'; + if (isStatusText) { + novel.status = data === 'Ongoing' ? 'Ongoing' : 'Completed'; } - if(isGenresText){ + if (isGenresText) { genreArray.push(data); } }, - onclosetag(name){ - if(name === 'a'){ + onclosetag(name) { + if (name === 'a') { isCover = false; isAuthor = false; isStatusText = false; isGenresText = false; isStatus = false; } - if(name === 'div'){ + if (name === 'div') { isSummary = false; isGenres = false; } - } - }) + }, + }); parser.write(html); parser.end(); novel.genres = genreArray.join(', '); const chapterListUrl = this.site + '/chapters/' + novelId + '/'; - const chaptersHtml = await fetchApi(chapterListUrl).then(r => - r.text(), - ); - let dataJson: { - pages_count: string, - chapters: ChapterEntry[] - } = { pages_count: '', chapters : [] }; + const chaptersHtml = await fetchApi(chapterListUrl).then(r => r.text()); + let dataJson: { + pages_count: string; + chapters: ChapterEntry[]; + } = { pages_count: '', chapters: [] }; let isScript = false; - const parser2 = new Parser ({ - ontext(data){ - if(isScript){ - if (data.includes('window.__DATA__ =')){ - dataJson = JSON.parse( - data.replace('window.__DATA__ =', '') - ); + const parser2 = new Parser({ + ontext(data) { + if (isScript) { + if (data.includes('window.__DATA__ =')) { + dataJson = JSON.parse(data.replace('window.__DATA__ =', '')); } } }, - onclosetag(name){ - if(name === 'main'){ + onclosetag(name) { + if (name === 'main') { isScript = true; } - if (name === 'script'){ + if (name === 'script') { isScript = false; } }, - }) + }); parser2.write(chaptersHtml); parser2.end(); @@ -241,29 +237,27 @@ class RanobesPlugin implements Plugin.PagePlugin { const pageUrl = firstUrl + '/page/' + page; const pageBody = await fetchApi(pageUrl).then(r => r.text()); let isScript = false; - let dataJson: { - pages_count: string, - chapters: ChapterEntry[] - } = { pages_count: '', chapters : [] }; + let dataJson: { + pages_count: string; + chapters: ChapterEntry[]; + } = { pages_count: '', chapters: [] }; const parser = new Parser({ - ontext(data){ - if(isScript){ - if (data.includes('window.__DATA__ =')){ - dataJson = JSON.parse( - data.replace('window.__DATA__ =', '') - ); + ontext(data) { + if (isScript) { + if (data.includes('window.__DATA__ =')) { + dataJson = JSON.parse(data.replace('window.__DATA__ =', '')); } } }, - onclosetag(name){ - if(name === 'main'){ + onclosetag(name) { + if (name === 'main') { isScript = true; } - if (name === 'script'){ + if (name === 'script') { isScript = false; } - } - }) + }, + }); parser.write(pageBody); parser.end(); const chapters = this.parseChapters(dataJson); @@ -280,92 +274,92 @@ class RanobesPlugin implements Plugin.PagePlugin { let isPtag = false; let isStyleText = false; const parser = new Parser({ - onopentag(name,attribs){ - if (isChapter && name === 'div'){ - let stylediv = attribs['style'] - if(stylediv){ - chapterText += `
` + onopentag(name, attribs) { + if (isChapter && name === 'div') { + let stylediv = attribs['style']; + if (stylediv) { + chapterText += `
`; isStyleText = true; } else { - chapterText += `
` + chapterText += `
`; } } - if (isChapter && name === 'table'){ + if (isChapter && name === 'table') { let w = attribs['width']; - if(w) { + if (w) { chapterText += ``; } else { chapterText += `
`; } } - if (isChapter && name === 'tbody'){ + if (isChapter && name === 'tbody') { chapterText += ``; } - if (isChapter && name === 'tr'){ + if (isChapter && name === 'tr') { chapterText += ``; } - if (isChapter && name === 'td'){ + if (isChapter && name === 'td') { let w1 = attribs['width']; - if(w1) { + if (w1) { chapterText += ``; } - if (isChapter && name === 'tr'){ + if (isChapter && name === 'tr') { chapterText += ``; } - if (isChapter && name === 'tbody'){ + if (isChapter && name === 'tbody') { chapterText += ``; } - if (isChapter && name === 'table'){ + if (isChapter && name === 'table') { chapterText += `
`; } else { chapterText += ``; } } }, - onattribute(name, value){ - if (name === 'id' && value === 'arrticle'){ + onattribute(name, value) { + if (name === 'id' && value === 'arrticle') { isChapter = true; } - if (name === 'class' && value === 'category grey ellipses'){ + if (name === 'class' && value === 'category grey ellipses') { isChapter = false; isPtag = false; } }, - onopentagname(name){ - if (isChapter && name === 'p'){ + onopentagname(name) { + if (isChapter && name === 'p') { chapterText += '

'; isPtag = true; - if(isStyleText){ + if (isStyleText) { isStyleText = false; } } - if (isChapter && name === 'br'){ + if (isChapter && name === 'br') { chapterText += `
`; } }, - ontext(data){ - if(isPtag){ + ontext(data) { + if (isPtag) { chapterText += data; } - if(isStyleText){ + if (isStyleText) { chapterText += data; } }, - onclosetag(name){ - if (name === 'p'){ + onclosetag(name) { + if (name === 'p') { isPtag = false; - chapterText += '

' + chapterText += '

'; } - if (isChapter && name === 'td'){ + if (isChapter && name === 'td') { chapterText += `
`; } - if (isChapter && name === 'div'){ + if (isChapter && name === 'div') { isStyleText = false; - chapterText += `
` + chapterText += `
`; } - } - }) - parser.write(html) + }, + }); + parser.write(html); parser.end(); return chapterText; @@ -380,11 +374,6 @@ class RanobesPlugin implements Plugin.PagePlugin { return this.parseNovels(body); } - - - async fetchImage(url: string): Promise { - return await fetchFile(url); - } } export default new RanobesPlugin(); @@ -393,4 +382,4 @@ interface ChapterEntry { title: string; date: string; link: string; -} \ No newline at end of file +} diff --git a/plugins/english/readlitenovel.ts b/plugins/english/readlitenovel.ts index 017658a..9e2ae4a 100644 --- a/plugins/english/readlitenovel.ts +++ b/plugins/english/readlitenovel.ts @@ -174,10 +174,6 @@ class ReadLiteNovel implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { order: { value: 'top-rated', diff --git a/plugins/english/relibrary.ts b/plugins/english/relibrary.ts index dd5c586..aafce11 100644 --- a/plugins/english/relibrary.ts +++ b/plugins/english/relibrary.ts @@ -382,10 +382,6 @@ class ReLibraryPlugin implements Plugin.PluginBase { this.searchFunc.setHaystack(novels); return this.searchFunc.search(searchTerm); } - - async fetchImage(url: string): Promise { - return fetchFile(url, { headers: { referer: this.site } }); - } } export default new ReLibraryPlugin(); diff --git a/plugins/english/royalroad.ts b/plugins/english/royalroad.ts index 11afdc9..86848a4 100644 --- a/plugins/english/royalroad.ts +++ b/plugins/english/royalroad.ts @@ -18,37 +18,37 @@ class RoyalRoad implements Plugin.PluginBase { let isParsingNovel = false; let isNovelName = false; const parser = new Parser({ - onopentag(name, attribs){ - if (attribs['class']?.includes('fiction-list-item')){ + onopentag(name, attribs) { + if (attribs['class']?.includes('fiction-list-item')) { isParsingNovel = true; } - if (isParsingNovel){ - if (name === 'a' && attribs['class']?.includes('bold')){ + if (isParsingNovel) { + if (name === 'a' && attribs['class']?.includes('bold')) { tempNovel.path = attribs['href'].slice(1); isNovelName = true; } - if (name === 'img'){ + if (name === 'img') { tempNovel.cover = attribs['src']; } - if (tempNovel.path && tempNovel.name){ + if (tempNovel.path && tempNovel.name) { novels.push(tempNovel); tempNovel = {} as Plugin.NovelItem; tempNovel.name = ''; } } }, - ontext(data){ - if(isNovelName){ + ontext(data) { + if (isNovelName) { tempNovel.name += data; } }, - onclosetag(name){ - if(name === 'h2'){ + onclosetag(name) { + if (name === 'h2') { isNovelName = false; isParsingNovel = false; } - } - }) + }, + }); parser.write(html); parser.end(); return novels; @@ -64,9 +64,9 @@ class RoyalRoad implements Plugin.PluginBase { link += `?page=${page}`; if (filters.genre.value !== '') link += `&genre=${filters.genre.value}`; - + const body = await fetchApi(link).then(r => r.text()); - + return this.parseNovels(body); } @@ -78,110 +78,110 @@ class RoyalRoad implements Plugin.PluginBase { name: '', summary: '', chapters: [], - } + }; let isNovelName = false; let isAuthorName = false; let isDescription = false; let isH4 = false; - let isSpan = 0 + let isSpan = 0; let isTags = false; let isGenres = false; - let genreArray: string[] = [] + let genreArray: string[] = []; let isFooter = false; let isScript = false; let chapterJson: ChapterEntry[] = []; let volumeJson: VolumeEntry[] = []; - const parser = new Parser ({ - onopentag(name,attribs){ - if (name === 'img' && attribs['class']?.includes('thumbnail')){ + const parser = new Parser({ + onopentag(name, attribs) { + if (name === 'img' && attribs['class']?.includes('thumbnail')) { novel.cover = attribs['src']; } - if (name === 'span' && attribs['class']?.includes('label-sm')){ + if (name === 'span' && attribs['class']?.includes('label-sm')) { isSpan++; } - if (name === 'span' && attribs['class']?.includes('tags')){ + if (name === 'span' && attribs['class']?.includes('tags')) { isTags = true; } }, - onopentagname(name){ - if (name === 'h1'){ + onopentagname(name) { + if (name === 'h1') { isNovelName = true; } - if (isH4 && name === 'a'){ + if (isH4 && name === 'a') { isAuthorName = true; } - if(isTags && name === 'a'){ + if (isTags && name === 'a') { isGenres = true; } - if (name === 'label'){ + if (name === 'label') { isDescription = false; isTags = false; } - if (isFooter && name === 'script'){ + if (isFooter && name === 'script') { isScript = true; } }, - onattribute(name,value){ - if (name === 'class' && value === 'description'){ + onattribute(name, value) { + if (name === 'class' && value === 'description') { isDescription = true; } - if (name === 'class' && value === 'page-footer footer'){ + if (name === 'class' && value === 'page-footer footer') { isFooter = true; } }, - ontext(data){ - if (isNovelName){ + ontext(data) { + if (isNovelName) { novel.name = data; } - if (isAuthorName){ + if (isAuthorName) { novel.author = data; isAuthorName = false; } - if (isDescription){ + if (isDescription) { novel.summary += data; } - if (isSpan === 2){ + if (isSpan === 2) { novel.status = data.trim(); isSpan++; } - if (isGenres){ + if (isGenres) { genreArray.push(data); } - if (isScript){ - if (data.includes('window.chapters =')){ + if (isScript) { + if (data.includes('window.chapters =')) { chapterJson = JSON.parse( - data.match(/window.chapters = (.+])(?=;)/)![1] - ) + data.match(/window.chapters = (.+])(?=;)/)![1], + ); volumeJson = JSON.parse( - data.match(/window.volumes = (.+])(?=;)/)![1] - ) + data.match(/window.volumes = (.+])(?=;)/)![1], + ); } } }, - onclosetag(name){ - if (name === 'h1'){ + onclosetag(name) { + if (name === 'h1') { isNovelName = false; isH4 = true; } - if (name === 'h4'){ + if (name === 'h4') { isH4 = false; } - if (name === 'a'){ + if (name === 'a') { isGenres = false; } - if (name === 'script'){ + if (name === 'script') { isScript = false; } - if (name === 'body'){ + if (name === 'body') { isFooter = false; } - } - }) + }, + }); parser.write(html); parser.end(); novel.summary = novel.summary?.trim(); novel.genres = genreArray.join(', '); - switch(novel.status){ + switch (novel.status) { case 'ONGOING': novel.status = NovelStatus.Ongoing; break; @@ -224,106 +224,106 @@ class RoyalRoad implements Plugin.PluginBase { let isStyleText = false; let styles = ''; const parser = new Parser({ - onopentag(name,attribs){ - if (isChapter && name === 'div'){ - let stylediv = attribs['style'] - if(stylediv){ - chapterText += `
` + onopentag(name, attribs) { + if (isChapter && name === 'div') { + let stylediv = attribs['style']; + if (stylediv) { + chapterText += `
`; isStyleText = true; } else { - chapterText += `
` + chapterText += `
`; } } - if (isChapter && name === 'table'){ + if (isChapter && name === 'table') { let w = attribs['width']; - if(w) { + if (w) { chapterText += ``; } else { chapterText += `
`; } } - if (isChapter && name === 'tbody'){ + if (isChapter && name === 'tbody') { chapterText += ``; } - if (isChapter && name === 'tr'){ + if (isChapter && name === 'tr') { chapterText += ``; } - if (isChapter && name === 'td'){ + if (isChapter && name === 'td') { let w1 = attribs['width']; - if(w1) { + if (w1) { chapterText += ``; } - if (isChapter && name === 'tr'){ + if (isChapter && name === 'tr') { chapterText += ``; } - if (isChapter && name === 'tbody'){ + if (isChapter && name === 'tbody') { chapterText += ``; } - if (isChapter && name === 'table'){ + if (isChapter && name === 'table') { chapterText += `
`; } else { chapterText += ``; } } }, - onattribute(name, value){ - if (name === 'class' && value === 'chapter-inner chapter-content'){ + onattribute(name, value) { + if (name === 'class' && value === 'chapter-inner chapter-content') { isChapter = true; } - if (name === 'class' && value === 'portlet light t-center-3'){ + if (name === 'class' && value === 'portlet light t-center-3') { isChapter = false; isPtag = false; } - if (name === 'class' && value === styles){ + if (name === 'class' && value === styles) { isPtag = false; } }, - onopentagname(name){ - if (isChapter && name === 'p'){ + onopentagname(name) { + if (isChapter && name === 'p') { chapterText += '

'; isPtag = true; - if(isStyleText){ + if (isStyleText) { isStyleText = false; } } - if (name === 'style'){ + if (name === 'style') { isStyle = true; } - if (isChapter && name === 'br'){ + if (isChapter && name === 'br') { chapterText += `
`; } }, - ontext(data){ - if(isPtag){ + ontext(data) { + if (isPtag) { chapterText += data; } - if(isStyleText){ + if (isStyleText) { chapterText += data; } - if (isStyle){ - if (data.includes('display: none;')){ + if (isStyle) { + if (data.includes('display: none;')) { styles = data.match(/\.(.*)\{/)![1]; } } }, - onclosetag(name){ - if (name === 'p'){ + onclosetag(name) { + if (name === 'p') { isPtag = false; - chapterText += '

' + chapterText += '

'; } - if (name === 'style'){ + if (name === 'style') { isStyle = false; } - if (isChapter && name === 'td'){ + if (isChapter && name === 'td') { chapterText += `
`; } - if (isChapter && name === 'div'){ + if (isChapter && name === 'div') { isStyleText = false; - chapterText += `
` + chapterText += `
`; } - } - }) - parser.write(html) + }, + }); + parser.write(html); parser.end(); return chapterText; @@ -339,10 +339,6 @@ class RoyalRoad implements Plugin.PluginBase { return this.parseNovels(body); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { order: { value: 'weekly-popular', diff --git a/plugins/english/scribblehub.ts b/plugins/english/scribblehub.ts index d7b4ea4..756ee04 100644 --- a/plugins/english/scribblehub.ts +++ b/plugins/english/scribblehub.ts @@ -185,10 +185,6 @@ class ScribbleHubPlugin implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { sort: { label: 'Sort Results By', diff --git a/plugins/english/wtrlab.ts b/plugins/english/wtrlab.ts index 51db544..f010ddb 100644 --- a/plugins/english/wtrlab.ts +++ b/plugins/english/wtrlab.ts @@ -170,7 +170,6 @@ class WTRLAB implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; filters = { order: { value: 'chapter', diff --git a/plugins/english/wuxiaworld.ts b/plugins/english/wuxiaworld.ts index f824c91..79140dc 100644 --- a/plugins/english/wuxiaworld.ts +++ b/plugins/english/wuxiaworld.ts @@ -285,10 +285,6 @@ class WuxiaWorld implements Plugin.PluginBase { return this.parseNovels(data); } - fetchImage(url: string): Promise { - return fetchFile(url); - } - proto = ` syntax = "proto3"; option optimize_for = CODE_SIZE; diff --git a/plugins/french/chireads.ts b/plugins/french/chireads.ts index 5118bd3..f0f2467 100644 --- a/plugins/french/chireads.ts +++ b/plugins/french/chireads.ts @@ -250,8 +250,6 @@ class ChireadsPlugin implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; - filters = { tag: { type: FilterTypes.Picker, diff --git a/plugins/french/harkeneliwood.ts b/plugins/french/harkeneliwood.ts index eb14486..220b45e 100644 --- a/plugins/french/harkeneliwood.ts +++ b/plugins/french/harkeneliwood.ts @@ -173,12 +173,6 @@ class HarkenEliwoodPlugin implements Plugin.PluginBase { return novels; } - - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } } export default new HarkenEliwoodPlugin(); diff --git a/plugins/french/noveldeglace.ts b/plugins/french/noveldeglace.ts index 9fbe947..db1b0fe 100644 --- a/plugins/french/noveldeglace.ts +++ b/plugins/french/noveldeglace.ts @@ -292,8 +292,6 @@ class NovelDeGlacePlugin implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; - filters = { categorie_genre: { type: FilterTypes.Picker, diff --git a/plugins/french/novhell.ts b/plugins/french/novhell.ts index d7abcb6..f4ebedf 100644 --- a/plugins/french/novhell.ts +++ b/plugins/french/novhell.ts @@ -202,12 +202,6 @@ class NovhellPlugin implements Plugin.PluginBase { return novels; } - - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } } export default new NovhellPlugin(); diff --git a/plugins/french/phenixscans.ts b/plugins/french/phenixscans.ts index f9068a6..a309df5 100644 --- a/plugins/french/phenixscans.ts +++ b/plugins/french/phenixscans.ts @@ -172,13 +172,6 @@ class PhenixScansTradPlugin implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - const headers = new Headers({ - 'Referer': `${this.site}`, - }); - return await fetchFile(url, { headers }); - } - filters = { genre: { type: FilterTypes.CheckboxGroup, diff --git a/plugins/french/warriorlegendtrad.ts b/plugins/french/warriorlegendtrad.ts index fb720df..4d8138c 100644 --- a/plugins/french/warriorlegendtrad.ts +++ b/plugins/french/warriorlegendtrad.ts @@ -193,12 +193,6 @@ class WarriorLegendTradPlugin implements Plugin.PluginBase { return novels; } - - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } } export default new WarriorLegendTradPlugin(); diff --git a/plugins/french/wuxialnscantrad.ts b/plugins/french/wuxialnscantrad.ts index fa1435a..7568091 100644 --- a/plugins/french/wuxialnscantrad.ts +++ b/plugins/french/wuxialnscantrad.ts @@ -211,12 +211,6 @@ class WuxialnscantradPlugin implements Plugin.PluginBase { return novels; } - - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } } export default new WuxialnscantradPlugin(); diff --git a/plugins/french/xiaowaz.ts b/plugins/french/xiaowaz.ts index 0f628f0..b525ae9 100644 --- a/plugins/french/xiaowaz.ts +++ b/plugins/french/xiaowaz.ts @@ -293,12 +293,6 @@ class XiaowazPlugin implements Plugin.PluginBase { return await this.getNovelsCovers(novels); } - - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } } export default new XiaowazPlugin(); diff --git a/plugins/indonesian/indowebnovel.ts b/plugins/indonesian/indowebnovel.ts index ff7c10f..cc59721 100644 --- a/plugins/indonesian/indowebnovel.ts +++ b/plugins/indonesian/indowebnovel.ts @@ -131,10 +131,6 @@ class IndoWebNovel implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { status: { value: '', diff --git a/plugins/indonesian/novelringan.ts b/plugins/indonesian/novelringan.ts index 1dfd788..f9429bb 100644 --- a/plugins/indonesian/novelringan.ts +++ b/plugins/indonesian/novelringan.ts @@ -140,10 +140,6 @@ class NovelRingan implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { status: { value: '', diff --git a/plugins/indonesian/sakuranovel.ts b/plugins/indonesian/sakuranovel.ts index 8abb94e..b9a3276 100644 --- a/plugins/indonesian/sakuranovel.ts +++ b/plugins/indonesian/sakuranovel.ts @@ -159,10 +159,6 @@ class SakuraNovel implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } - filters = { status: { value: '', diff --git a/plugins/japanese/Syosetu.ts b/plugins/japanese/Syosetu.ts index 2a4e5a4..1da70be 100644 --- a/plugins/japanese/Syosetu.ts +++ b/plugins/japanese/Syosetu.ts @@ -217,9 +217,7 @@ class Syosetu implements Plugin.PluginBase { // respond with novels! return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } + resolveUrl(path: string, isNovel?: boolean | undefined): string { return this.novelPrefix + path; } diff --git a/plugins/korean/Agitoon.ts b/plugins/korean/Agitoon.ts index 21ef680..abc7b54 100644 --- a/plugins/korean/Agitoon.ts +++ b/plugins/korean/Agitoon.ts @@ -155,7 +155,6 @@ class Agitoon implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + (isNovel ? '/novel/list/' : '/novel/view/') + path; } diff --git a/plugins/polish/novelki.ts b/plugins/polish/novelki.ts index c8375b8..6b27fdd 100644 --- a/plugins/polish/novelki.ts +++ b/plugins/polish/novelki.ts @@ -165,11 +165,7 @@ class NovelkiPL implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - // if your plugin has images and they won't load - // this is the function to fiddle with - return fetchFile(url); - } + filters = { genres: { value: '', diff --git a/plugins/russian/LitSpace.ts b/plugins/russian/LitSpace.ts index 0338c0b..49287c2 100644 --- a/plugins/russian/LitSpace.ts +++ b/plugins/russian/LitSpace.ts @@ -151,8 +151,6 @@ class freedlit implements Plugin.PluginBase { return dateString || null; }; - fetchImage = fetchFile; - filters = { sort: { label: 'Сортировка:', diff --git a/plugins/russian/authortoday.ts b/plugins/russian/authortoday.ts index 45d50d7..3b64ef9 100644 --- a/plugins/russian/authortoday.ts +++ b/plugins/russian/authortoday.ts @@ -175,7 +175,6 @@ class AuthorToday implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => isNovel ? this.site + '/work/' + path : this.site + '/reader/' + path; diff --git a/plugins/russian/bookriver.ts b/plugins/russian/bookriver.ts index 3a89cbc..7fd6f7e 100644 --- a/plugins/russian/bookriver.ts +++ b/plugins/russian/bookriver.ts @@ -138,7 +138,6 @@ class Bookriver implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + (isNovel ? '/book/' : '/reader/') + path; diff --git a/plugins/russian/ficbook.ts b/plugins/russian/ficbook.ts index 408e94f..2f1035c 100644 --- a/plugins/russian/ficbook.ts +++ b/plugins/russian/ficbook.ts @@ -197,8 +197,6 @@ class ficbook implements Plugin.PluginBase { return dateString || null; }; - fetchImage = fetchFile; - filters = { sort: { label: 'Сортировка:', diff --git a/plugins/russian/jaomix.ts b/plugins/russian/jaomix.ts index 696bdd3..c11011e 100644 --- a/plugins/russian/jaomix.ts +++ b/plugins/russian/jaomix.ts @@ -193,8 +193,6 @@ class Jaomix implements Plugin.PluginBase { return dateString || null; }; - fetchImage = fetchFile; - filters = { sortby: { label: 'Сортировка:', diff --git a/plugins/russian/neobook.ts b/plugins/russian/neobook.ts index ce5f19e..78fe38f 100644 --- a/plugins/russian/neobook.ts +++ b/plugins/russian/neobook.ts @@ -143,7 +143,6 @@ class Neobook implements Plugin.PluginBase { return chapterText; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + (isNovel ? '/book/' : '/reader/') + path; diff --git a/plugins/russian/novelOvh.ts b/plugins/russian/novelOvh.ts index 0bd7ce8..9488096 100644 --- a/plugins/russian/novelOvh.ts +++ b/plugins/russian/novelOvh.ts @@ -158,7 +158,6 @@ class novelOvh implements Plugin.PluginBase { return html; }; - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + '/novel/' + path; diff --git a/plugins/russian/novelTL.ts b/plugins/russian/novelTL.ts index 703d1eb..96258dc 100644 --- a/plugins/russian/novelTL.ts +++ b/plugins/russian/novelTL.ts @@ -195,7 +195,6 @@ class TL implements Plugin.PluginBase { return chapterText; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => 'https://' + path; filters = { diff --git a/plugins/russian/ranobehub.ts b/plugins/russian/ranobehub.ts index 5c3a957..1782cef 100644 --- a/plugins/russian/ranobehub.ts +++ b/plugins/russian/ranobehub.ts @@ -164,7 +164,6 @@ class RNBH implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + '/ranobe/' + path; diff --git a/plugins/russian/ranobelib.ts b/plugins/russian/ranobelib.ts index f4f6c1d..8e23a05 100644 --- a/plugins/russian/ranobelib.ts +++ b/plugins/russian/ranobelib.ts @@ -216,7 +216,6 @@ class RLIB implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => { const ui = this.user?.ui ? 'ui=' + this.user.ui : ''; diff --git a/plugins/russian/ranoberf.ts b/plugins/russian/ranoberf.ts index 43d2fd0..709d4b6 100644 --- a/plugins/russian/ranoberf.ts +++ b/plugins/russian/ranoberf.ts @@ -134,8 +134,6 @@ class RNRF implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; - filters = { sort: { label: 'Сортировка', diff --git a/plugins/russian/renovels.ts b/plugins/russian/renovels.ts index 07c698b..da98780 100644 --- a/plugins/russian/renovels.ts +++ b/plugins/russian/renovels.ts @@ -147,7 +147,6 @@ class ReN implements Plugin.PluginBase { return novels; } - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + '/novel/' + path; diff --git a/plugins/russian/zelluloza.ts b/plugins/russian/zelluloza.ts index debae8d..4a35a17 100644 --- a/plugins/russian/zelluloza.ts +++ b/plugins/russian/zelluloza.ts @@ -190,7 +190,6 @@ class Zelluloza implements Plugin.PluginBase { return null; }; - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + '/books/' + path; diff --git a/plugins/spanish/hasutl.ts b/plugins/spanish/hasutl.ts index bd45c37..d36fb20 100644 --- a/plugins/spanish/hasutl.ts +++ b/plugins/spanish/hasutl.ts @@ -136,9 +136,6 @@ class HasulTL implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new HasulTL(); diff --git a/plugins/spanish/novelasligera.ts b/plugins/spanish/novelasligera.ts index 766b63a..2eb93c5 100644 --- a/plugins/spanish/novelasligera.ts +++ b/plugins/spanish/novelasligera.ts @@ -176,9 +176,6 @@ class Ligera implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new Ligera(); diff --git a/plugins/spanish/novelawuxia.ts b/plugins/spanish/novelawuxia.ts index e160f55..bbcc9da 100644 --- a/plugins/spanish/novelawuxia.ts +++ b/plugins/spanish/novelawuxia.ts @@ -199,9 +199,6 @@ class ReinoWuxia implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new ReinoWuxia(); diff --git a/plugins/spanish/oasistranslations.ts b/plugins/spanish/oasistranslations.ts index 5d7616d..3921e90 100644 --- a/plugins/spanish/oasistranslations.ts +++ b/plugins/spanish/oasistranslations.ts @@ -161,9 +161,6 @@ class Oasis implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new Oasis(); diff --git a/plugins/spanish/skynovels.ts b/plugins/spanish/skynovels.ts index d0b8a5b..2bc1b49 100644 --- a/plugins/spanish/skynovels.ts +++ b/plugins/spanish/skynovels.ts @@ -128,9 +128,6 @@ class SkyNovels implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new SkyNovels(); diff --git a/plugins/spanish/tunovelaligera.ts b/plugins/spanish/tunovelaligera.ts index baa3246..74af715 100644 --- a/plugins/spanish/tunovelaligera.ts +++ b/plugins/spanish/tunovelaligera.ts @@ -182,10 +182,6 @@ class TuNovelaLigera implements Plugin.PagePlugin { return novels; } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } - filters = { order: { value: 'rating', diff --git a/plugins/spanish/yukitls.ts b/plugins/spanish/yukitls.ts index 439ccc8..3ed3154 100644 --- a/plugins/spanish/yukitls.ts +++ b/plugins/spanish/yukitls.ts @@ -179,9 +179,6 @@ class Yuuki implements Plugin.PluginBase { return novels; } - fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new Yuuki(); diff --git a/plugins/turkish/epiknovel.ts b/plugins/turkish/epiknovel.ts index 3759c48..ae57e0b 100644 --- a/plugins/turkish/epiknovel.ts +++ b/plugins/turkish/epiknovel.ts @@ -159,9 +159,6 @@ class EpikNovel implements Plugin.PluginBase { return novels; } - fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new EpikNovel(); diff --git a/plugins/turkish/lshnovel.broken.ts b/plugins/turkish/lshnovel.broken.ts index a813f1a..e40f64e 100644 --- a/plugins/turkish/lshnovel.broken.ts +++ b/plugins/turkish/lshnovel.broken.ts @@ -166,9 +166,6 @@ class LSHNovel implements Plugin.PluginBase { return novels; } - async fetchImage(url: string): Promise { - return await fetchFile(url); - } filters = { order: { diff --git a/plugins/ukrainian/smakolykytl.ts b/plugins/ukrainian/smakolykytl.ts index 18d2856..0514861 100644 --- a/plugins/ukrainian/smakolykytl.ts +++ b/plugins/ukrainian/smakolykytl.ts @@ -113,8 +113,6 @@ class Smakolykytl implements Plugin.PluginBase { ); return novels; } - - fetchImage = fetchFile; } export default new Smakolykytl(); diff --git a/plugins/vietnamese/LNHako.ts b/plugins/vietnamese/LNHako.ts index e6339f2..62b29f4 100644 --- a/plugins/vietnamese/LNHako.ts +++ b/plugins/vietnamese/LNHako.ts @@ -1,5 +1,4 @@ import { Parser } from 'htmlparser2'; -import { fetchFile } from '@libs/fetch'; import { HTMLParser2Util, Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; import { FilterTypes, Filters } from '@libs/filterInputs'; @@ -395,6 +394,8 @@ class HakoPlugin implements Plugin.PluginBase { novel.status = NovelStatus.Unknown; } novel.genres = novel.genres?.replace(/,*\s*$/, ''); + novel.name = novel.name.trim(); + novel.summary = novel.summary?.trim(); return novel; }); } @@ -416,12 +417,11 @@ class HakoPlugin implements Plugin.PluginBase { this.site + '/tim-kiem?keywords=' + searchTerm + '&page=' + pageNo; return this.parseNovels(url); } - fetchImage(url: string): Promise { - const headers = { + imageRequestInit: Plugin.ImageRequestInit = { + headers: { Referer: 'https://ln.hako.vn', - }; - return fetchFile(url, { headers: headers }); - } + }, + }; filters = { alphabet: { type: FilterTypes.Picker, diff --git a/plugins/vietnamese/Truyenconect.ts b/plugins/vietnamese/Truyenconect.ts index 10dcb0e..4baaa3b 100644 --- a/plugins/vietnamese/Truyenconect.ts +++ b/plugins/vietnamese/Truyenconect.ts @@ -247,9 +247,7 @@ class TruyenConect implements Plugin.PagePlugin { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } + filters = { category: { label: 'Lọc theo', diff --git a/plugins/vietnamese/lightnovelvn.ts b/plugins/vietnamese/lightnovelvn.ts index 7df5e7b..b91059a 100644 --- a/plugins/vietnamese/lightnovelvn.ts +++ b/plugins/vietnamese/lightnovelvn.ts @@ -170,9 +170,6 @@ class LightNovelVN implements Plugin.PagePlugin { }) || []; return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new LightNovelVN(); diff --git a/plugins/vietnamese/nettruyen.ts b/plugins/vietnamese/nettruyen.ts index 7b3d815..f16994a 100644 --- a/plugins/vietnamese/nettruyen.ts +++ b/plugins/vietnamese/nettruyen.ts @@ -119,8 +119,5 @@ class Nettruyen implements Plugin.PagePlugin { ): Promise { throw new Error('Method not implemented.'); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new Nettruyen(); diff --git a/plugins/vietnamese/truyenchu.ts b/plugins/vietnamese/truyenchu.ts index 667b714..81c4d75 100644 --- a/plugins/vietnamese/truyenchu.ts +++ b/plugins/vietnamese/truyenchu.ts @@ -151,9 +151,6 @@ class TruyenFull implements Plugin.PagePlugin { const loadedCheerio = parseHTML(body); return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new TruyenFull(); diff --git a/plugins/vietnamese/truyenfull.ts b/plugins/vietnamese/truyenfull.ts index 82a9c09..dffe073 100644 --- a/plugins/vietnamese/truyenfull.ts +++ b/plugins/vietnamese/truyenfull.ts @@ -142,9 +142,6 @@ class TruyenFull implements Plugin.PagePlugin { const loadedCheerio = parseHTML(body); return this.parseNovels(loadedCheerio); } - async fetchImage(url: string): Promise { - return fetchFile(url); - } } export default new TruyenFull(); diff --git a/scripts/multisrc/hotnovelpub/template.ts b/scripts/multisrc/hotnovelpub/template.ts index 49677f8..31d1e7d 100644 --- a/scripts/multisrc/hotnovelpub/template.ts +++ b/scripts/multisrc/hotnovelpub/template.ts @@ -1,4 +1,4 @@ -import { fetchFile, fetchApi } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Filters, FilterTypes } from '@libs/filterInputs'; import { Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; @@ -162,8 +162,6 @@ class HotNovelPubPlugin implements Plugin.PluginBase { return novels; } - - fetchImage = fetchFile; resolveUrl = (path: string, isNovel?: boolean) => this.site + '/' + path; } diff --git a/scripts/multisrc/ifreedom/template.ts b/scripts/multisrc/ifreedom/template.ts index 9bf1633..cca9e92 100644 --- a/scripts/multisrc/ifreedom/template.ts +++ b/scripts/multisrc/ifreedom/template.ts @@ -1,4 +1,4 @@ -import { fetchFile, fetchApi } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Filters, FilterTypes } from '@libs/filterInputs'; import { Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; @@ -216,6 +216,4 @@ class IfreedomPlugin implements Plugin.PluginBase { } return dateString || null; }; - - fetchImage = fetchFile; } diff --git a/scripts/multisrc/lightnovelworld/template.ts b/scripts/multisrc/lightnovelworld/template.ts index c2bfd12..ba2c967 100644 --- a/scripts/multisrc/lightnovelworld/template.ts +++ b/scripts/multisrc/lightnovelworld/template.ts @@ -1,5 +1,5 @@ import { load as parseHTML } from 'cheerio'; -import { fetchApi, fetchFile } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Plugin } from '@typings/plugin'; import { Filters, FilterTypes } from '@libs/filterInputs'; import dayjs from 'dayjs'; @@ -27,6 +27,9 @@ class LightNovelWorld implements Plugin.PagePlugin { Accept: 'application/json', 'Content-Type': 'application/json', }; + imageRequestInit?: Plugin.ImageRequestInit | undefined = { + headers: this.headers, + }; options?: LightNovelWorldOptions; constructor(metadata: LightNovelWorldMetadata) { @@ -188,10 +191,6 @@ class LightNovelWorld implements Plugin.PagePlugin { return novels; } - async fetchImage(url: string): Promise { - return fetchFile(url, { headers: this.headers }); - } - filters = { order: { value: 'popular', diff --git a/scripts/multisrc/lightnovelwp/template.ts b/scripts/multisrc/lightnovelwp/template.ts index 1266205..97c769c 100644 --- a/scripts/multisrc/lightnovelwp/template.ts +++ b/scripts/multisrc/lightnovelwp/template.ts @@ -1,6 +1,6 @@ import { load } from 'cheerio'; import { Parser } from 'htmlparser2'; -import { fetchApi, fetchFile } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; import { defaultCover } from '@libs/defaultCover'; @@ -407,8 +407,6 @@ class LightNovelWPPlugin implements Plugin.PluginBase { const html = await this.safeFecth(url, true); return this.parseNovels(html); } - - fetchImage = fetchFile; } function extractChapterNumber(data: string, tempChapter: Plugin.ChapterItem) { diff --git a/scripts/multisrc/madara/template.ts b/scripts/multisrc/madara/template.ts index 5992e67..8257b82 100644 --- a/scripts/multisrc/madara/template.ts +++ b/scripts/multisrc/madara/template.ts @@ -1,4 +1,4 @@ -import { fetchApi, fetchFile } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Filters, FilterTypes } from '@libs/filterInputs'; import { Plugin } from '@typings/plugin'; import { Cheerio, AnyNode, CheerioAPI, load as parseHTML } from 'cheerio'; @@ -294,8 +294,6 @@ class MadaraPlugin implements Plugin.PluginBase { return this.parseNovels(loadedCheerio); } - fetchImage = fetchFile; - parseData = (date: string) => { const dayJSDate = dayjs(); // today const timeAgo = date.match(/\d+/)?.[0] || ''; diff --git a/scripts/multisrc/readnovelfull/template.ts b/scripts/multisrc/readnovelfull/template.ts index 61abdb9..a265c2a 100644 --- a/scripts/multisrc/readnovelfull/template.ts +++ b/scripts/multisrc/readnovelfull/template.ts @@ -1,5 +1,5 @@ import { CheerioAPI, load } from 'cheerio'; -import { fetchApi, fetchFile } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; @@ -172,6 +172,4 @@ class ReadNovelFullPlugin implements Plugin.PluginBase { return this.parseNovels($); } - - fetchImage = fetchFile; } diff --git a/scripts/multisrc/readwn/template.ts b/scripts/multisrc/readwn/template.ts index c8de278..6e3cd18 100644 --- a/scripts/multisrc/readwn/template.ts +++ b/scripts/multisrc/readwn/template.ts @@ -1,4 +1,4 @@ -import { fetchFile, fetchApi } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Filters, FilterTypes } from '@libs/filterInputs'; import { Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; @@ -223,6 +223,4 @@ class ReadwnPlugin implements Plugin.PluginBase { .filter(novel => novel.name && novel.path); return novels; } - - fetchImage = fetchFile; } diff --git a/scripts/multisrc/rulate/template.ts b/scripts/multisrc/rulate/template.ts index 77090ff..e25d0d3 100644 --- a/scripts/multisrc/rulate/template.ts +++ b/scripts/multisrc/rulate/template.ts @@ -1,4 +1,4 @@ -import { fetchFile, fetchApi } from '@libs/fetch'; +import { fetchApi } from '@libs/fetch'; import { Filters, FilterTypes } from '@libs/filterInputs'; import { Plugin } from '@typings/plugin'; import { NovelStatus } from '@libs/novelStatus'; @@ -246,8 +246,6 @@ class RulatePlugin implements Plugin.PluginBase { } return dateString || null; }; - - fetchImage = fetchFile; } interface response { diff --git a/test_web/api/plugins.ts b/test_web/api/plugins.ts index f8cf440..804fc94 100644 --- a/test_web/api/plugins.ts +++ b/test_web/api/plugins.ts @@ -4,6 +4,7 @@ import path from 'path'; import { PluginList } from '@typings/types'; import { Plugin } from '@typings/plugin'; import { Filters } from '@libs/filterInputs'; +import { fetchFile } from '@libs/fetch'; const root = path.dirname(require?.main?.filename || ''); export const fetchHeaders: Record = {}; @@ -83,8 +84,14 @@ export const parseChapter = async ( chapterPath: string, ) => (await getPlugin(pluginRequirePath))?.parseChapter(chapterPath); -export const fetchImage = async (pluginRequirePath: string, url: string) => - (await getPlugin(pluginRequirePath))?.fetchImage(url); +export const fetchImage = async (pluginRequirePath: string, url: string) => { + const plugin = await getPlugin(pluginRequirePath); + return fetchFile(url, { + method: plugin?.imageRequestInit?.method, + headers: plugin?.imageRequestInit?.headers, + body: plugin?.imageRequestInit?.body, + }); +}; export const resolveUrl = async ( pluginRequirePath: string, diff --git a/types/plugin.ts b/types/plugin.ts index 797e4c3..de1786b 100644 --- a/types/plugin.ts +++ b/types/plugin.ts @@ -53,6 +53,11 @@ export namespace Plugin { requirePath: string; icon: string; } + export interface ImageRequestInit { + method?: string; + headers?: Record; + body?: string; + } export interface PluginBase { id: string; @@ -65,6 +70,7 @@ export namespace Plugin { */ icon: string; site: string; + imageRequestInit?: ImageRequestInit; filters?: Filters; version: string; //flag indicates whether access to LocalStorage, SesesionStorage is required. @@ -93,7 +99,6 @@ export namespace Plugin { * return await fetchFile(url, { headers: headers }); * ``` */ - fetchImage(url: string): Promise; resolveUrl?(path: string, isNovel?: boolean): string; }