* add prettier

* lint-staged

* prettier

* upgrade husky
This commit is contained in:
nyagami
2024-03-23 22:00:29 +07:00
committed by GitHub
parent c22979b10f
commit 5f9a067ab9
113 changed files with 79244 additions and 50841 deletions
+26 -25
View File
@@ -1,36 +1,37 @@
import { FilterTypes, Filters } from "../../../libs/filterInputs";
import { ScrpitGeneratorFunction } from "../generate";
import list from "./sources.json";
import { MadaraMetadata } from "./template";
import { readFileSync } from "fs";
import path from "path";
import { FilterTypes, Filters } from '../../../libs/filterInputs';
import { ScrpitGeneratorFunction } from '../generate';
import list from './sources.json';
import { MadaraMetadata } from './template';
import { readFileSync } from 'fs';
import path from 'path';
export const generateAll: ScrpitGeneratorFunction = function (name) {
return list.map((metadata: MadaraMetadata) => {
let filters: any = {};
try {
filters = require(`./filters/${metadata.id}`);
metadata.filters = filters.filters;
}
catch (e) {}
console.log(`[${name}] Generating: ${metadata.id}${" ".repeat(20 - metadata.id.length)} ${metadata.filters ? "🔎with filters🔍" : "🚫no filters🚫"}`);
return generator(metadata);
});
return list.map((metadata: MadaraMetadata) => {
let filters: any = {};
try {
filters = require(`./filters/${metadata.id}`);
metadata.filters = filters.filters;
} catch (e) {}
console.log(
`[${name}] Generating: ${metadata.id}${' '.repeat(20 - metadata.id.length)} ${metadata.filters ? '🔎with filters🔍' : '🚫no filters🚫'}`,
);
return generator(metadata);
});
};
const generator = function generator(metadata: MadaraMetadata) {
const madaraTemplate = readFileSync(path.join(__dirname, "template.ts"), {
encoding: "utf-8",
});
const madaraTemplate = readFileSync(path.join(__dirname, 'template.ts'), {
encoding: 'utf-8',
});
const pluginScript = `
const pluginScript = `
${madaraTemplate}
const plugin = new MadaraPlugin(${JSON.stringify(metadata)});
export default plugin;
`.trim();
return {
lang: metadata.options?.lang || "English",
filename: metadata.sourceName,
pluginScript,
};
return {
lang: metadata.options?.lang || 'English',
filename: metadata.sourceName,
pluginScript,
};
};
+185 -154
View File
@@ -3,177 +3,208 @@ import * as cheerio from 'cheerio';
import * as path from 'path';
function getFilters(name: string, html: string) {
const $:cheerio.CheerioAPI = cheerio.load(html);
const filters: any = {filters: {
"genre[]": {
type: "Checkbox",
label: "Genre",
value: [],
options: []
},
"op": {
type: "Switch",
label: "Having ALL selected genres",
value: false
},
"author": {
type: "Text",
label: "Author",
value: ""
},
"artist": {
type: "Text",
label: "Artist",
value: ""
},
"release": {
type: "Text",
label: "Year of Released",
value: ""
},
"adult": {
type: "Picker",
label: "Adult content",
value: "",
options: [],
},
"status[]": {
type: "Checkbox",
label: "Status",
value: [],
options: []
},
"m_orderby": {
type: "Picker",
label: "Order by",
value: "",
options: []
},
}};
const $: cheerio.CheerioAPI = cheerio.load(html);
const filters: any = {
filters: {
'genre[]': {
type: 'Checkbox',
label: 'Genre',
value: [],
options: [],
},
'op': {
type: 'Switch',
label: 'Having ALL selected genres',
value: false,
},
'author': {
type: 'Text',
label: 'Author',
value: '',
},
'artist': {
type: 'Text',
label: 'Artist',
value: '',
},
'release': {
type: 'Text',
label: 'Year of Released',
value: '',
},
'adult': {
type: 'Picker',
label: 'Adult content',
value: '',
options: [],
},
'status[]': {
type: 'Checkbox',
label: 'Status',
value: [],
options: [],
},
'm_orderby': {
type: 'Picker',
label: 'Order by',
value: '',
options: [],
},
},
};
const divs = $("form.search-advanced-form > div");
const divs = $('form.search-advanced-form > div');
// ==================== Genre ====================
const genreDiv = divs.eq(0);
genreDiv.find("label").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr("for") || "")
};
filters.filters["genre[]"].options.push(option);
});
// ==================== Genre ====================
const genreDiv = divs.eq(0);
genreDiv.find('label').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr('for') || ''),
};
filters.filters['genre[]'].options.push(option);
});
// ===================== Op ======================
const statusDiv = divs.eq(1);
filters.filters["op"].label = statusDiv.find("option").eq(1)
.text().replace("AND", "").replace("(", "").replace(")", "").trim();
// ===================== Op ======================
const statusDiv = divs.eq(1);
filters.filters['op'].label = statusDiv
.find('option')
.eq(1)
.text()
.replace('AND', '')
.replace('(', '')
.replace(')', '')
.trim();
// ==================== Author ====================
const authorDiv = divs.eq(2);
filters.filters["author"].label = authorDiv.find("span").text().trim();
// ==================== Author ====================
const authorDiv = divs.eq(2);
filters.filters['author'].label = authorDiv.find('span').text().trim();
// ==================== Artist ====================
const artistDiv = divs.eq(3);
filters.filters["artist"].label = artistDiv.find("span").text().trim();
// ==================== Artist ====================
const artistDiv = divs.eq(3);
filters.filters['artist'].label = artistDiv.find('span').text().trim();
// ==================== Release ====================
const releaseDiv = divs.eq(4);
filters.filters["release"].label = releaseDiv.find("span").text().trim();
// ==================== Release ====================
const releaseDiv = divs.eq(4);
filters.filters['release'].label = releaseDiv.find('span').text().trim();
// ==================== Adult ====================
const adultDiv = divs.eq(5);
filters.filters["adult"].label = adultDiv.find("span").text().trim();
adultDiv.find("option").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr("value") || "")
};
filters.filters["adult"].options.push(option);
});
// ==================== Adult ====================
const adultDiv = divs.eq(5);
filters.filters['adult'].label = adultDiv.find('span').text().trim();
adultDiv.find('option').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI($(el).attr('value') || ''),
};
filters.filters['adult'].options.push(option);
});
// ==================== Status ====================
const statusDiv2 = divs.eq(6);
filters.filters["status[]"].label = statusDiv2.find("span").text().trim();
statusDiv2.find("label").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: $(el).attr("for")
};
filters.filters["status[]"].options.push(option);
});
// ==================== Status ====================
const statusDiv2 = divs.eq(6);
filters.filters['status[]'].label = statusDiv2.find('span').text().trim();
statusDiv2.find('label').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: $(el).attr('for'),
};
filters.filters['status[]'].options.push(option);
});
// ==================== Order by ====================
const orderByDiv = $("div.c-nav-tabs").eq(0);
filters.filters["m_orderby"].label = orderByDiv.find("span").text().trim();
orderByDiv.find("a").each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI(($(el).attr("href")?.split("=").length == 3 ? $(el).attr("href")?.split("=")[2] : "") || "")
};
filters.filters["m_orderby"].options.push(option);
});
// ==================== Order by ====================
const orderByDiv = $('div.c-nav-tabs').eq(0);
filters.filters['m_orderby'].label = orderByDiv.find('span').text().trim();
orderByDiv.find('a').each((i, el) => {
const option = {
label: $(el).text().trim(),
value: decodeURI(
($(el).attr('href')?.split('=').length == 3
? $(el).attr('href')?.split('=')[2]
: '') || '',
),
};
filters.filters['m_orderby'].options.push(option);
});
if (filters.filters["m_orderby"].options.length == 0 ||
filters.filters["status[]"].options.length == 0 ||
filters.filters["adult"].options.length == 0 ||
filters.filters["genre[]"].options.length == 0) {
console.error(`🚨Error in filters for ${name} please fix manually (${path.join(__dirname, 'filters', name + ".json")})🚨`);
}
if (
filters.filters['m_orderby'].options.length == 0 ||
filters.filters['status[]'].options.length == 0 ||
filters.filters['adult'].options.length == 0 ||
filters.filters['genre[]'].options.length == 0
) {
console.error(
`🚨Error in filters for ${name} please fix manually (${path.join(__dirname, 'filters', name + '.json')})🚨`,
);
}
fs.writeFileSync(
path.join(__dirname, 'filters', name + ".json"),
JSON.stringify(filters, null, 2)
);
console.log(`✅Filters created successfully for ${name}✅`);
fs.writeFileSync(
path.join(__dirname, 'filters', name + '.json'),
JSON.stringify(filters, null, 2),
);
console.log(`✅Filters created successfully for ${name}✅`);
}
async function getFiltersFromURL(name: string, url: string) {
const response = await fetch(url + "/?s=&post_type=wp-manga");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}, while fetching ${response.url}`);
}
const html = await response.text();
try {
getFilters(name, html);
} catch (e) {
console.error("Error while getting filters from", url);
}
const response = await fetch(url + '/?s=&post_type=wp-manga');
if (!response.ok) {
throw new Error(
`HTTP error! status: ${response.status}, while fetching ${response.url}`,
);
}
const html = await response.text();
try {
getFilters(name, html);
} catch (e) {
console.error('Error while getting filters from', url);
}
}
async function askGetFilter() {
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
async function askGetFilter(){
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const EREASE_PREV_LINE = '\x1b[1A\r\x1b[2K';
await readline.question('Enter the id of the site (same one as in sources.json): ', async (name: string) => {
await readline.question(EREASE_PREV_LINE + 'Do you want to get the filters from a URL or the html text? (if url dosen\'t work try html) (url/html): ', async (method: string) => {
if (method.toLowerCase() === "url") {
await readline.question(EREASE_PREV_LINE + 'Enter the URL (same one as in sources.json): ', async (url: string) => {
try {
await getFiltersFromURL(name, url);
} catch (e: any) {
console.error("Error while getting filters from", url);
console.log(e.message || e);
}
readline.close();
});
} else {
process.stdout.write(EREASE_PREV_LINE + `Enter the html text from the page at {sourceSite}/?s=&post_type=wp-manga (at the end press ENTER then press CTRL+C): `)
let html = "";
readline.on('SIGINT', () => {
console.log("Stopeed reading input, creating filters file");
getFilters(name, html);
readline.close();
});
readline.on('line', (line: string) => {
html += line + "\n";
});
}
});
});
const EREASE_PREV_LINE = '\x1b[1A\r\x1b[2K';
await readline.question(
'Enter the id of the site (same one as in sources.json): ',
async (name: string) => {
await readline.question(
EREASE_PREV_LINE +
"Do you want to get the filters from a URL or the html text? (if url dosen't work try html) (url/html): ",
async (method: string) => {
if (method.toLowerCase() === 'url') {
await readline.question(
EREASE_PREV_LINE +
'Enter the URL (same one as in sources.json): ',
async (url: string) => {
try {
await getFiltersFromURL(name, url);
} catch (e: any) {
console.error('Error while getting filters from', url);
console.log(e.message || e);
}
readline.close();
},
);
} else {
process.stdout.write(
EREASE_PREV_LINE +
`Enter the html text from the page at {sourceSite}/?s=&post_type=wp-manga (at the end press ENTER then press CTRL+C): `,
);
let html = '';
readline.on('SIGINT', () => {
console.log('Stopeed reading input, creating filters file');
getFilters(name, html);
readline.close();
});
readline.on('line', (line: string) => {
html += line + '\n';
});
}
},
);
},
);
}
askGetFilter();
+161 -129
View File
@@ -1,13 +1,13 @@
import { fetchApi, fetchFile } from "@libs/fetch";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { CheerioAPI, load as parseHTML } from "cheerio";
import { defaultCover } from "@libs/defaultCover";
import { NovelStatus } from "@libs/novelStatus";
import dayjs from "dayjs";
import { fetchApi, fetchFile } from '@libs/fetch';
import { Filters, FilterTypes } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
import { CheerioAPI, load as parseHTML } from 'cheerio';
import { defaultCover } from '@libs/defaultCover';
import { NovelStatus } from '@libs/novelStatus';
import dayjs from 'dayjs';
const includesAny = (str: string, keywords: string[]) =>
new RegExp(keywords.join("|")).test(str);
new RegExp(keywords.join('|')).test(str);
interface MadaraOptions {
useNewChapterEndpoint?: boolean;
@@ -45,157 +45,178 @@ class MadaraPlugin implements Plugin.PluginBase {
}
getHostname(url: string): string {
return url.split("/")[2];
return url.split('/')[2];
}
async getCheerio(url: string): Promise<CheerioAPI> {
const r = await fetchApi(url);
if (!r.ok) throw new Error("Could not reach site (" + r.status + ") try to open in webview.");
if (!r.ok)
throw new Error(
'Could not reach site (' + r.status + ') try to open in webview.',
);
const $ = parseHTML(await r.text());
const title = $("title").text().trim();
if (this.getHostname(url) != this.getHostname(r.url) ||
title == "Bot Verification" || title == "You are being redirected..." || title == "Un instant..." || title == "Just a moment..." || title == "Redirecting...")
throw new Error("Captcha error, please open in webview");
return ($);
const title = $('title').text().trim();
if (
this.getHostname(url) != this.getHostname(r.url) ||
title == 'Bot Verification' ||
title == 'You are being redirected...' ||
title == 'Un instant...' ||
title == 'Just a moment...' ||
title == 'Redirecting...'
)
throw new Error('Captcha error, please open in webview');
return $;
}
parseNovels(loadedCheerio: CheerioAPI): Plugin.NovelItem[] {
const novels: Plugin.NovelItem[] = [];
loadedCheerio(".manga-title-badges").remove();
loadedCheerio(".page-item-detail, .c-tabs-item__content").each((index, element) => {
const novelName = loadedCheerio(element).find(".post-title").text().trim();
const novelUrl = loadedCheerio(element).find(".post-title").find("a").attr("href") || "";
if (!novelName || !novelUrl) return;
const image = loadedCheerio(element).find("img");
const novelCover = image.attr("data-src") || image.attr("src");
const novel: Plugin.NovelItem = {
name: novelName,
cover: novelCover,
path: novelUrl.replace(this.site, ""),
};
novels.push(novel);
});
loadedCheerio('.manga-title-badges').remove();
loadedCheerio('.page-item-detail, .c-tabs-item__content').each(
(index, element) => {
const novelName = loadedCheerio(element)
.find('.post-title')
.text()
.trim();
const novelUrl =
loadedCheerio(element).find('.post-title').find('a').attr('href') ||
'';
if (!novelName || !novelUrl) return;
const image = loadedCheerio(element).find('img');
const novelCover = image.attr('data-src') || image.attr('src');
const novel: Plugin.NovelItem = {
name: novelName,
cover: novelCover,
path: novelUrl.replace(this.site, ''),
};
novels.push(novel);
},
);
return novels;
}
async popularNovels(pageNo: number,{ filters, showLatestNovels }: Plugin.PopularNovelsOptions<typeof this.filters>): Promise<Plugin.NovelItem[]> {
let url = this.site + "/page/" + pageNo + "/?s=&post_type=wp-manga";
async popularNovels(
pageNo: number,
{
filters,
showLatestNovels,
}: Plugin.PopularNovelsOptions<typeof this.filters>,
): Promise<Plugin.NovelItem[]> {
let url = this.site + '/page/' + pageNo + '/?s=&post_type=wp-manga';
if (!filters) filters = {};
if (showLatestNovels) url += "&m_orderby=latest";
if (showLatestNovels) url += '&m_orderby=latest';
for (const key in filters) {
if (typeof filters[key].value === "object")
if (typeof filters[key].value === 'object')
for (const value of filters[key].value as string[])
url += `&${key}=${value}`;
else if (filters[key].value)
url += `&${key}=${filters[key].value}`;
else if (filters[key].value) url += `&${key}=${filters[key].value}`;
}
const loadedCheerio = await this.getCheerio(url);
return this.parseNovels(loadedCheerio);
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(this.site + novelPath).then((res) => res.text());
const body = await fetchApi(this.site + novelPath).then(res => res.text());
let loadedCheerio = parseHTML(body);
loadedCheerio(".manga-title-badges, #manga-title span").remove();
loadedCheerio('.manga-title-badges, #manga-title span').remove();
const novel: Plugin.SourceNovel = {
path: novelPath,
name:
loadedCheerio(".post-title h1").text().trim() ||
loadedCheerio("#manga-title h1").text(),
loadedCheerio('.post-title h1').text().trim() ||
loadedCheerio('#manga-title h1').text(),
};
novel.cover =
loadedCheerio(".summary_image > a > img").attr("data-lazy-src") ||
loadedCheerio(".summary_image > a > img").attr("data-src") ||
loadedCheerio(".summary_image > a > img").attr("src") ||
loadedCheerio(".summary_image > a > img").attr("src") ||
loadedCheerio('.summary_image > a > img').attr('data-lazy-src') ||
loadedCheerio('.summary_image > a > img').attr('data-src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
loadedCheerio('.summary_image > a > img').attr('src') ||
defaultCover;
loadedCheerio(".post-content_item, .post-content").each(function () {
const detailName = loadedCheerio(this).find("h5").text().trim();
const detail = loadedCheerio(this).find(".summary-content").text().trim();
loadedCheerio('.post-content_item, .post-content').each(function () {
const detailName = loadedCheerio(this).find('h5').text().trim();
const detail = loadedCheerio(this).find('.summary-content').text().trim();
switch (detailName) {
case "Genre(s)":
case "Género(s)":
case "التصنيفات":
case 'Genre(s)':
case 'Género(s)':
case 'التصنيفات':
novel.genres = detail;
break;
case "Author(s)":
case "Autor(es)":
case "المؤلف":
case "المؤلف (ين)":
case 'Author(s)':
case 'Autor(es)':
case 'المؤلف':
case 'المؤلف (ين)':
novel.author = detail;
break;
case "Status":
case "Estado":
case 'Status':
case 'Estado':
novel.status =
detail.includes("OnGoing") || detail.includes("مستمرة")
detail.includes('OnGoing') || detail.includes('مستمرة')
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
}
});
loadedCheerio("div.summary__content .code-block,script").remove();
loadedCheerio('div.summary__content .code-block,script').remove();
novel.summary =
loadedCheerio("div.summary__content").text().trim() ||
loadedCheerio("#tab-manga-about").text().trim() ||
loadedCheerio('div.summary__content').text().trim() ||
loadedCheerio('#tab-manga-about').text().trim() ||
loadedCheerio('.post-content_item h5:contains("Summary")')
.next()
.text()
.trim();
const chapters: Plugin.ChapterItem[] = [];
let html = "";
let html = '';
if (this.options?.useNewChapterEndpoint) {
html = await fetchApi(this.site + novelPath + "ajax/chapters/", {
method: "POST",
}).then((res) => res.text());
html = await fetchApi(this.site + novelPath + 'ajax/chapters/', {
method: 'POST',
}).then(res => res.text());
} else {
const novelId =
loadedCheerio(".rating-post-id").attr("value") ||
loadedCheerio("#manga-chapters-holder").attr("data-id") ||
"";
loadedCheerio('.rating-post-id').attr('value') ||
loadedCheerio('#manga-chapters-holder').attr('data-id') ||
'';
const formData = new FormData();
formData.append("action", "manga_get_chapters");
formData.append("manga", novelId);
formData.append('action', 'manga_get_chapters');
formData.append('manga', novelId);
html = await fetchApi(this.site + "wp-admin/admin-ajax.php", {
method: "POST",
html = await fetchApi(this.site + 'wp-admin/admin-ajax.php', {
method: 'POST',
body: formData,
}).then((res) => res.text());
}).then(res => res.text());
}
if (html !== "0") {
if (html !== '0') {
loadedCheerio = parseHTML(html);
}
const totalChapters = loadedCheerio(".wp-manga-chapter").length;
loadedCheerio(".wp-manga-chapter").each((chapterIndex, element) => {
const chapterName = loadedCheerio(element).find("a").text().trim();
const totalChapters = loadedCheerio('.wp-manga-chapter').length;
loadedCheerio('.wp-manga-chapter').each((chapterIndex, element) => {
const chapterName = loadedCheerio(element).find('a').text().trim();
let releaseDate = loadedCheerio(element)
.find("span.chapter-release-date")
.find('span.chapter-release-date')
.text()
.trim();
if (releaseDate) {
releaseDate = this.parseData(releaseDate);
} else {
releaseDate = dayjs().format("LL");
releaseDate = dayjs().format('LL');
}
let chapterUrl = loadedCheerio(element).find("a").attr("href") || "";
let chapterUrl = loadedCheerio(element).find('a').attr('href') || '';
chapters.push({
name: chapterName,
path: chapterUrl.replace(this.site, ""),
path: chapterUrl.replace(this.site, ''),
releaseTime: releaseDate || null,
chapterNumber: totalChapters - chapterIndex,
});
@@ -206,21 +227,32 @@ class MadaraPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
const chapterText =
loadedCheerio(".text-left").html() ||
loadedCheerio(".text-right").html() ||
loadedCheerio(".entry-content").html() ||
loadedCheerio(".c-blog-post > div > div:nth-child(2)").html() ||
"";
loadedCheerio('.text-left').html() ||
loadedCheerio('.text-right').html() ||
loadedCheerio('.entry-content').html() ||
loadedCheerio('.c-blog-post > div > div:nth-child(2)').html() ||
'';
return chapterText;
}
async searchNovels(searchTerm: string, pageNo?: number | undefined): Promise<Plugin.NovelItem[]> {
const url = this.site + "page/" + pageNo + "/?s=" + searchTerm + "&post_type=wp-manga";
async searchNovels(
searchTerm: string,
pageNo?: number | undefined,
): Promise<Plugin.NovelItem[]> {
const url =
this.site +
'page/' +
pageNo +
'/?s=' +
searchTerm +
'&post_type=wp-manga';
const loadedCheerio = await this.getCheerio(url);
return this.parseNovels(loadedCheerio);
}
@@ -229,66 +261,66 @@ class MadaraPlugin implements Plugin.PluginBase {
parseData = (date: string) => {
const dayJSDate = dayjs(); // today
const timeAgo = date.match(/\d+/)?.[0] || "";
const timeAgo = date.match(/\d+/)?.[0] || '';
const timeAgoInt = parseInt(timeAgo, 10);
if (!timeAgo) return date; // there is no number!
if (includesAny(date, ["detik", "segundo", "second", "วินาที"])) {
dayJSDate.subtract(timeAgoInt, "second"); // go back N seconds
if (includesAny(date, ['detik', 'segundo', 'second', 'วินาที'])) {
dayJSDate.subtract(timeAgoInt, 'second'); // go back N seconds
} else if (
includesAny(date, [
"menit",
"dakika",
"min",
"minute",
"minuto",
"นาที",
"دقائق",
'menit',
'dakika',
'min',
'minute',
'minuto',
'นาที',
'دقائق',
])
) {
dayJSDate.subtract(timeAgoInt, "minute"); // go back N minute
dayJSDate.subtract(timeAgoInt, 'minute'); // go back N minute
} else if (
includesAny(date, [
"jam",
"saat",
"heure",
"hora",
"hour",
"ชั่วโมง",
"giờ",
"ore",
"ساعة",
"小时",
'jam',
'saat',
'heure',
'hora',
'hour',
'ชั่วโมง',
'giờ',
'ore',
'ساعة',
'小时',
])
) {
dayJSDate.subtract(timeAgoInt, "hours"); // go back N hours
dayJSDate.subtract(timeAgoInt, 'hours'); // go back N hours
} else if (
includesAny(date, [
"hari",
"gün",
"jour",
"día",
"dia",
"day",
"วัน",
"ngày",
"giorni",
"أيام",
"天",
'hari',
'gün',
'jour',
'día',
'dia',
'day',
'วัน',
'ngày',
'giorni',
'أيام',
'天',
])
) {
dayJSDate.subtract(timeAgoInt, "days"); // go back N days
} else if (includesAny(date, ["week", "semana"])) {
dayJSDate.subtract(timeAgoInt, "week"); // go back N a week
} else if (includesAny(date, ["month", "mes"])) {
dayJSDate.subtract(timeAgoInt, "month"); // go back N months
} else if (includesAny(date, ["year", "año"])) {
dayJSDate.subtract(timeAgoInt, "year"); // go back N years
dayJSDate.subtract(timeAgoInt, 'days'); // go back N days
} else if (includesAny(date, ['week', 'semana'])) {
dayJSDate.subtract(timeAgoInt, 'week'); // go back N a week
} else if (includesAny(date, ['month', 'mes'])) {
dayJSDate.subtract(timeAgoInt, 'month'); // go back N months
} else if (includesAny(date, ['year', 'año'])) {
dayJSDate.subtract(timeAgoInt, 'year'); // go back N years
} else {
return date;
}
return dayJSDate.format("LL");
return dayJSDate.format('LL');
};
}