From 4165bbf7017cb395049b8157ac6989b4d6653b14 Mon Sep 17 00:00:00 2001 From: Adam Kemish <49228220+Soopyboo32@users.noreply.github.com> Date: Sun, 26 Jan 2025 21:23:35 +0800 Subject: [PATCH] Add daoist quest (#1462) --- public/static/src/en/daoistquest/icon.png | Bin 0 -> 806 bytes src/plugins/english/daoistquest.ts | 130 ++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 public/static/src/en/daoistquest/icon.png create mode 100644 src/plugins/english/daoistquest.ts diff --git a/public/static/src/en/daoistquest/icon.png b/public/static/src/en/daoistquest/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..31ed9043e2b48ed91b6fed6b262fede2d964b551 GIT binary patch literal 806 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dy(*k@#T-^(N98f`cc(|jZV{L6M zs<4Brt1Dc@#|NZq%a$!b^8f$;fByXW`SYino7<~bufBf$`r*Te?Ck95=;)G?k`*gf zoIQKi*Vp&brAv<=KVGtQ$9OOrAXX-o1O>-QCH_$y>K> z-Me>hTV3M`pbJGyg8YIRzANt5{3Ukx-`TLWZBq^M`D?yU>pk;!)-(nNCM{1F$B>F! zxsxL&-8SHH(XGx2iaTz~c*J$eirV;^|EF1}%;{M+>H9(cMXN8mGVRX)_FR8{rQGNI z=YQYDzY8yGF?au8W&c-a{yd!~-9Oj)j~;&*!C%UiJn_>;v%n+Pbw6+1_{~r#q4w9} z%UXxEQ|gvJxWB!0LSc@z>Xe6j=Smkbf4DEVoLR>wFp^_U<)tG+VtVttAN=&o->u`G znloX>zNwR(}nY zq_%8AfaaD!SFwMY<#EDGO0Ac6FX0q8%s4sY0mHq@@2uRVlUwiFxT&la2uwDA%FA%4 z>|a(ctB_;dlmsW0NuH@Gl{X9-G8btbn7W`lwe^ThwrgF^^NB0hUQ1f>GNfi%@Ds<XVDU?!9zH*?j4jKhOVv`(3h6R-$mn dT=VYV(xp=a)l9W#RRWV0gQu&X%Q~loCIDbjcb@, + ): Promise { + if (pageNo !== 1) return []; + const req = await fetchApi(this.site + '/collection/novels/'); + const body = await req.text(); + const loadedCheerio = loadCheerio(body); + + return loadedCheerio('#featured-list > li > div > div') + .map((i, el) => { + const novelName = loadedCheerio(el).find('h3 > a').text(); + const novelCover = loadedCheerio(el) + .find('a.cell-img:has(img)') + .attr('href'); + const novelUrl = loadedCheerio(el).find('h3 > a').attr('href'); + + return { + name: novelName, + cover: novelCover, + path: novelUrl!.replace(this.site + '/', '').replace(/\/$/, ''), + }; + }) + .toArray(); + } + + async parseNovel(novelPath: string): Promise { + const req = await fetchApi(this.site + '/' + novelPath + '/'); + const body = await req.text(); + const loadedCheerio = loadCheerio(body); + + const novel: Plugin.SourceNovel = { + path: novelPath, + name: loadedCheerio('h1.story__identity-title').text(), + }; + + // novel.artist = ''; + novel.author = loadedCheerio('div.story__identity-meta') + .text() + .split('|')[0] + .replace('Author: ', '') + .trim(); + novel.cover = loadedCheerio('figure.story__thumbnail > a').attr('href'); + novel.genres = loadedCheerio('div.tag-group > a') + .map((i, el) => loadedCheerio(el).text()) + .toArray() + .join(','); + novel.summary = loadedCheerio('section.story__summary').text(); + + novel.chapters = loadedCheerio('li.chapter-group__list-item._publish') + .filter((i, el) => !el.attribs['class'].includes('_password')) + .map((i, el) => { + const chapterName = loadedCheerio(el).find('a').text(); + const chapterUrl = loadedCheerio(el) + .find('a') + .attr('href') + ?.replace(this.site + '/', '') + .replace(/\/$/, ''); + + return { + name: chapterName, + path: chapterUrl!, + }; + }) + .toArray(); + + return novel; + } + + async parseChapter(chapterPath: string): Promise { + const req = await fetchApi(this.site + '/' + chapterPath + '/'); + const body = await req.text(); + + const loadedCheerio = loadCheerio(body); + return loadedCheerio('section#chapter-content > div').html() || ''; + } + + async searchNovels( + searchTerm: string, + pageNo: number, + ): Promise { + if (pageNo !== 1) return []; + const req = await fetchApi( + this.site + `?s=${encodeURIComponent(searchTerm)}&post_type=fcn_story`, + ); + const body = await req.text(); + const loadedCheerio = loadCheerio(body); + + return loadedCheerio('#search-result-list > li > div > div') + .map((i, el) => { + const novelName = loadedCheerio(el).find('h3 > a').text(); + const novelCover = loadedCheerio(el) + .find('a.cell-img:has(img)') + .attr('href'); + const novelUrl = loadedCheerio(el).find('h3 > a').attr('href'); + + return { + name: novelName, + cover: novelCover, + path: novelUrl!.replace(this.site + '/', '').replace(/\/$/, ''), + }; + }) + .toArray(); + } + + resolveUrl = (path: string, isNovel?: boolean) => + this.site + '/' + path + '/'; +} + +export default new DaoistQuestPlugin();