update zaimanhua and ikmmh (#127)

* 显示收藏状态

* 新增 再漫画

#48

* 更新 ikmmh.js

* 更新 zaimanhua.js

* Update index.json
This commit is contained in:
lost one
2025-08-16 18:51:42 +08:00
committed by GitHub
parent 65bb0d244d
commit 714353cf64
3 changed files with 877 additions and 817 deletions

View File

@@ -2,7 +2,7 @@ class Ikm extends ComicSource {
// 基础配置 // 基础配置
name = "爱看漫"; name = "爱看漫";
key = "ikmmh"; key = "ikmmh";
version = "1.0.3"; version = "1.0.4";
minAppVersion = "1.0.0"; minAppVersion = "1.0.0";
url = "https://git.nyne.dev/nyne/venera-configs/raw/branch/main/ikmmh.js"; url = "https://git.nyne.dev/nyne/venera-configs/raw/branch/main/ikmmh.js";
// 常量定义 // 常量定义
@@ -10,13 +10,13 @@ class Ikm extends ComicSource {
static Mobile_UA = "Mozilla/5.0 (Linux; Android) Mobile"; static Mobile_UA = "Mozilla/5.0 (Linux; Android) Mobile";
static webHeaders = { static webHeaders = {
"User-Agent": Ikm.Mobile_UA, "User-Agent": Ikm.Mobile_UA,
Accept: "Accept":
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
}; };
static jsonHead = { static jsonHead = {
"User-Agent": Ikm.Mobile_UA, "User-Agent": Ikm.Mobile_UA,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
Accept: "application/json, text/javascript, */*; q=0.01", "Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip", "Accept-Encoding": "gzip",
"X-Requested-With": "XMLHttpRequest", "X-Requested-With": "XMLHttpRequest",
}; };
@@ -24,7 +24,7 @@ class Ikm extends ComicSource {
static thumbConfig = (url) => ({ static thumbConfig = (url) => ({
headers: { headers: {
...Ikm.webHeaders, ...Ikm.webHeaders,
Referer: Ikm.baseUrl, "referer": Ikm.baseUrl,
}, },
}); });
// 账号系统 // 账号系统
@@ -72,10 +72,10 @@ class Ikm extends ComicSource {
}; };
}; };
return { return {
本周推荐: document "本周推荐": document
.querySelectorAll("div.module-good-fir > div.item") .querySelectorAll("div.module-good-fir > div.item")
.map(parseComic), .map(parseComic),
今日更新: document "今日更新": document
.querySelectorAll("div.module-day-fir > div.item") .querySelectorAll("div.module-day-fir > div.item")
.map(parseComic), .map(parseComic),
}; };
@@ -90,6 +90,21 @@ class Ikm extends ComicSource {
category = { category = {
title: "爱看漫", title: "爱看漫",
parts: [ parts: [
{
name: "更新",
type: "fixed",
categories: [
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期日",
],
itemType: "category",
categoryParams: ["1", "2", "3", "4", "5", "6", "7"],
},
{ {
name: "分类", name: "分类",
// fixed 或者 random // fixed 或者 random
@@ -139,38 +154,13 @@ class Ikm extends ComicSource {
"历史", "历史",
"战争", "战争",
"恐怖", "恐怖",
"霸总", "霸总"
"全部",
"连载中",
"已完结",
"全部",
"日漫",
"港台",
"美漫",
"国漫",
"韩漫",
"未分类",
], ],
// category或者search // category或者search
// 如果为category, 点击后将进入分类漫画页面, 使用下方的`categoryComics`加载漫画 // 如果为category, 点击后将进入分类漫画页面, 使用下方的`categoryComics`加载漫画
// 如果为search, 将进入搜索页面 // 如果为search, 将进入搜索页面
itemType: "category", itemType: "category",
}, }
{
name: "更新",
type: "fixed",
categories: [
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期日",
],
itemType: "category",
categoryParams: ["1", "2", "3", "4", "5", "6", "7"],
},
], ],
enableRankingPage: false, enableRankingPage: false,
}; };
@@ -195,7 +185,7 @@ class Ikm extends ComicSource {
})); }));
return { return {
comics, comics,
maxPage: 1, maxPage: 1
}; };
} else { } else {
res = await Network.post( res = await Network.post(
@@ -348,6 +338,14 @@ class Ikm extends ComicSource {
// 漫画详情 // 漫画详情
comic = { comic = {
loadInfo: async (id) => { loadInfo: async (id) => {
// 加载收藏页并判断是否收藏
let isFavorite = false;
try {
let favorites = await this.favorites.loadComics(1, null);
isFavorite = favorites.comics.some((comic) => comic.id === id);
} catch (error) {
console.error("加载收藏页失败:", error);
}
let res = await Network.get(id, Ikm.webHeaders); let res = await Network.get(id, Ikm.webHeaders);
let document = new HtmlDocument(res.body); let document = new HtmlDocument(res.body);
let comicId = id.match(/\d+/)[0]; let comicId = id.match(/\d+/)[0];
@@ -356,7 +354,7 @@ class Ikm extends ComicSource {
`${Ikm.baseUrl}/api/comic/zyz/chapterlink?id=${comicId}`, `${Ikm.baseUrl}/api/comic/zyz/chapterlink?id=${comicId}`,
{ {
...Ikm.jsonHead, ...Ikm.jsonHead,
Referer: id, "referer": id,
} }
); );
let epData = JSON.parse(epRes.body); let epData = JSON.parse(epRes.body);
@@ -388,29 +386,18 @@ class Ikm extends ComicSource {
); );
let intro = desc?.[1]?.trim().replace(/\s+/g, " ") || ""; let intro = desc?.[1]?.trim().replace(/\s+/g, " ") || "";
// 获取更新日期 return {
let fullDateStr = document
.querySelector('meta[property="og:cartoon:update_time"]')
.attributes["content"]; // "2025-07-18 08:37:02"
let date = new Date(fullDateStr);
let year = date.getFullYear();
let month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始要加1
let day = String(date.getDate()).padStart(2, "0");
let updateTime = `${year}-${month}-${day}`;
return new ComicDetails({
title: title.split("~")[0], title: title.split("~")[0],
cover: thumb, cover: thumb,
description: intro, description: intro,
updateTime: updateTime,
tags: { tags: {
作者: [ "作者": [
document document
.querySelector("div.book-container__author") .querySelector("div.book-container__author")
.text.split("作者:")[1], .text.split("作者:")[1],
], ],
最新章节: [document.querySelector("div.update > a > em").text], "更新": [document.querySelector("div.update > a > em").text],
标签: document "标签": document
.querySelectorAll("div.book-hero__detail > div.tags > a") .querySelectorAll("div.book-hero__detail > div.tags > a")
.map((e) => e.text.trim()) .map((e) => e.text.trim())
.filter((text) => text), .filter((text) => text),
@@ -423,7 +410,8 @@ class Ikm extends ComicSource {
cover: e.querySelector("div.thumb_img").attributes["data-src"], cover: e.querySelector("div.thumb_img").attributes["data-src"],
id: `${Ikm.baseUrl}${e.querySelector("a").attributes["href"]}`, id: `${Ikm.baseUrl}${e.querySelector("a").attributes["href"]}`,
})), })),
}); isFavorite: isFavorite,
};
}, },
onThumbnailLoad: Ikm.thumbConfig, onThumbnailLoad: Ikm.thumbConfig,
loadEp: async (comicId, epId) => { loadEp: async (comicId, epId) => {
@@ -444,7 +432,7 @@ class Ikm extends ComicSource {
url, url,
headers: { headers: {
...Ikm.webHeaders, ...Ikm.webHeaders,
Referer: epId, "referer": epId,
}, },
}; };
}, },

View File

@@ -60,7 +60,7 @@
"name": "爱看漫", "name": "爱看漫",
"fileName": "ikmmh.js", "fileName": "ikmmh.js",
"key": "ikmmh", "key": "ikmmh",
"version": "1.0.3" "version": "1.0.4"
}, },
{ {
"name": "少年ジャンプ+", "name": "少年ジャンプ+",
@@ -90,7 +90,7 @@
"name": "再漫画", "name": "再漫画",
"fileName": "zaimanhua.js", "fileName": "zaimanhua.js",
"key": "zaimanhua", "key": "zaimanhua",
"version": "1.0.0" "version": "1.0.1"
}, },
{ {
"name": "漫画柜", "name": "漫画柜",

View File

@@ -1,418 +1,490 @@
/** @type {import('./_venera_.js')} */ class Zaimanhua extends ComicSource {
class ZaiManHua extends ComicSource { // 基础信息
// Note: The fields which are marked as [Optional] should be removed if not used
// name of the source
name = "再漫画"; name = "再漫画";
// unique id of the source
key = "zaimanhua"; key = "zaimanhua";
version = "1.0.1";
minAppVersion = "1.0.0";
url =
"https://git.nyne.dev/nyne/venera-configs/raw/branch/main/zaimanhua.js";
version = "1.0.0"; // 初始化请求头
minAppVersion = "1.4.0";
// update url
url = "https://git.nyne.dev/nyne/venera-configs/raw/branch/main/zaimanhua.js";
/**
* fetch html content
* @param url {string}
* @param headers {object?}
* @returns {Promise<{document:HtmlDocument}>}
*/
async fetchHtml(url, headers = {}) {
let res = await Network.get(url, headers);
if (res.status !== 200) {
throw "Invalid status code: " + res.status;
}
let document = new HtmlDocument(res.body);
return document;
}
/**
* fetch json content
* @param url {string}
* @param headers {object?}
* @returns {Promise<{data:object}>}
*/
async fetchJson(url, headers = {}) {
let res = await Network.get(url, headers);
return JSON.parse(res.body).data;
}
/**
* parse json content
* @param e object
* @returns {Comic}
*/
parseJsonComic(e) {
let id = e.comic_py;
if (!id) {
id = id.comicPy;
}
let title = e?.name;
if (!title) {
title = e?.title;
}
return new Comic({
id: id.toString(),
title: title.toString(),
subtitle: e?.authors,
tags: e?.types?.split("/"),
cover: e?.cover,
description: e?.last_update_chapter_name.toString(),
});
}
/**
* [Optional] init function
*/
init() { init() {
this.domain = "https://www.zaimanhua.com"; this.headers = {
this.imgBase = "https://images.zaimanhua.com"; "User-Agent": "Mozilla/5.0 (Linux; Android) Mobile",
this.baseUrl = "https://manhua.zaimanhua.com"; "authorization": `Bearer ${this.loadData("token") || ""}`,
};
}
// 构建 URL
buildUrl(path) {
return `https://v4api.zaimanhua.com/app/v1/${path}`;
} }
// explore page list //账户管理
account = {
login: async (username, password) => {
try {
const encryptedPwd = Convert.hexEncode(
Convert.md5(Convert.encodeUtf8(password))
);
const res = await Network.post(
"https://account-api.zaimanhua.com/v1/login/passwd",
{ "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" },
`username=${username}&passwd=${encryptedPwd}`
);
const data = JSON.parse(res.body);
if (data.errno !== 0) throw new Error(data.errmsg);
this.saveData("token", data.data.user.token);
this.headers.authorization = `Bearer ${data.data.user.token}`;
return true;
} catch (e) {
UI.showMessage(`登录失败: ${e.message}`);
throw e;
}
},
logout: () => {
this.deleteData("token");
},
};
// 状态检查
checkResponseStatus(res) {
if (res.status === 401) {
throw new Error("登录失效");
}
if (res.status !== 200) {
throw new Error(`请求失败: ${res.status}`);
}
}
// 漫画解析
parseComic(comic) {
// const safeString = (value) => (value || "").toString().trim();
const safeString = (value) => (value != null ? value.toString() : "");
const resolveId = () =>
[comic.comic_id, comic.id].find((id) => id && id !== "0") || "";
const resolveTags = () =>
[comic.status, ...safeString(comic.types).split("/")].filter(Boolean);
const resolveDescription = () => {
const candidates = [
comic.description,
comic.last_update_chapter_name,
comic.last_name,
];
return candidates.find((text) => text) || "";
};
return {
id: safeString(resolveId()),
title: comic.title || comic.name,
subTitle: comic.authors,
cover: comic.cover,
tags: resolveTags(),
description: resolveDescription(),
};
}
//探索页面
explore = [ explore = [
{ {
// title of the page. title: "再漫画 更新",
// title is used to identify the page, it should be unique type: "multiPageComicList",
title: this.name,
/// TODO multiPartPage
type: "singlePageWithMultiPart",
/**
* load function
* @param page {number | null} - page number, null for `singlePageWithMultiPart` type
* @returns {{}}
* - for `multiPartPage` type, return [{title: string, comics: Comic[], viewMore: PageJumpTarget}]
* - for `multiPageComicList` type, for each page(1-based), return {comics: Comic[], maxPage: number}
* - for `mixed` type, use param `page` as index. for each index(0-based), return {data: [], maxPage: number?}, data is an array contains Comic[] or {title: string, comics: Comic[], viewMore: string?}
*/
load: async (page) => { load: async (page) => {
let result = {}; const res = await Network.get(
// https://manhua.zaimanhua.com/api/v1/comic1/recommend/list? this.buildUrl(`comic/update/list/0/${page}`),
// channel=pc&app_name=zmh&version=1.0.0&timestamp=1753547675981&uid=0 this.headers
let api = `${this.baseUrl}/api/v1/comic1/recommend/list`; );
let params = { const data = JSON.parse(res.body).data;
channel: "pc", return {
app_name: "zmh", comics: data.map((item) => this.parseComic(item)),
version: "1.0.0",
timestamp: Date.now(),
uid: 0,
}; };
let params_str = Object.keys(params)
.map((key) => `${key}=${params[key]}`)
.join("&");
let url = `${api}?${params_str}`;
const json = await this.fetchJson(url);
let data = json.list;
data.shift(); // 去掉第一个
data.pop(); // 去掉最后一个
data.map((arr) => {
let title = arr.name;
let comic_list = arr.list.map((item) => this.parseJsonComic(item));
result[title] = comic_list;
});
log("error", "再看漫画", result);
return result;
}, },
}, },
]; ];
// categories static categoryParamMap = {
// categories "全部": "0",
"冒险": "4",
"欢乐向": "5",
"格斗": "6",
"科幻": "7",
"爱情": "8",
"侦探": "9",
"竞技": "10",
"魔法": "11",
"神鬼": "12",
"校园": "13",
"惊悚": "14",
"其他": "16",
"四格": "17",
"亲情": "3242",
"百合": "3243",
"秀吉": "3244",
"悬疑": "3245",
"纯爱": "3246",
"热血": "3248",
"泛爱": "3249",
"历史": "3250",
"战争": "3251",
"萌系": "3252",
"宅系": "3253",
"治愈": "3254",
"励志": "3255",
"武侠": "3324",
"机战": "3325",
"音乐舞蹈": "3326",
"美食": "3327",
"职场": "3328",
"西方魔幻": "3365",
"高清单行": "4459",
"TS": "4518",
"东方": "5077",
"魔幻": "5806",
"奇幻": "5848",
"节操": "6219",
"轻小说": "6316",
"颜艺": "6437",
"搞笑": "7568",
"仙侠": "23388",
"舰娘": "7900",
"动画": "13627",
"AA": "17192",
"福瑞": "18522",
"生存": "23323",
"日常": "23388",
"画集": "30788",
"C100": "31137",
};
//分类页面
category = { category = {
/// title of the category page, used to identify the page, it should be unique title: "再漫画",
title: this.name,
parts: [ parts: [
{ {
name: "类型", name: "排行榜",
type: "fixed", type: "fixed",
categories: [ categories: ["日排行", "周排行", "月排行", "总排行"],
"全部", itemType: "category",
"冒险", categoryParams: ["0", "1", "2", "3"],
"搞笑", },
"格斗", {
"科幻", name: "分类",
"爱情", type: "fixed",
"侦探", categories: Object.keys(Zaimanhua.categoryParamMap),
"竞技", categoryParams: Object.values(Zaimanhua.categoryParamMap),
"魔法",
"校园",
"百合",
"耽美",
"历史",
"战争",
"宅系",
"治愈",
"仙侠",
"武侠",
"职场",
"神鬼",
"奇幻",
"生活",
"其他",
],
itemType: "category", itemType: "category",
categoryParams: [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"11",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
],
}, },
], ],
// enable ranking page
enableRankingPage: false,
}; };
/// category comic loading related //分类漫画加载
categoryComics = { categoryComics = {
/**
* load comics of a category
* @param category {string} - category name
* @param param {string?} - category param
* @param options {string[]} - options from optionList
* @param page {number} - page number
* @returns {Promise<{comics: Comic[], maxPage: number}>}
*/
load: async (category, param, options, page) => { load: async (category, param, options, page) => {
let fil = `${this.baseUrl}/api/v1/comic1/filter`; if (category.includes("排行")) {
let params = { let res = await Network.get(
timestamp: Date.now(), this.buildUrl(
sortType: 0, `comic/rank/list?page=${page}&rank_type=${options}&by_time=${param}`
page: page, ),
size: 20, this.headers
status: options[1], );
audience: options[0], return {
theme: param, comics: JSON.parse(res.body).data.map((item) =>
cate: options[2], this.parseComic(item)
}; ),
// 拼接url maxPage: 10,
let params_str = Object.keys(params) };
.map((key) => `${key}=${params[key]}`) } else {
.join("&"); param = Zaimanhua.categoryParamMap[category] || "0";
// log("error", "再漫画", params_str); let res = await Network.get(
let url = `${fil}?${params_str}&firstLetter`; this.buildUrl(
// log("error", "再漫画", url); `comic/filter/list?status=${options[2]}&theme=${param}&zone=${options[3]}&cate=${options[1]}&sortType=${options[0]}&page=${page}&size=20`
),
const json = await this.fetchJson(url); this.headers
let comics = json.comicList.map((e) => this.parseJsonComic(e)); );
let maxPage = Math.ceil(json.totalNum / params.size); const data = JSON.parse(res.body).data;
// log("error", "再漫画", comics); return {
return { comics: data.comicList.map((item) => this.parseComic(item)),
comics, maxPage: Math.ceil(data.totalNum / 20),
maxPage, };
}; }
}, },
// provide options for category comic loading
optionList: [ optionList: [
{ {
options: ["0-全部", "3262-少年", "3263-少女", "3264-青年"], options: ["1-更新", "2-人气"],
notShowWhen: null,
showWhen: Object.keys(Zaimanhua.categoryParamMap),
}, },
{ {
options: ["0-全部", "1-故事漫画", "2-四格多格"], options: [
"0-全部",
"3262-少年漫画",
"3263-少女漫画",
"3264-青年漫画",
"13626-女青漫画",
],
notShowWhen: null,
showWhen: Object.keys(Zaimanhua.categoryParamMap),
}, },
{ {
options: ["0-全部", "1-连载", "2-完结"], options: ["0-全部", "2309-连载", "2310-已完结", "29205-短篇"],
notShowWhen: null,
showWhen: Object.keys(Zaimanhua.categoryParamMap),
},
{
options: [
"0-全部",
"2304-日本",
"2305-韩国",
"2306-欧美",
"2307-港台",
"2308-内地",
"8435-其他",
],
notShowWhen: null,
showWhen: Object.keys(Zaimanhua.categoryParamMap),
},
{
options: ["0-人气", "1-吐槽", "2-订阅"],
notshowWhen: null,
showWhen: ["日排行", "周排行", "月排行", "总排行"],
}, },
], ],
}; };
/// search related //搜索
search = { search = {
/**
* load search result
* @param keyword {string}
* @param options {string[]} - options from optionList
* @param page {number}
* @returns {Promise<{comics: Comic[], maxPage: number}>}
*/
load: async (keyword, options, page) => { load: async (keyword, options, page) => {
let url = `${this.baseUrl}/app/v1/search/index?keyword=${keyword}&source=0&page=${page}&size=20`; const res = await Network.get(
const json = await this.fetchJson(url); this.buildUrl(
let comics = json.comicList.map((e) => this.parseJsonComic(e)); `search/index?keyword=${encodeURIComponent(
let maxPage = Math.ceil(json.totalNum / params.size); keyword
// log("error", "再漫画", comics); )}&page=${page}&sort=0&size=20`
),
this.headers
);
const data = JSON.parse(res.body).data.list;
return { return {
comics, comics: data.map((item) => this.parseComic(item)),
maxPage,
}; };
}, },
// provide options for search
optionList: [], optionList: [],
}; };
/// single comic related //收藏
favorites = {
multiFolder: false,
addOrDelFavorite: async (comicId, folderId, isAdding) => {
const path = isAdding ? "add" : "del";
const res = await Network.get(
this.buildUrl(`comic/sub/${path}?comic_id=${comicId}`),
this.headers
);
const data = JSON.parse(res.body);
if (data.errno !== 0) {
throw new Error(data.errmsg || "操作失败");
}
return "ok";
},
loadComics: async (page) => {
try {
const res = await Network.get(
this.buildUrl(`comic/sub/list?status=0&page=${page}&size=20`),
this.headers
);
const data = JSON.parse(res.body).data;
return {
comics: data.subList.map((item) => this.parseComic(item)) ?? [],
maxPage: Math.ceil(data.total / 20),
};
} catch (e) {
console.error("加载收藏失败:", e);
return { comics: [], maxPage: null };
}
},
};
// 时间戳转换
formatTimestamp(ts) {
const date = new Date(ts * 1000);
return date.toISOString().split("T")[0];
}
//漫画详情
comic = { comic = {
/**
* load comic info
* @param id {string}
* @returns {Promise<ComicDetails>}
*/
loadInfo: async (id) => { loadInfo: async (id) => {
const api = `${this.domain}/api/v1/comic1/comic/detail`; const getFavoriteStatus = async (id) => {
let params = { let res = await Network.get(
channel: "pc", this.buildUrl(`comic/sub/checkIsSub?objId=${id}&source=1`),
app_name: "zmh", this.headers
version: "1.0.0", );
timestamp: Date.now(), this.checkResponseStatus(res);
uid: 0, return JSON.parse(res.body).data.isSub;
comic_py: id,
}; };
let params_str = Object.keys(params) let results = await Promise.all([
.map((key) => `${key}=${params[key]}`) Network.get(
.join("&"); this.buildUrl(`comic/detail/${id}?channel=android`),
let url = `${api}?${params_str}`; this.headers
const json = await this.fetchJson(url); ),
const info = json.comicInfo; getFavoriteStatus.bind(this)(id),
const comic_id = info.id; ]);
let title = info.title; const response = JSON.parse(results[0].body);
let author = info.authorInfo.authorName; if (response.errno !== 0) throw new Error(response.errmsg || "加载失败");
const data = response.data.data;
// 修复时间戳转换问题 function processChapters(groups) {
let lastUpdateTime = new Date(info.lastUpdateTime * 1000); return (groups || []).reduce((result, group) => {
let updateTime = `${lastUpdateTime.getFullYear()}-${ const groupTitle = group.title || "默认";
lastUpdateTime.getMonth() + 1 const chapters = (group.data || [])
}-${lastUpdateTime.getDate()}`; .reverse()
.map((ch) => [
let description = info.description; String(ch.chapter_id),
let cover = info.cover; `${ch.chapter_title.replace(
/^(?:连载版?)?(\d+\.?\d*)([话卷])?$/,
let chapters = new Map(); (_, n, t) => `${n}${t || "话"}`
info.chapterList[0].data.forEach((e) => { )}`,
chapters.set(e.chapter_id.toString(), e.chapter_title); ]);
}); result.set(groupTitle, new Map(chapters));
// chapters 按照key排序 return result;
let chaptersSorted = new Map([...chapters].sort((a, b) => a[0] - b[0])); }, new Map());
}
// 获取推荐漫画 // 分类标签
const api2 = `${this.baseUrl}/api/v1/comic1/comic/same_list`; const { authors, status, types } = data;
let params2 = { const tagMapper = (arr) => arr.map((t) => t.tag_name);
channel: "pc",
app_name: "zmh",
version: "1.0.0",
timestamp: Date.now(),
uid: 0,
comic_id: comic_id,
};
let params2_str = Object.keys(params2)
.map((key) => `${key}=${params2[key]}`)
.join("&");
let url2 = `${api2}?${params2_str}`;
const json2 = await this.fetchJson(url2);
let recommend = json2.data.comicList.map((e) => this.parseJsonComic(e));
let tags = {
状态: [info.status],
类型: [info.readerGroup, ...info.types.split("/")],
点击: [info.hitNumStr.toString()],
订阅: [info.subNumStr],
};
return new ComicDetails({
title,
subtitle: author,
cover,
description,
tags,
chapters: chaptersSorted,
recommend,
updateTime,
});
},
/**
* load images of a chapter
* @param comicId {string}
* @param epId {string?}
* @returns {Promise<{images: string[]}>}
*/
loadEp: async (comicId, epId) => {
const api_ = `${this.domain}/api/v1/comic1/comic/detail`;
// log("error", "再漫画", id);
let params_ = {
channel: "pc",
app_name: "zmh",
version: "1.0.0",
timestamp: Date.now(),
uid: 0,
comic_py: comicId,
};
let params_str_ = Object.keys(params_)
.map((key) => `${key}=${params_[key]}`)
.join("&");
let url_ = `${api_}?${params_str_}`;
const json_ = await this.fetchJson(url_);
const info_ = json_.comicInfo;
const comic_id = info_.id;
const api = `${this.baseUrl}/api/v1/comic1/chapter/detail`;
// comic_id=18114&chapter_id=36227
let params = {
channel: "pc",
app_name: "zmh",
version: "1.0.0",
timestamp: Date.now(),
uid: 0,
comic_id: comic_id,
chapter_id: epId,
};
let params_str = Object.keys(params)
.map((key) => `${key}=${params[key]}`)
.join("&");
let url = `${api}?${params_str}`;
const json = await this.fetchJson(url);
const info = json.chapterInfo;
return { return {
images: info.page_url, title: data.title,
cover: data.cover,
description: data.description,
tags: {
"作者": tagMapper(authors),
"状态": [...tagMapper(status), data.last_update_chapter_name],
"标签": tagMapper(types),
},
updateTime: this.formatTimestamp(data.last_updatetime),
chapters: processChapters(data.chapters),
isFavorite: results[1],
subId: id,
}; };
}, },
/** loadEp: async (comicId, epId) => {
* [Optional] provide configs for an image loading const res = await Network.get(
* @param url this.buildUrl(`comic/chapter/${comicId}/${epId}`)
* @param comicId );
* @param epId const data = JSON.parse(res.body).data.data;
* @returns {ImageLoadingConfig | Promise<ImageLoadingConfig>} return { images: data.page_url_hd || data.page_url };
*/
onImageLoad: (url, comicId, epId) => {
return {};
}, },
/**
* [Optional] provide configs for a thumbnail loading loadComments: async (comicId, subId, page, replyTo) => {
* @param url {string} try {
* @returns {ImageLoadingConfig | Promise<ImageLoadingConfig>} // 构建请求URL
* const url = this.buildUrl(
* `ImageLoadingConfig.modifyImage` and `ImageLoadingConfig.onLoadFailed` will be ignored. `comment/list?page=${page}&size=30&type=4&objId=${
* They are not supported for thumbnails. subId || comicId
*/ }&sortBy=1`
onThumbnailLoad: (url) => { );
return {}; const res = await Network.get(url, this.headers);
this.checkResponseStatus(res);
const response = JSON.parse(res.body);
const data = response.data;
/* 空数据检查 */
if (!data || !data.commentIdList || !data.commentList) {
UI.showMessage("暂时没有评论,快来发表第一条吧~");
return { comments: [], maxPage: 0 };
}
/* 处理评论ID列表 */
// 标准化ID数组处理null/字符串/数组等多种情况
const rawIds = Array.isArray(data.commentIdList)
? data.commentIdList
: [];
// 展开所有ID并过滤无效值
const allCommentIds = rawIds
.map((idStr) => `${idStr || ""}`.split(",")) // 转换为字符串再分割
.flat()
.filter((id) => id.trim() !== "");
// 最终ID处理流程
const processComments = () => {
// 去重并验证ID有效性
const validIds = [...new Set(allCommentIds)].filter((id) =>
data.commentList.hasOwnProperty(id)
);
// 过滤回复评论
const filteredIds = replyTo
? validIds.filter(
(id) => data.commentList[id]?.to_comment_id == replyTo
)
: validIds;
// 转换为评论对象
return filteredIds.map((id) => {
const comment = data.commentList[id];
return new Comment({
userName: comment.nickname || "匿名用户",
avatar: comment.photo || "",
content: comment.content || "[内容已删除]",
time: this.formatTimestamp(comment.create_time),
replyCount: comment.reply_amount || 0,
score: comment.like_amount || 0,
id: String(id),
parentId: comment.to_comment_id || null,
});
});
};
// 当没有有效评论时显示提示
const comments = processComments();
if (comments.length === 0) {
UI.showMessage(replyTo ? "该评论暂无回复" : "这里还没有评论哦~");
}
return {
comments: comments,
maxPage: Math.ceil((data.total || 0) / 30),
};
} catch (e) {
console.error("评论加载失败:", e);
UI.showMessage(`加载评论失败: ${e.message}`);
return { comments: [], maxPage: 0 };
}
},
// 发送评论, 返回任意值表示成功.
sendComment: async (comicId, subId, content, replyTo) => {
if (!replyTo) {
replyTo = 0;
}
let res = await Network.post(
this.buildUrl(`comment/add`),
{
...this.headers,
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
},
`obj_id=${subId}&content=${encodeURIComponent(
content
)}&to_comment_id=${replyTo}&type=4`
);
this.checkResponseStatus(res);
let response = JSON.parse(res.body);
if (response.errno !== 0) throw new Error(response.errmsg || "加载失败");
return "ok";
},
// 点赞
likeComment: async (comicId, subId, commentId, isLike) => {
let res = await Network.post(
this.buildUrl(`comment/addLike`),
{
...this.headers,
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
},
`commentId=${commentId}&type=4`
);
this.checkResponseStatus(res);
return "ok";
}, },
}; };
} }