rsshub
Version:
Make RSS Great Again!
57 lines (55 loc) • 2.52 kB
JavaScript
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { load } from "cheerio";
//#region lib/routes/gamersky/utils.ts
const getArticleList = async (nodeId) => {
return (await ofetch_default(`https://db2.gamersky.com/LabelJsonpAjax.aspx?${new URLSearchParams({ jsondata: JSON.stringify({
type: "updatenodelabel",
isCache: true,
cacheTime: 60,
nodeId,
isNodeId: "true",
page: 1
}) })}`, { parseResponse: (txt) => JSON.parse(txt.match(/\((.+)\);/)?.[1] ?? "{}") })).body;
};
const parseArticleList = (response) => {
const $ = load(response);
return $("li").toArray().map((item) => {
const ele = $(item);
const a = ele.find(".tt").length ? ele.find(".tt") : ele.find("a");
const title = a.text();
const link = a.attr("href");
const pubDate = timezone(parseDate(ele.find(".time").text()), 8);
const description = ele.find(".txt").text();
if (!link) return;
return {
title,
link,
pubDate,
description
};
}).filter((item) => item !== void 0);
};
const getArticle = (item) => cache_default.tryGet(item.link, async () => {
const content = load(await ofetch_default(item.link))(".Mid2L_con, .MidLcon");
content.find(".appGameBuyCardIframe, .GSAppButton, .Mid2L_down").remove();
content.find("a").each((_, item$1) => {
if (item$1.attribs.href?.startsWith("https://www.gamersky.com/showimage/id_gamersky.shtml?")) item$1.attribs.href = item$1.attribs.href.replace("https://www.gamersky.com/showimage/id_gamersky.shtml?", "");
});
content.find("img").each((_, item$1) => {
if (item$1.attribs.src === "http://image.gamersky.com/webimg13/zhuanti/common/blank.png") item$1.attribs.src = item$1.attribs["data-origin"];
else if (item$1.attribs.src.endsWith("_S.jpg")) item$1.attribs.src = item$1.attribs.src.replace("_S.jpg", ".jpg");
});
content.find(".Slides li").each((_, item$1) => {
if (item$1.attribs.style === "display: none;") item$1.attribs.style = "display: list-item;";
});
item.description = content.html() || item.description;
return item;
});
function mdTableBuilder(data) {
return "|" + data.map((item) => `${item.type}|`).join("") + "\n|" + Array.from({ length: data.length }).fill("---|").join("") + "\n|" + data.map((item) => `${item.name}|`).join("") + "\n";
}
//#endregion
export { parseArticleList as i, getArticleList as n, mdTableBuilder as r, getArticle as t };