diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/lib/Data/Manga/raw.ts | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/lib/Data/Manga/raw.ts')
| -rw-r--r-- | src/lib/Data/Manga/raw.ts | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/lib/Data/Manga/raw.ts b/src/lib/Data/Manga/raw.ts index 0d7e928c..4dfa6a8e 100644 --- a/src/lib/Data/Manga/raw.ts +++ b/src/lib/Data/Manga/raw.ts @@ -1,47 +1,47 @@ import proxy from '$lib/Utility/proxy'; interface Chapter { - href: string; - chapterNum: string; - chapterDate: string; + href: string; + chapterNum: string; + chapterDate: string; } export const getChapterCount = async (nativeTitle: string): Promise<number | undefined> => { - const html = new DOMParser().parseFromString( - await (await fetch(proxy(`https://rawkuma.com/?s=${encodeURIComponent(nativeTitle)}`))).text(), - 'text/html' - ); - const listContent = html.querySelector('.listupd'); + const html = new DOMParser().parseFromString( + await (await fetch(proxy(`https://rawkuma.com/?s=${encodeURIComponent(nativeTitle)}`))).text(), + 'text/html' + ); + const listContent = html.querySelector('.listupd'); - if (listContent && listContent.textContent && listContent.textContent.includes('Not Found')) { - return undefined; - } + if (listContent && listContent.textContent && listContent.textContent.includes('Not Found')) { + return undefined; + } - const chapterCount = html.querySelector('.epxs'); + const chapterCount = html.querySelector('.epxs'); - if (chapterCount && chapterCount.textContent && chapterCount.textContent.includes('Chapter')) { - return Number.parseInt(chapterCount.textContent.replace('Chapter', '').trim(), 10); - } + if (chapterCount && chapterCount.textContent && chapterCount.textContent.includes('Chapter')) { + return Number.parseInt(chapterCount.textContent.replace('Chapter', '').trim(), 10); + } - return undefined; + return undefined; }; export const getChaptersFromText = (text: string) => { - const dom = new DOMParser().parseFromString(text, 'text/html').querySelectorAll('.eph-num'); - const chapters: Chapter[] = []; - - dom.forEach((chapter) => { - const href = chapter.querySelector('a')?.getAttribute('href'); - const chapterNum = chapter.querySelector('.chapternum')?.textContent; - const chapterDate = chapter.querySelector('.chapterdate')?.textContent; - - if (href && chapterNum && chapterDate) - chapters.push({ - href, - chapterNum, - chapterDate - }); - }); - - return chapters; + const dom = new DOMParser().parseFromString(text, 'text/html').querySelectorAll('.eph-num'); + const chapters: Chapter[] = []; + + dom.forEach((chapter) => { + const href = chapter.querySelector('a')?.getAttribute('href'); + const chapterNum = chapter.querySelector('.chapternum')?.textContent; + const chapterDate = chapter.querySelector('.chapterdate')?.textContent; + + if (href && chapterNum && chapterDate) + chapters.push({ + href, + chapterNum, + chapterDate + }); + }); + + return chapters; }; |