From ee126b20d88b367410c78638f9bdbcc93c79107f Mon Sep 17 00:00:00 2001 From: K1ngfish3r Date: Thu, 22 Aug 2024 22:53:59 +0800 Subject: [PATCH] RainofSnow: Manual Date Parse (#1160) * manual date parse * optimize regex * remove s spaces * superfast * even faster --- src/plugins/english/rainofsnow.ts | 38 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/plugins/english/rainofsnow.ts b/src/plugins/english/rainofsnow.ts index f99abd9..46b6443 100644 --- a/src/plugins/english/rainofsnow.ts +++ b/src/plugins/english/rainofsnow.ts @@ -9,7 +9,7 @@ class Rainofsnow implements Plugin.PagePlugin { name = 'Rainofsnow'; icon = 'src/en/rainofsnow/icon.png'; site = 'https://rainofsnow.com/'; - version = '1.1.0'; + version = '1.1.1'; parseNovels(loadedCheerio: CheerioAPI) { const novels: Plugin.NovelItem[] = []; @@ -97,18 +97,40 @@ class Rainofsnow implements Plugin.PagePlugin { const chapter: Plugin.ChapterItem[] = []; loadedCheerio('#chapter .march1 li').each((i, el) => { - const name = loadedCheerio(el).find('.chapter').first().text().trim(); - const releaseTime = new Date( - loadedCheerio(el).find('small').text().trim(), - ).toISOString(); const path = loadedCheerio(el) .find('a') .attr('href') ?.slice(this.site.length); + if (!path) return; + const name = loadedCheerio(el).find('.chapter').first().text().trim(); + const date = loadedCheerio(el).find('small').text().trim().toLowerCase(); + const months = [ + 'jan', + 'feb', + 'mar', + 'apr', + 'may', + 'jun', + 'jul', + 'aug', + 'sep', + 'oct', + 'nov', + 'dec', + ]; + const regex = /([a-z]+) (..?), (.+)/; + const [, monthName, day, year] = regex.exec(date) || []; + const month = months.indexOf(monthName.slice(0, 3)); + const releaseTime = + monthName && month !== -1 + ? new Date(+year, month, +day).toISOString() + : null; - if (path && name) { - chapter.push({ name, path, releaseTime }); - } + chapter.push({ + name, + path, + releaseTime, + }); }); return chapter;