Freewebnovel: update (#1648)

* freewebnovel

* forgot most-popular
This commit is contained in:
K1ngfish3r
2025-04-24 06:13:23 +05:00
committed by GitHub
parent f1f847546c
commit e6196254bf
+92 -74
View File
@@ -7,7 +7,7 @@ class FreeWebNovel implements Plugin.PluginBase {
id = 'FWN.com'; id = 'FWN.com';
name = 'Free Web Novel'; name = 'Free Web Novel';
site = 'https://freewebnovel.com/'; site = 'https://freewebnovel.com/';
version = '1.1.3'; version = '1.2.0';
icon = 'src/en/freewebnovel/icon.png'; icon = 'src/en/freewebnovel/icon.png';
lastSearch: number | null = null; lastSearch: number | null = null;
@@ -26,16 +26,23 @@ class FreeWebNovel implements Plugin.PluginBase {
return parseHTML(await r.text()); return parseHTML(await r.text());
} }
parseNovels(loadedCheerio: CheerioAPI): Plugin.NovelItem[] { parseNovels(loadedCheerio: CheerioAPI) {
return loadedCheerio('.li-row') return loadedCheerio('.li-row')
.map((index, element) => ({ .toArray()
name: loadedCheerio(element).find('.tit').text() || '', .map(el => {
cover: this.site + loadedCheerio(element).find('img').attr('src'), const row = loadedCheerio(el);
path: const name = row.find('.tit').text().trim();
loadedCheerio(element).find('h3 > a').attr('href')?.slice(1) || '', const path = row.find('h3 > a').attr('href')?.slice(1);
})) if (!name || !path) return null;
.get()
.filter(novel => novel.name && novel.path); const coverSrc = row.find('img').attr('src') || '';
const cover = coverSrc.startsWith('http')
? coverSrc
: this.site + coverSrc;
return { name, cover, path };
})
.filter(Boolean) as Plugin.NovelItem[];
} }
async popularNovels( async popularNovels(
@@ -45,87 +52,96 @@ class FreeWebNovel implements Plugin.PluginBase {
filters, filters,
}: Plugin.PopularNovelsOptions<typeof this.filters>, }: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> { ): Promise<Plugin.NovelItem[]> {
let url = this.site; let path: string;
if (showLatestNovels) url += 'sort/latest-novels/';
else {
if (filters && filters.genres && filters.genres.value !== '')
url += filters.genres.value;
else {
url += 'most-popular/';
if (page != 1) return [];
page = 0;
}
}
url += page;
const $ = await this.getCheerio(url); if (showLatestNovels) {
return this.parseNovels($); path = 'sort/latest-novels/';
} else if (filters?.genres?.value) {
path = filters.genres.value;
} else {
if (page !== 1) return [];
path = 'most-popular/';
page = 0;
}
const url = `${this.site}${path}${page}`;
const loadedCheerio = await this.getCheerio(url);
return this.parseNovels(loadedCheerio);
} }
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> { async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const loadedCheerio = await this.getCheerio(this.site + novelPath); const loadedCheerio = await this.getCheerio(this.site + novelPath);
const novel: Plugin.SourceNovel = { const novel: Partial<Plugin.SourceNovel> = {
path: novelPath, path: novelPath,
name: loadedCheerio('h1.tit').text(),
cover: this.site + loadedCheerio('.pic > img').attr('src'),
summary: loadedCheerio('.inner').text().trim(),
}; };
novel.genres = loadedCheerio('[title=Genre]') const img = loadedCheerio('.m-imgtxt img');
.next() novel.name = img.attr('title');
.text() novel.cover = this.site + img.attr('src');
.replace(/[\t\n]/g, '');
novel.author = loadedCheerio('[title=Author]') loadedCheerio('.m-imgtxt .item').each((i, el) => {
.next() const item = loadedCheerio(el);
.text() const title = item.find('span').attr('title');
.replace(/[\t\n]/g, '');
novel.status = loadedCheerio('[title=Status]') switch (title) {
.next() case 'Author':
.text() novel.author = item.find('.right a').text();
.replace(/[\t\n]/g, ''); break;
case 'Status':
novel.status = item.find('.right span').text();
break;
case 'Genre':
novel.genres = item
.find('.right a')
.map((_, el) => loadedCheerio(el).text())
.toArray()
.join(', ');
break;
}
});
novel.genres = loadedCheerio('[title=Genre]') novel.summary = loadedCheerio('.inner p')
.next() .toArray()
.text() .map(p => loadedCheerio(p).text().trim())
.trim() .join('\n');
.replace(/[\t\n]/g, ',')
.replace(/, /g, ',');
const chapters: Plugin.ChapterItem[] = loadedCheerio('#idData > li > a') const chapters: Plugin.ChapterItem[] = loadedCheerio('#idData > li > a')
.map((chapterIndex, element) => ({ .toArray()
name: .map((el, i) => {
loadedCheerio(element).attr('title') || const a = loadedCheerio(el);
'Chapter ' + (chapterIndex + 1), const name = a.attr('title') || `Chapter ${i + 1}`;
path: const href = a.attr('href');
loadedCheerio(element).attr('href')?.slice(1) || const path =
novelPath.replace( href?.slice(1) ||
'.html', novelPath.replace('.html', `/chapter-${i + 1}.html`);
'/chapter-' + (chapterIndex + 1) + '.html',
), return {
releaseTime: null, name,
chapterNumber: chapterIndex + 1, path,
})) releaseTime: null,
.get(); chapterNumber: i + 1,
};
});
novel.chapters = chapters; novel.chapters = chapters;
return novel; return novel as Plugin.SourceNovel;
} }
async parseChapter(chapterPath: string): Promise<string> { async parseChapter(chapterPath: string): Promise<string> {
const loadedCheerio = await this.getCheerio(this.site + chapterPath); const loadedCheerio = await this.getCheerio(this.site + chapterPath);
const script = loadedCheerio('.footer')
// remove freewebnovel signature .prev()
if (loadedCheerio('style').text().includes('p:nth-last-child(1)')) .text()
loadedCheerio('div.txt').find('p:last-child').remove(); .match(/e\("([^]+?)"/)?.[1];
const chapterText = loadedCheerio('div.txt').html() || ''; const chapterText = loadedCheerio('div.txt').html() || '';
return chapterText.replace( return chapterText
/>([^<\.]+?\.)?[^\.<]*?\b[ƒfF][Rrɾг][Eēeё]+[Wwω𝑤]+[Eёēe][Bbɓ][Nnɳη][Oø૦ѳσo][Vѵνv][Eёeē][^<]*/g, .replace(script!, '')
'>$1', .replace(
); />([^<\.]+?\.)?[^\.<]*?[ƒfF][Rrɾг][Eēeё]+[Wwω𝑤]+[Eёēe][Bbɓ][Nnɳη][Oø૦ѳσo][Vѵνv][Eёeē][^<,!\?;:\"”“’‘\(\)\-\d]*/g,
'>$1',
);
} }
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> { async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
@@ -133,18 +149,20 @@ class FreeWebNovel implements Plugin.PluginBase {
if (this.lastSearch && now - this.lastSearch <= this.searchInterval) { if (this.lastSearch && now - this.lastSearch <= this.searchInterval) {
await this.sleep(this.searchInterval); await this.sleep(this.searchInterval);
} }
const r = await fetchApi(this.site + 'search', { const r = await fetchApi(this.site + 'search', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ searchkey: searchTerm }).toString(), body: new URLSearchParams({ searchkey: searchTerm }).toString(),
}); });
this.lastSearch = Date.now(); this.lastSearch = Date.now();
if (!r.ok)
if (!r.ok) {
throw new Error( throw new Error(
'Could not reach site (' + r.status + ') try to open in webview.', `Could not reach site ('${r.status}') try to open in webview.`,
); );
}
const loadedCheerio = parseHTML(await r.text()); const loadedCheerio = parseHTML(await r.text());
const alertText = const alertText =