-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathmycomic.js
More file actions
701 lines (630 loc) · 24.6 KB
/
Copy pathmycomic.js
File metadata and controls
701 lines (630 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/** @type {import('./_venera_.js')} */
const BASE_URL = "https://mycomic.com/cn";
const CDN_URL = "https://biccam.com";
const REFERER = "https://mycomic.com/";
const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
const headers = {
"User-Agent": UA,
"Referer": REFERER,
"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",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Sec-Ch-Ua": '"Chromium";v="131", "Not_A Brand";v="24"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
};
/**
* Check if the response is a Cloudflare challenge page
* @param {number} status
* @param {string} body
* @returns {boolean}
*/
function isCloudflareChallenge(status, body) {
if (status === 403 || status === 503) {
if (body && (body.indexOf("challenge-platform") !== -1 ||
body.indexOf("cf-browser-verification") !== -1 ||
body.indexOf("Just a moment") !== -1 ||
body.indexOf("__cf_chl_") !== -1)) {
return true;
}
return true;
}
if (body && body.indexOf("challenge-platform") !== -1) {
return true;
}
return false;
}
/**
* Wrapper for Network.get that detects Cloudflare challenges
* and throws a user-friendly error guiding them to login
* @param {string} url
* @returns {Promise<{status: number, headers: object, body: string}>}
*/
async function fetchWithCFCheck(url) {
const resp = await Network.get(url, headers);
if (isCloudflareChallenge(resp.status, resp.body)) {
throw "Cloudflare 验证拦截:请在漫画源设置中点击「登录」,通过内置浏览器完成一次 Cloudflare 验证后即可正常使用。";
}
return resp;
}
/**
* Extract meta tag content from raw HTML
* @param {string} html
* @param {string} name - meta name or property (e.g. "description", "og:title")
* @returns {string|null}
*/
function getMetaContent(html, name) {
// pattern 1: <meta name="x" content="y"> or <meta property="x" content="y">
let m = new RegExp(
"<meta[^>]*?(?:name|property)=['\"]" + escapeRegex(name) + "['\"][^>]*?content=['\"]([^'\"]*)['\"]",
"i"
).exec(html);
if (m) return m[1];
// pattern 2: <meta content="y" name="x"> or <meta content="y" property="x">
m = new RegExp(
"<meta[^>]*?content=['\"]([^'\"]*)['\"][^>]*?(?:name|property)=['\"]" + escapeRegex(name) + "['\"]",
"i"
).exec(html);
if (m) return m[1];
return null;
}
function escapeRegex(s) {
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
/**
* Parse comic list from an HtmlDocument
* Finds all <a> links to /cn/comics/{id} that contain an <img> with a CDN cover
* @param {HtmlDocument} doc
* @returns {Comic[]}
*/
function parseComicList(doc) {
const links = doc.querySelectorAll("a[href*='/cn/comics/']");
const comics = [];
const seen = new Set();
links.forEach((a) => {
const href = a.attributes["href"] || "";
const match = /\/cn\/comics\/(\d+)/.exec(href);
if (!match) return;
const id = match[1];
if (seen.has(id)) return;
const img = a.querySelector("img");
if (!img) return;
// Cover: prefer data-src (lazy-loaded), fallback to src
let cover = img.attributes["data-src"] || img.attributes["src"] || "";
if (!cover || cover.indexOf("biccam.com/comics/") === -1) return;
// Title from alt attribute
const title = (img.attributes["alt"] || "").trim() || id;
// Latest chapter info
let description = "";
const chapterDiv = a.querySelector("div.truncate");
if (chapterDiv) {
description = chapterDiv.text.trim();
}
seen.add(id);
comics.push(
new Comic({
id: id,
title: title,
cover: cover,
description: description,
language: "zh-Hans",
})
);
});
return comics;
}
/**
* Extract max page number from pagination links in raw HTML
* @param {string} html
* @returns {number}
*/
function parseMaxPage(html) {
const pageMatches = html.match(/(?:href="[^"]*page=)(\d+)/g);
if (!pageMatches) return 1;
let max = 1;
pageMatches.forEach((m) => {
const n = parseInt(m.replace(/.*page=/, ""), 10);
if (!isNaN(n) && n > max) max = n;
});
return max;
}
/**
* Build a comics listing URL with optional filters
* @param {number} page
* @param {string} sort - sort param (e.g. "-update", "-views", "-id")
* @param {string} q - search keyword
* @param {string} filterType - "tag" | "country" | "audience" | "year" | "end"
* @param {string} filterValue - filter value
* @returns {string}
*/
function buildComicsUrl(page, sort, q, filterType, filterValue) {
const params = [];
if (q) params.push("q=" + encodeURIComponent(q));
if (sort) params.push("sort=" + sort);
if (filterType && filterValue) {
params.push("filter[" + filterType + "]=" + filterValue);
}
if (page && page > 1) params.push("page=" + page);
const query = params.join("&");
return BASE_URL + "/comics" + (query ? "?" + query : "");
}
class MyComic extends ComicSource {
name = "MYCOMIC";
key = "mycomic";
version = "1.1.0";
minAppVersion = "1.4.6";
url = "https://cdn.jsdelivr.net/gh/venera-app/venera-configs@main/mycomic.js";
init() {
// Check if cf_clearance cookie exists; if not, the user may need to "login"
const cookies = Network.getCookies("https://mycomic.com");
let hasCfClearance = false;
if (cookies && cookies.length > 0) {
for (let i = 0; i < cookies.length; i++) {
if (cookies[i].name === "cf_clearance") {
hasCfClearance = true;
break;
}
}
}
if (!hasCfClearance) {
console.log("[MyComic] No cf_clearance cookie found. User may need to login.");
}
}
// ==================== Account (Cloudflare bypass) ====================
account = {
// Method 1: WebView login - opens mycomic.com in a real browser engine
// The browser will automatically solve Cloudflare's JS challenge,
// and the resulting cf_clearance cookie will be stored for Network requests.
loginWithWebview: {
url: "https://mycomic.com/cn",
checkStatus: (url, title) => {
// Cloudflare challenge page has title "Just a moment..." or similar
// After the challenge is passed, the real site loads
if (!url || !title) return false;
if (title.indexOf("moment") !== -1) return false;
if (title.indexOf("Cloudflare") !== -1) return false;
if (title.indexOf("challenge") !== -1) return false;
// Success: we're on the actual mycomic.com page
if (url.indexOf("mycomic.com") !== -1) return true;
return false;
},
onLoginSuccess: () => {
// Cookies from WebView should be synced with Network API automatically.
// Log for debugging.
const cookies = Network.getCookies("https://mycomic.com");
console.log("[MyComic] Login success. Cookies: " + (cookies ? cookies.length : 0));
},
},
// Method 2: Manual cookie input - user can paste cf_clearance value
// obtained from their browser's dev tools
loginWithCookies: {
fields: ["cf_clearance"],
validate: async (values) => {
if (!values || !values[0]) return false;
// Set the cf_clearance cookie
Network.setCookies("https://mycomic.com", [
new Cookie({
name: "cf_clearance",
value: values[0],
domain: ".mycomic.com",
}),
]);
// Validate by trying to fetch the homepage
try {
const resp = await Network.get(
"https://mycomic.com/cn",
headers
);
return resp.status === 200 &&
!isCloudflareChallenge(resp.status, resp.body);
} catch (e) {
return false;
}
},
},
logout: () => {
Network.deleteCookies("https://mycomic.com");
},
registerWebsite: null,
};
// ==================== Explore ====================
explore = [
{
title: "最新上架",
type: "multiPageComicList",
load: async (page) => {
if (!page) page = 1;
const url = buildComicsUrl(page, "-id");
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
const comics = parseComicList(doc);
const maxPage = parseMaxPage(resp.body);
return { comics, maxPage };
},
},
{
title: "最近更新",
type: "multiPageComicList",
load: async (page) => {
if (!page) page = 1;
const url = buildComicsUrl(page, "-update");
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
const comics = parseComicList(doc);
const maxPage = parseMaxPage(resp.body);
return { comics, maxPage };
},
},
{
title: "最高人气",
type: "multiPageComicList",
load: async (page) => {
if (!page) page = 1;
const url = buildComicsUrl(page, "-views");
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
const comics = parseComicList(doc);
const maxPage = parseMaxPage(resp.body);
return { comics, maxPage };
},
},
];
// ==================== Category ====================
category = {
title: "MYCOMIC",
parts: [
{
name: "作品类型",
type: "fixed",
categories: [
"魔幻", "魔法", "热血", "冒险", "悬疑", "侦探", "爱情",
"校园", "搞笑", "四格", "科幻", "神鬼", "舞蹈", "音乐",
"百合", "后宫", "机战", "格斗", "恐怖", "萌系", "武侠",
"社会", "历史", "耽美", "励志", "职场", "生活", "治愈",
"伪娘", "黑道", "战争", "竞技", "体育", "美食", "腐女",
"宅男", "推理", "杂志",
],
itemType: "category",
categoryParams: [
"tag:mohuan", "tag:mofa", "tag:rexue", "tag:maoxian",
"tag:xuanyi", "tag:zhentan", "tag:aiqing", "tag:xiaoyuan",
"tag:gaoxiao", "tag:sige", "tag:kehuan", "tag:shengui",
"tag:wudao", "tag:yinyue", "tag:baihe", "tag:hougong",
"tag:jizhan", "tag:gedou", "tag:kongbu", "tag:mengxi",
"tag:wuxia", "tag:shehui", "tag:lishi", "tag:danmei",
"tag:lizhi", "tag:zhichang", "tag:shenghuo", "tag:zhiyu",
"tag:weiniang", "tag:heidao", "tag:zhanzheng", "tag:jingji",
"tag:tiyu", "tag:meishi", "tag:funv", "tag:zhainan",
"tag:tuili", "tag:zazhi",
],
},
{
name: "作品地区",
type: "fixed",
categories: ["日本", "港台", "欧美", "内地", "韩国", "其他"],
itemType: "category",
categoryParams: [
"country:japan", "country:hongkong", "country:europe",
"country:china", "country:korea", "country:other",
],
},
{
name: "适合受众",
type: "fixed",
categories: ["少女", "少年", "青年", "儿童", "通用"],
itemType: "category",
categoryParams: [
"audience:shaonv", "audience:shaonian", "audience:qingnian",
"audience:ertong", "audience:tongyong",
],
},
{
name: "出品年份",
type: "fixed",
categories: [
"2026", "2025", "2024", "2023", "2022", "2021",
"2020", "2019", "2018", "2017", "2016", "2015",
"2014", "2013", "2012", "2011", "2010",
"00年代", "90年代", "80年代", "70年代或更早",
],
itemType: "category",
categoryParams: [
"year:2026", "year:2025", "year:2024", "year:2023",
"year:2022", "year:2021", "year:2020", "year:2019",
"year:2018", "year:2017", "year:2016", "year:2015",
"year:2014", "year:2013", "year:2012", "year:2011",
"year:2010", "year:200x", "year:199x", "year:198x",
"year:197x",
],
},
{
name: "目前进度",
type: "fixed",
categories: ["连载中", "已完结"],
itemType: "category",
categoryParams: ["end:0", "end:1"],
},
],
enableRankingPage: true,
};
// ==================== Category Comics ====================
categoryComics = {
load: async (category, param, options, page) => {
if (!page) page = 1;
// Parse filter type and value from param (format: "type:value")
let filterType = null;
let filterValue = null;
let sort = "-id";
if (param) {
const parts = param.split(":");
if (parts.length >= 2) {
filterType = parts[0];
filterValue = parts.slice(1).join(":");
}
}
// Get sort option
if (options && options.length > 0 && options[0]) {
sort = options[0];
}
const url = buildComicsUrl(page, sort, null, filterType, filterValue);
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
const comics = parseComicList(doc);
const maxPage = parseMaxPage(resp.body);
return { comics, maxPage };
},
optionList: [
{
options: [
"-id-最新上架",
"-update-最近更新",
"-views-最高人气",
],
},
],
ranking: {
options: [
"-views-历史排行",
"-week-週排行",
"-month-月排行",
],
load: async (option, page) => {
if (!page) page = 1;
const sort = option || "-views";
const url =
BASE_URL +
"/rank?sort=" +
sort +
(page > 1 ? "&page=" + page : "");
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
const comics = parseComicList(doc);
const maxPage = parseMaxPage(resp.body);
return { comics, maxPage };
},
},
};
// ==================== Search ====================
search = {
load: async (keyword, options, page) => {
if (!page) page = 1;
const kw = (keyword || "").trim();
if (!kw) return { comics: [], maxPage: 1 };
let sort = null;
if (options && options.length > 0 && options[0]) {
sort = options[0];
}
const url = buildComicsUrl(page, sort, kw);
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
const comics = parseComicList(doc);
const maxPage = parseMaxPage(resp.body);
return { comics, maxPage };
},
optionList: [
{
type: "select",
options: [
"-id-最新上架",
"-update-最近更新",
"-views-最高人气",
],
label: "排序",
default: null,
},
],
enableTagsSuggestions: false,
};
// ==================== Comic Detail ====================
comic = {
loadInfo: async (id) => {
const url = BASE_URL + "/comics/" + id;
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const html = resp.body;
const doc = new HtmlDocument(html);
// Parse meta tags
let title = getMetaContent(html, "og:title") || id;
title = title.replace(/\s*-\s*MYCOMIC.*$/, "").trim();
const description = getMetaContent(html, "description") || "";
const author = getMetaContent(html, "author") || "";
const cover =
getMetaContent(html, "og:image") ||
CDN_URL + "/comics/" + id + ".jpg";
const keywords = getMetaContent(html, "keywords") || "";
// Parse tags from filter links on the page
const tags = new Map();
const tagLinks = doc.querySelectorAll(
"a[href*='filter%5Btag%5D']"
);
const tagNames = [];
tagLinks.forEach((a) => {
const text = a.text.trim();
if (text) tagNames.push(text);
});
if (tagNames.length) tags.set("类型", tagNames);
// Parse additional info from keywords
const keywordList = keywords
.split(",")
.map((s) => s.trim())
.filter(Boolean);
if (author) tags.set("作者", [author]);
// Try to extract country and audience from keywords
const countryMap = {
日本: "日本",
内地: "内地",
韩国: "韩国",
欧美: "欧美",
港台: "港台",
其他: "其他",
};
const audienceMap = {
少年: "少年",
少女: "少女",
青年: "青年",
儿童: "儿童",
通用: "通用",
};
const countries = [];
const audiences = [];
keywordList.forEach((kw) => {
if (countryMap[kw]) countries.push(kw);
if (audienceMap[kw]) audiences.push(kw);
});
if (countries.length) tags.set("地区", countries);
if (audiences.length) tags.set("受众", audiences);
// Parse chapter list from Alpine.js x-data
// The x-data attribute contains: chapters: [{"id":96338,"title":"第16回"}, ...]
const chapters = new Map();
const chapterMatch = /chapters:\s*(\[[\s\S]*?\])/.exec(html);
if (chapterMatch) {
try {
const chapterList = JSON.parse(chapterMatch[1]);
chapterList.forEach((ch) => {
chapters.set(String(ch.id), ch.title);
});
} catch (e) {
// Fallback: try to find chapter links in the page
const chapterLinks = doc.querySelectorAll(
"a[href*='/cn/chapters/']"
);
chapterLinks.forEach((a) => {
const href = a.attributes["href"] || "";
const m = /\/cn\/chapters\/(\d+)/.exec(href);
if (m) {
const chTitle = a.text.trim();
if (chTitle && !chapters.has(m[1])) {
chapters.set(m[1], chTitle);
}
}
});
}
}
return new ComicDetails({
title: title,
cover: cover,
description: description,
tags: tags,
chapters: chapters,
thumbnails: [cover],
url: url,
uploader: author || undefined,
});
},
loadEp: async (comicId, epId) => {
if (!epId) {
throw "No episode id";
}
const url = BASE_URL + "/chapters/" + epId;
const resp = await fetchWithCFCheck(url);
if (resp.status !== 200) throw "HTTP " + resp.status;
const doc = new HtmlDocument(resp.body);
// Chapter images have class "page" and src or data-src from biccam.com/chapters/
const imgs = doc.querySelectorAll("img.page");
const images = [];
if (imgs.length > 0) {
imgs.forEach((img) => {
let src =
img.attributes["data-src"] ||
img.attributes["src"] ||
"";
if (src && src.indexOf("biccam.com/chapters/") !== -1) {
images.push(src);
}
});
}
// Fallback: find all imgs with src containing biccam.com/chapters/
if (images.length === 0) {
const allImgs = doc.querySelectorAll("img");
allImgs.forEach((img) => {
let src =
img.attributes["data-src"] ||
img.attributes["src"] ||
"";
if (src && src.indexOf("biccam.com/chapters/") !== -1) {
images.push(src);
}
});
}
return { images: images };
},
onImageLoad: (url, comicId, epId) => {
return {
url: url,
headers: {
"Referer": REFERER,
"User-Agent": UA,
"Accept": "image/avif,image/webp,image/apng,image/*,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Sec-Fetch-Dest": "image",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "cross-site",
},
};
},
onThumbnailLoad: (url) => {
return {
url: url,
headers: {
"Referer": REFERER,
"User-Agent": UA,
"Accept": "image/avif,image/webp,image/apng,image/*,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Sec-Fetch-Dest": "image",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "cross-site",
},
};
},
onClickTag: (namespace, tag) => {
return {
page: "search",
attributes: {
keyword: tag,
},
};
},
link: {
domains: ["mycomic.com"],
linkToId: (url) => {
const m = /https?:\/\/(?:www\.)?mycomic\.com\/(?:cn\/)?comics\/(\d+)/.exec(
url
);
if (!m) return null;
return m[1];
},
},
};
}