+38
-13
@@ -2,14 +2,14 @@ import { Plugin } from '@/types/plugin';
|
|||||||
import { FilterTypes, Filters } from '@libs/filterInputs';
|
import { FilterTypes, Filters } from '@libs/filterInputs';
|
||||||
import { fetchApi } from '@libs/fetch';
|
import { fetchApi } from '@libs/fetch';
|
||||||
import { NovelStatus } from '@libs/novelStatus';
|
import { NovelStatus } from '@libs/novelStatus';
|
||||||
import { load as parseHTML } from 'cheerio';
|
import { load as parseHTML, CheerioAPI } from 'cheerio';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
class Jaomix implements Plugin.PluginBase {
|
class Jaomix implements Plugin.PagePlugin {
|
||||||
id = 'jaomix.ru';
|
id = 'jaomix.ru';
|
||||||
name = 'Jaomix';
|
name = 'Jaomix';
|
||||||
site = 'https://jaomix.ru';
|
site = 'https://jaomix.ru';
|
||||||
version = '1.0.2';
|
version = '1.0.3';
|
||||||
icon = 'src/ru/jaomix/icon.png';
|
icon = 'src/ru/jaomix/icon.png';
|
||||||
|
|
||||||
async popularNovels(
|
async popularNovels(
|
||||||
@@ -72,15 +72,18 @@ class Jaomix implements Plugin.PluginBase {
|
|||||||
return novels;
|
return novels;
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
async parseNovel(
|
||||||
|
novelPath: string,
|
||||||
|
): Promise<Plugin.SourceNovel & { totalPages: number }> {
|
||||||
const body = await fetchApi(this.site + novelPath).then(res => res.text());
|
const body = await fetchApi(this.site + novelPath).then(res => res.text());
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
|
|
||||||
const novel: Plugin.SourceNovel = {
|
const novel: Plugin.SourceNovel & { totalPages: number } = {
|
||||||
path: novelPath,
|
path: novelPath,
|
||||||
name: loadedCheerio('div[class="desc-book"] > h1').text().trim(),
|
name: loadedCheerio('div[class="desc-book"] > h1').text().trim(),
|
||||||
cover: loadedCheerio('div[class="img-book"] > img').attr('src'),
|
cover: loadedCheerio('div[class="img-book"] > img').attr('src'),
|
||||||
summary: loadedCheerio('div[id="desc-tab"]').text().trim(),
|
summary: loadedCheerio('div[id="desc-tab"]').text().trim(),
|
||||||
|
totalPages: loadedCheerio('.sel-toc > option').length,
|
||||||
};
|
};
|
||||||
|
|
||||||
loadedCheerio('#info-book > p').each(function () {
|
loadedCheerio('#info-book > p').each(function () {
|
||||||
@@ -95,11 +98,36 @@ class Jaomix implements Plugin.PluginBase {
|
|||||||
: NovelStatus.Completed;
|
: NovelStatus.Completed;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
novel.chapters = this.parseChapters(loadedCheerio);
|
||||||
|
return novel;
|
||||||
|
}
|
||||||
|
|
||||||
|
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
|
||||||
|
const body = await fetchApi(`${this.site}/wp-admin/admin-ajax.php`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
Referer: this.site + novelPath,
|
||||||
|
Origin: this.site,
|
||||||
|
},
|
||||||
|
body: new URLSearchParams({
|
||||||
|
action: 'loadpagenavchapstt',
|
||||||
|
page,
|
||||||
|
}).toString(),
|
||||||
|
}).then(data => data.text());
|
||||||
|
|
||||||
|
const loadedCheerio = parseHTML(body);
|
||||||
|
const chapters = this.parseChapters(loadedCheerio);
|
||||||
|
|
||||||
|
return {
|
||||||
|
chapters,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
parseChapters(loadedCheerio: CheerioAPI) {
|
||||||
const chapters: Plugin.ChapterItem[] = [];
|
const chapters: Plugin.ChapterItem[] = [];
|
||||||
const totalChapters = loadedCheerio('div.title').length;
|
|
||||||
|
|
||||||
loadedCheerio('div.title').each((chapterIndex, element) => {
|
loadedCheerio('div.title').each((_, element) => {
|
||||||
const name = loadedCheerio(element).find('a').attr('title');
|
const name = loadedCheerio(element).find('a').attr('title');
|
||||||
const url = loadedCheerio(element).find('a').attr('href');
|
const url = loadedCheerio(element).find('a').attr('href');
|
||||||
if (!name || !url) return;
|
if (!name || !url) return;
|
||||||
@@ -109,12 +137,10 @@ class Jaomix implements Plugin.PluginBase {
|
|||||||
name,
|
name,
|
||||||
path: url.replace(this.site, ''),
|
path: url.replace(this.site, ''),
|
||||||
releaseTime: this.parseDate(releaseDate),
|
releaseTime: this.parseDate(releaseDate),
|
||||||
chapterNumber: totalChapters - chapterIndex,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
novel.chapters = chapters.reverse();
|
return chapters;
|
||||||
return novel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseChapter(chapterPath: string): Promise<string> {
|
async parseChapter(chapterPath: string): Promise<string> {
|
||||||
@@ -123,9 +149,8 @@ class Jaomix implements Plugin.PluginBase {
|
|||||||
);
|
);
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
|
|
||||||
loadedCheerio('div[class="adblock-service"]').remove();
|
loadedCheerio('.adblock-service, .lazyblock').remove();
|
||||||
const chapterText =
|
const chapterText = loadedCheerio('.entry-content').html() || '';
|
||||||
loadedCheerio('div[class="entry-content"]').html() || '';
|
|
||||||
|
|
||||||
return chapterText.replace(/<a[^>]*>(.*?)<\/a>/gi, '$1');
|
return chapterText.replace(/<a[^>]*>(.*?)<\/a>/gi, '$1');
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Reference in New Issue
Block a user