style: Run Prettier

This commit is contained in:
Rajarshee Chatterjee
2022-04-24 17:39:48 +05:30
parent 2d85fa0938
commit 815172b91d
6 changed files with 97 additions and 53 deletions
+45 -27
View File
@@ -13,18 +13,24 @@ const popularNovels = async page => {
const loadedCheerio = cheerio.load(body);
let novels = [];
loadedCheerio('div[class="block-home"] > div[class="one"]').each(function() {
const novelName = loadedCheerio(this).find('div[class="img-home"] > a').attr('title');
const novelCover = loadedCheerio(this).find('div[class="img-home"] > a > img')
.attr('src').replace("-150x150", "");
const novelUrl = loadedCheerio(this).find('div[class="img-home"] > a').attr('href');
loadedCheerio('div[class="block-home"] > div[class="one"]').each(function () {
const novelName = loadedCheerio(this)
.find('div[class="img-home"] > a')
.attr('title');
const novelCover = loadedCheerio(this)
.find('div[class="img-home"] > a > img')
.attr('src')
.replace('-150x150', '');
const novelUrl = loadedCheerio(this)
.find('div[class="img-home"] > a')
.attr('href');
const novel = { sourceId, novelName, novelCover, novelUrl };
novels.push(novel);
});
return { totalPages, novels };
}
};
const parseNovelAndChapters = async novelUrl => {
const result = await fetch(novelUrl);
@@ -42,7 +48,7 @@ const parseNovelAndChapters = async novelUrl => {
novel.novelCover = loadedCheerio('div[class="img-book"] > img').attr('src');
novel.summary = loadedCheerio('div[id="desc-tab"]').text().trim();
const termid = loadedCheerio('div[class="like-but"]').attr('id')
const termid = loadedCheerio('div[class="like-but"]').attr('id');
const chapters = [];
let formData = new FormData();
@@ -51,15 +57,15 @@ const parseNovelAndChapters = async novelUrl => {
let doc = await fetch(baseUrl + '/wp-admin/admin-ajax.php', {
method: 'POST',
body: formData
body: formData,
});
let results2 = await doc.text()
let loadedCheerio2 = cheerio.load(results2)
let page = loadedCheerio2('option').length
let results2 = await doc.text();
let loadedCheerio2 = cheerio.load(results2);
let page = loadedCheerio2('option').length;
for (let i = 0; i < page; i++) {
if (i == 0) {
loadedCheerio2 = loadedCheerio
loadedCheerio2 = loadedCheerio;
} else {
formData = new FormData();
formData.append('action', 'toc');
@@ -67,16 +73,22 @@ const parseNovelAndChapters = async novelUrl => {
formData.append('termid', termid);
doc = await fetch(baseUrl + '/wp-admin/admin-ajax.php', {
method: 'POST',
body: formData
body: formData,
});
results2 = await doc.text()
loadedCheerio2 = cheerio.load(results2)
results2 = await doc.text();
loadedCheerio2 = cheerio.load(results2);
}
loadedCheerio2('div[class="hiddenstab active"] > div > div[class="flex-dow-txt"]').each(function() {
const chapterName = loadedCheerio2(this).find('div[class="title"] > a').attr("title")
loadedCheerio2(
'div[class="hiddenstab active"] > div > div[class="flex-dow-txt"]',
).each(function () {
const chapterName = loadedCheerio2(this)
.find('div[class="title"] > a')
.attr('title');
const releaseDate = loadedCheerio2(this).find('time').text();
const chapterUrl = loadedCheerio2(this).find('div[class="title"] > a').attr("href");
const chapterUrl = loadedCheerio2(this)
.find('div[class="title"] > a')
.attr('href');
chapters.push({ chapterName, releaseDate, chapterUrl });
});
@@ -91,13 +103,13 @@ const parseChapter = async (novelUrl, chapterUrl) => {
const body = await result.text();
const loadedCheerio = cheerio.load(body);
loadedCheerio('img').each(function() {
loadedCheerio('img').each(function () {
if (!loadedCheerio(this).attr('src')?.startsWith('http')) {
let src = loadedCheerio(this).attr('src');
loadedCheerio(this).attr('src', baseUrl + src);
}
})
loadedCheerio('div[class="adblock-service"]').remove()
});
loadedCheerio('div[class="adblock-service"]').remove();
const chapterName = loadedCheerio('h1[class="entry-title"]').html();
const chapterText = loadedCheerio('div[class="entry-content"]').html();
@@ -119,11 +131,17 @@ const searchNovels = async searchTerm => {
const loadedCheerio = cheerio.load(body);
let novels = [];
loadedCheerio('div[class="block-home"] > div[class="one"]').each(function() {
const novelName = loadedCheerio(this).find('div[class="img-home"] > a').attr('title');
const novelCover = loadedCheerio(this).find('div[class="img-home"] > a > img')
.attr('src').replace("-150x150", "");
const novelUrl = loadedCheerio(this).find('div[class="img-home"] > a').attr('href');
loadedCheerio('div[class="block-home"] > div[class="one"]').each(function () {
const novelName = loadedCheerio(this)
.find('div[class="img-home"] > a')
.attr('title');
const novelCover = loadedCheerio(this)
.find('div[class="img-home"] > a > img')
.attr('src')
.replace('-150x150', '');
const novelUrl = loadedCheerio(this)
.find('div[class="img-home"] > a')
.attr('href');
const novel = { sourceId, novelName, novelCover, novelUrl };
novels.push(novel);
@@ -137,4 +155,4 @@ const JaomixScraper = {
searchNovels,
};
export default JaomixScraper;
export default JaomixScraper;
+4 -2
View File
@@ -18,7 +18,8 @@ const popularNovels = async page => {
loadedCheerio('.media-card-wrap').each(function () {
const novelName = loadedCheerio(this).find('.media-card__title').text();
const novelCover = baseUrl + loadedCheerio(this).find('a.media-card').attr('data-src');
const novelCover =
baseUrl + loadedCheerio(this).find('a.media-card').attr('data-src');
const novelUrl = loadedCheerio(this).find('a.media-card').attr('href');
const novel = { sourceId, novelName, novelCover, novelUrl };
@@ -127,7 +128,8 @@ const searchNovels = async searchTerm => {
loadedCheerio('.media-card-wrap').each(function () {
const novelName = loadedCheerio(this).find('.media-card__title').text();
const novelCover = baseUrl + loadedCheerio(this).find('a.media-card').attr('data-src');
const novelCover =
baseUrl + loadedCheerio(this).find('a.media-card').attr('data-src');
const novelUrl = loadedCheerio(this).find('a.media-card').attr('href');
const novel = { sourceId, novelName, novelCover, novelUrl };
+6 -4
View File
@@ -47,11 +47,13 @@ const parseNovelAndChapters = async novelUrl => {
let chapters = [];
json.props.pageProps.book.chapters.map(item => {
const chapterName = item.title
const chapterName = item.title;
const releaseDate = item.publishedAt;
const chapterUrl = baseUrl + item.url;
if (!item.isDonate) chapters.push({ chapterName, releaseDate, chapterUrl });
if (!item.isDonate) {
chapters.push({ chapterName, releaseDate, chapterUrl });
}
});
novel.chapters = chapters.reverse();
@@ -66,10 +68,10 @@ const parseChapter = async (novelUrl, chapterUrl) => {
let json = loadedCheerio('#__NEXT_DATA__').html();
json = JSON.parse(json);
const chapterName = json.props.pageProps.chapter.title
const chapterName = json.props.pageProps.chapter.title;
let temp = cheerio.load(json.props.pageProps.chapter.content.text);
temp('img').each(function() {
temp('img').each(function () {
if (!loadedCheerio(this).attr('src')?.startsWith('http')) {
let src = loadedCheerio(this).attr('src');
loadedCheerio(this).attr('src', baseUrl + src);
+13 -6
View File
@@ -33,17 +33,21 @@ const parseNovelAndChapters = async novelUrl => {
sourceName,
url: baseUrl + 'novel/' + body.content.dir,
novelName: body.content.rus_name,
novelCover: 'https://api.renovels.org' + body.content.img?.high || body.content.img?.low,
novelCover:
'https://api.renovels.org' + body.content.img?.high ||
body.content.img?.low,
summary: htmlToText(body.content.description),
novelUrl,
};
let all = (body.content.count_chapters / 100 + 1) ^ 0
let all = (body.content.count_chapters / 100 + 1) ^ 0;
let chapters = [];
for (let i = 0; i < all; i++) {
let chapterResult = await fetch(
`https://api.renovels.org/api/titles/chapters/?branch_id=${body.content.branches[0].id}&count=100&page=${i + 1}`,
`https://api.renovels.org/api/titles/chapters/?branch_id=${
body.content.branches[0].id
}&count=100&page=${i + 1}`,
);
let volumes = await chapterResult.json();
@@ -51,9 +55,12 @@ const parseNovelAndChapters = async novelUrl => {
const chapterName =
`Том ${item.tome} Глава ${item.chapter} ${item.name}`?.trim();
const releaseDate = item.upload_date;
const chapterUrl = 'https://api.renovels.org/api/titles/chapters/' + item.id + '/';
const chapterUrl =
'https://api.renovels.org/api/titles/chapters/' + item.id + '/';
if (!item.is_paid) chapters.push({ chapterName, releaseDate, chapterUrl });
if (!item.is_paid) {
chapters.push({ chapterName, releaseDate, chapterUrl });
}
});
}
@@ -100,4 +107,4 @@ const RenovelsScraper = {
searchNovels,
};
export default RenovelsScraper;
export default RenovelsScraper;
+28 -13
View File
@@ -13,9 +13,10 @@ const popularNovels = async page => {
const loadedCheerio = cheerio.load(body);
let novels = [];
loadedCheerio('.imged > li').each(function() {
loadedCheerio('.imged > li').each(function () {
const novelName = loadedCheerio(this).find('p > a').text();
const novelCover = baseUrl + loadedCheerio(this).find('div').attr('style').split("'")[1];
const novelCover =
baseUrl + loadedCheerio(this).find('div').attr('style').split("'")[1];
const novelUrl = loadedCheerio(this).find('p > a').attr('href');
const novel = { sourceId, novelName, novelCover, novelUrl };
@@ -37,15 +38,23 @@ const parseNovelAndChapters = async novelUrl => {
novelUrl,
};
novel.novelName = loadedCheerio('div[class="container"] > div > div > h1').text().trim();
novel.novelCover = baseUrl + loadedCheerio('div[class="images"] > div img').attr('src');
novel.novelName = loadedCheerio('div[class="container"] > div > div > h1')
.text()
.trim();
novel.novelCover =
baseUrl + loadedCheerio('div[class="images"] > div img').attr('src');
novel.summary = loadedCheerio('#Info > div:nth-child(3)').text().trim();
let chapters = [];
loadedCheerio('table > tbody > tr.chapter_row').each(function() {
const chapterName = loadedCheerio(this).find('td[class="t"] > a').text().trim()
const releaseDate = null
const chapterUrl = loadedCheerio(this).find('td[class="t"] > a').attr("href");
loadedCheerio('table > tbody > tr.chapter_row').each(function () {
const chapterName = loadedCheerio(this)
.find('td[class="t"] > a')
.text()
.trim();
const releaseDate = null;
const chapterUrl = loadedCheerio(this)
.find('td[class="t"] > a')
.attr('href');
if (loadedCheerio(this).find('td > span[class="disabled"]').length < 1) {
chapters.push({ chapterName, releaseDate, chapterUrl });
@@ -61,14 +70,18 @@ const parseChapter = async (novelUrl, chapterUrl) => {
const body = await result.text();
const loadedCheerio = cheerio.load(body);
loadedCheerio('.content-text img').each(function() {
loadedCheerio('.content-text img').each(function () {
if (!loadedCheerio(this).attr('src')?.startsWith('http')) {
const src = loadedCheerio(this).attr('src');
loadedCheerio(this).attr('src', baseUrl + src);
}
});
const chapterName = loadedCheerio('.chapter_select > select > option[selected]').text().trim();
const chapterName = loadedCheerio(
'.chapter_select > select > option[selected]',
)
.text()
.trim();
const chapterText = loadedCheerio('.content-text').html();
const chapter = {
@@ -83,9 +96,11 @@ const parseChapter = async (novelUrl, chapterUrl) => {
};
const searchNovels = async searchTerm => {
const result = await fetch(baseUrl + '/search/autocomplete?query=' + searchTerm);
const result = await fetch(
baseUrl + '/search/autocomplete?query=' + searchTerm,
);
let json = await result.json();
let novels = []
let novels = [];
json.map(item => {
const novelName = item.title_one + ' / ' + item.title_two;
@@ -105,4 +120,4 @@ const RulateLibScraper = {
searchNovels,
};
export default RulateLibScraper;
export default RulateLibScraper;
+1 -1
View File
@@ -255,4 +255,4 @@ export const sourceManager = (sourceId: number): Scraper => {
};
return scrapers[sourceId];
};
};