@jackwener/opencli 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build-extension.yml +80 -0
- package/.github/workflows/ci.yml +6 -6
- package/.github/workflows/docs.yml +52 -0
- package/.github/workflows/e2e-headed.yml +2 -2
- package/.github/workflows/pkg-pr-new.yml +2 -2
- package/.github/workflows/release.yml +2 -5
- package/.github/workflows/security.yml +2 -2
- package/CDP.md +1 -1
- package/CDP.zh-CN.md +1 -1
- package/README.md +42 -34
- package/README.zh-CN.md +42 -34
- package/SKILL.md +3 -5
- package/dist/browser/cdp.d.ts +42 -0
- package/dist/browser/cdp.js +339 -0
- package/dist/browser/daemon-client.d.ts +3 -1
- package/dist/browser/daemon-client.js +4 -0
- package/dist/browser/dom-helpers.d.ts +20 -0
- package/dist/browser/dom-helpers.js +109 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.js +4 -0
- package/dist/browser/mcp.d.ts +1 -0
- package/dist/browser/mcp.js +10 -5
- package/dist/browser/page.d.ts +7 -0
- package/dist/browser/page.js +39 -123
- package/dist/browser/utils.d.ts +10 -0
- package/dist/browser/utils.js +27 -0
- package/dist/browser.test.js +49 -1
- package/dist/build-manifest.js +3 -1
- package/dist/build-manifest.test.js +34 -0
- package/dist/capabilityRouting.d.ts +2 -0
- package/dist/capabilityRouting.js +30 -0
- package/dist/capabilityRouting.test.d.ts +1 -0
- package/dist/capabilityRouting.test.js +42 -0
- package/dist/chaoxing.d.ts +58 -0
- package/dist/chaoxing.js +225 -0
- package/dist/chaoxing.test.d.ts +1 -0
- package/dist/chaoxing.test.js +45 -0
- package/dist/cli-manifest.json +885 -48
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +234 -0
- package/dist/clis/antigravity/serve.d.ts +14 -0
- package/dist/clis/antigravity/serve.js +263 -0
- package/dist/clis/bilibili/download.js +4 -14
- package/dist/clis/boss/chatlist.d.ts +1 -0
- package/dist/clis/boss/chatlist.js +50 -0
- package/dist/clis/boss/chatmsg.d.ts +1 -0
- package/dist/clis/boss/chatmsg.js +73 -0
- package/dist/clis/boss/resume.d.ts +1 -0
- package/dist/clis/boss/resume.js +249 -0
- package/dist/clis/boss/send.d.ts +1 -0
- package/dist/clis/boss/send.js +176 -0
- package/dist/clis/chaoxing/assignments.d.ts +1 -0
- package/dist/clis/chaoxing/assignments.js +74 -0
- package/dist/clis/chaoxing/exams.d.ts +1 -0
- package/dist/clis/chaoxing/exams.js +74 -0
- package/dist/clis/chatgpt/ask.js +15 -14
- package/dist/clis/chatgpt/ax.d.ts +1 -0
- package/dist/clis/chatgpt/ax.js +78 -0
- package/dist/clis/chatgpt/read.js +5 -6
- package/dist/clis/hf/top.d.ts +1 -0
- package/dist/clis/hf/top.js +119 -0
- package/dist/clis/jike/comment.d.ts +1 -0
- package/dist/clis/jike/comment.js +107 -0
- package/dist/clis/jike/create.d.ts +1 -0
- package/dist/clis/jike/create.js +106 -0
- package/dist/clis/jike/feed.d.ts +1 -0
- package/dist/clis/jike/feed.js +67 -0
- package/dist/clis/jike/like.d.ts +1 -0
- package/dist/clis/jike/like.js +61 -0
- package/dist/clis/jike/notifications.d.ts +1 -0
- package/dist/clis/jike/notifications.js +169 -0
- package/dist/clis/jike/post.yaml +58 -0
- package/dist/clis/jike/repost.d.ts +1 -0
- package/dist/clis/jike/repost.js +103 -0
- package/dist/clis/jike/search.d.ts +1 -0
- package/dist/clis/jike/search.js +67 -0
- package/dist/clis/jike/shared.d.ts +19 -0
- package/dist/clis/jike/shared.js +25 -0
- package/dist/clis/jike/topic.yaml +52 -0
- package/dist/clis/jike/user.yaml +51 -0
- package/dist/clis/smzdm/search.js +28 -39
- package/dist/clis/stackoverflow/bounties.yaml +29 -0
- package/dist/clis/stackoverflow/hot.yaml +28 -0
- package/dist/clis/stackoverflow/search.yaml +32 -0
- package/dist/clis/stackoverflow/unanswered.yaml +28 -0
- package/dist/clis/twitter/download.js +6 -16
- package/dist/clis/twitter/post.js +9 -2
- package/dist/clis/twitter/search.js +14 -33
- package/dist/clis/xiaohongshu/download.d.ts +1 -1
- package/dist/clis/xiaohongshu/download.js +4 -4
- package/dist/clis/zhihu/download.js +3 -3
- package/dist/doctor.d.ts +7 -0
- package/dist/doctor.js +16 -0
- package/dist/download/index.d.ts +12 -8
- package/dist/download/index.js +11 -3
- package/dist/download/index.test.d.ts +1 -0
- package/dist/download/index.test.js +14 -0
- package/dist/engine.js +25 -14
- package/dist/explore.d.ts +1 -0
- package/dist/explore.js +48 -103
- package/dist/generate.js +1 -0
- package/dist/interceptor.js +3 -2
- package/dist/main.js +4 -193
- package/dist/output.d.ts +2 -1
- package/dist/output.js +3 -1
- package/dist/pipeline/executor.test.js +1 -0
- package/dist/pipeline/steps/download.js +14 -18
- package/dist/registry.d.ts +4 -3
- package/dist/registry.js +5 -2
- package/dist/runtime.d.ts +4 -1
- package/dist/runtime.js +2 -2
- package/dist/scripts/framework.d.ts +4 -0
- package/dist/scripts/framework.js +21 -0
- package/dist/scripts/interact.d.ts +4 -0
- package/dist/scripts/interact.js +20 -0
- package/dist/scripts/store.d.ts +9 -0
- package/dist/scripts/store.js +44 -0
- package/dist/synthesize.js +1 -1
- package/dist/types.d.ts +12 -0
- package/dist/verify.d.ts +6 -1
- package/dist/verify.js +54 -2
- package/docs/.vitepress/config.mts +193 -0
- package/docs/adapters/browser/apple-podcasts.md +28 -0
- package/docs/adapters/browser/bbc.md +26 -0
- package/docs/adapters/browser/bilibili.md +38 -0
- package/docs/adapters/browser/boss.md +28 -0
- package/docs/adapters/browser/coupang.md +28 -0
- package/docs/adapters/browser/ctrip.md +27 -0
- package/docs/adapters/browser/github.md +26 -0
- package/docs/adapters/browser/hackernews.md +26 -0
- package/docs/adapters/browser/linkedin.md +27 -0
- package/docs/adapters/browser/reddit.md +41 -0
- package/docs/adapters/browser/reuters.md +27 -0
- package/docs/adapters/browser/smzdm.md +27 -0
- package/docs/adapters/browser/twitter.md +47 -0
- package/docs/adapters/browser/v2ex.md +32 -0
- package/docs/adapters/browser/weibo.md +27 -0
- package/docs/adapters/browser/xiaohongshu.md +32 -0
- package/docs/adapters/browser/xiaoyuzhou.md +28 -0
- package/docs/adapters/browser/xueqiu.md +32 -0
- package/docs/adapters/browser/yahoo-finance.md +26 -0
- package/docs/adapters/browser/youtube.md +29 -0
- package/docs/adapters/browser/zhihu.md +30 -0
- package/docs/adapters/desktop/antigravity.md +46 -0
- package/docs/adapters/desktop/chatgpt.md +43 -0
- package/docs/adapters/desktop/chatwise.md +38 -0
- package/docs/adapters/desktop/codex.md +32 -0
- package/docs/adapters/desktop/cursor.md +33 -0
- package/docs/adapters/desktop/discord.md +28 -0
- package/docs/adapters/desktop/feishu.md +20 -0
- package/docs/adapters/desktop/neteasemusic.md +31 -0
- package/docs/adapters/desktop/notion.md +29 -0
- package/docs/adapters/desktop/wechat.md +28 -0
- package/docs/adapters/index.md +49 -0
- package/docs/advanced/cdp.md +103 -0
- package/docs/advanced/download.md +63 -0
- package/docs/advanced/electron.md +125 -0
- package/docs/advanced/remote-chrome.md +72 -0
- package/docs/developer/ai-workflow.md +66 -0
- package/docs/developer/architecture.md +90 -0
- package/docs/developer/contributing.md +136 -0
- package/docs/developer/testing.md +237 -0
- package/docs/developer/ts-adapter.md +87 -0
- package/docs/developer/yaml-adapter.md +108 -0
- package/docs/guide/browser-bridge.md +38 -0
- package/docs/guide/getting-started.md +56 -0
- package/docs/guide/installation.md +37 -0
- package/docs/guide/troubleshooting.md +56 -0
- package/docs/index.md +35 -0
- package/docs/zh/adapters/index.md +5 -0
- package/docs/zh/advanced/cdp.md +3 -0
- package/docs/zh/developer/contributing.md +24 -0
- package/docs/zh/guide/browser-bridge.md +25 -0
- package/docs/zh/guide/getting-started.md +40 -0
- package/docs/zh/guide/installation.md +37 -0
- package/docs/zh/index.md +29 -0
- package/extension/dist/background.js +386 -438
- package/extension/manifest.json +2 -2
- package/extension/package-lock.json +1156 -0
- package/extension/src/background.test.ts +151 -0
- package/extension/src/background.ts +124 -53
- package/extension/src/protocol.ts +3 -1
- package/package.json +7 -3
- package/src/browser/cdp.ts +367 -0
- package/src/browser/daemon-client.ts +7 -1
- package/src/browser/dom-helpers.ts +116 -0
- package/src/browser/index.ts +4 -0
- package/src/browser/mcp.ts +14 -6
- package/src/browser/page.ts +47 -124
- package/src/browser/utils.ts +27 -0
- package/src/browser.test.ts +56 -0
- package/src/build-manifest.test.ts +36 -0
- package/src/build-manifest.ts +2 -1
- package/src/capabilityRouting.test.ts +47 -0
- package/src/capabilityRouting.ts +28 -0
- package/src/chaoxing.test.ts +53 -0
- package/src/chaoxing.ts +268 -0
- package/src/cli.ts +205 -0
- package/src/clis/antigravity/SKILL.md +5 -0
- package/src/clis/antigravity/serve.ts +329 -0
- package/src/clis/bilibili/download.ts +4 -15
- package/src/clis/boss/chatlist.ts +50 -0
- package/src/clis/boss/chatmsg.ts +70 -0
- package/src/clis/boss/resume.ts +262 -0
- package/src/clis/boss/send.ts +193 -0
- package/src/clis/chaoxing/README.md +36 -0
- package/src/clis/chaoxing/README.zh-CN.md +35 -0
- package/src/clis/chaoxing/assignments.ts +88 -0
- package/src/clis/chaoxing/exams.ts +88 -0
- package/src/clis/chatgpt/ask.ts +14 -15
- package/src/clis/chatgpt/ax.ts +81 -0
- package/src/clis/chatgpt/read.ts +5 -7
- package/src/clis/hf/top.ts +141 -0
- package/src/clis/jike/comment.ts +113 -0
- package/src/clis/jike/create.ts +113 -0
- package/src/clis/jike/feed.ts +74 -0
- package/src/clis/jike/like.ts +65 -0
- package/src/clis/jike/notifications.ts +185 -0
- package/src/clis/jike/post.yaml +58 -0
- package/src/clis/jike/repost.ts +114 -0
- package/src/clis/jike/search.ts +74 -0
- package/src/clis/jike/shared.ts +36 -0
- package/src/clis/jike/topic.yaml +52 -0
- package/src/clis/jike/user.yaml +51 -0
- package/src/clis/smzdm/search.ts +30 -39
- package/src/clis/stackoverflow/bounties.yaml +29 -0
- package/src/clis/stackoverflow/hot.yaml +28 -0
- package/src/clis/stackoverflow/search.yaml +32 -0
- package/src/clis/stackoverflow/unanswered.yaml +28 -0
- package/src/clis/twitter/download.ts +6 -17
- package/src/clis/twitter/post.ts +9 -2
- package/src/clis/twitter/search.ts +15 -33
- package/src/clis/xiaohongshu/download.ts +4 -4
- package/src/clis/zhihu/download.ts +3 -3
- package/src/doctor.ts +18 -2
- package/src/download/index.test.ts +16 -0
- package/src/download/index.ts +22 -4
- package/src/engine.ts +20 -13
- package/src/explore.ts +54 -103
- package/src/generate.ts +1 -0
- package/src/interceptor.ts +3 -2
- package/src/main.ts +4 -180
- package/src/output.ts +15 -13
- package/src/pipeline/executor.test.ts +1 -0
- package/src/pipeline/steps/download.ts +14 -17
- package/src/registry.ts +9 -5
- package/src/runtime.ts +3 -2
- package/src/scripts/framework.ts +20 -0
- package/src/scripts/interact.ts +22 -0
- package/src/scripts/store.ts +40 -0
- package/src/synthesize.ts +1 -1
- package/src/types.ts +9 -0
- package/src/verify.ts +64 -3
package/dist/chaoxing.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chaoxing (学习通) shared helpers.
|
|
3
|
+
*
|
|
4
|
+
* Flow: initSession → getCourses → enterCourse → getTabIframeUrl → navigate → parse DOM
|
|
5
|
+
* Chaoxing has no flat "list all assignments" API; data is behind session-gated
|
|
6
|
+
* course pages loaded as iframes.
|
|
7
|
+
*/
|
|
8
|
+
// ── Utilities ────────────────────────────────────────────────────────
|
|
9
|
+
/** Sleep for given milliseconds (anti-scraping delay). */
|
|
10
|
+
export function sleep(ms) {
|
|
11
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
12
|
+
}
|
|
13
|
+
/** Execute a credentialed fetch in the browser context, returning JSON or text. */
|
|
14
|
+
export async function fetchChaoxing(page, url) {
|
|
15
|
+
const urlJs = JSON.stringify(url);
|
|
16
|
+
return page.evaluate(`
|
|
17
|
+
async () => {
|
|
18
|
+
const res = await fetch(${urlJs}, { credentials: "include" });
|
|
19
|
+
const text = await res.text();
|
|
20
|
+
try { return JSON.parse(text); } catch {}
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
`);
|
|
24
|
+
}
|
|
25
|
+
/** Format a timestamp (seconds or milliseconds or date string) to YYYY-MM-DD HH:mm. */
|
|
26
|
+
export function formatTimestamp(ts) {
|
|
27
|
+
if (ts == null || ts === '' || ts === 0)
|
|
28
|
+
return '';
|
|
29
|
+
if (typeof ts === 'string' && !/^\d+$/.test(ts.trim()))
|
|
30
|
+
return ts.trim();
|
|
31
|
+
const num = Number(ts);
|
|
32
|
+
if (Number.isNaN(num) || num <= 0)
|
|
33
|
+
return String(ts);
|
|
34
|
+
const millis = num > 1e12 ? num : num * 1000;
|
|
35
|
+
const d = new Date(millis);
|
|
36
|
+
if (Number.isNaN(d.getTime()))
|
|
37
|
+
return String(ts);
|
|
38
|
+
const yyyy = d.getFullYear();
|
|
39
|
+
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
40
|
+
const dd = String(d.getDate()).padStart(2, '0');
|
|
41
|
+
const hh = String(d.getHours()).padStart(2, '0');
|
|
42
|
+
const mi = String(d.getMinutes()).padStart(2, '0');
|
|
43
|
+
return `${yyyy}-${mm}-${dd} ${hh}:${mi}`;
|
|
44
|
+
}
|
|
45
|
+
/** Map numeric work status to Chinese label. */
|
|
46
|
+
export function workStatusLabel(status) {
|
|
47
|
+
if (status == null || status === '')
|
|
48
|
+
return '未知';
|
|
49
|
+
const s = Number(status);
|
|
50
|
+
if (s === 0)
|
|
51
|
+
return '未交';
|
|
52
|
+
if (s === 1)
|
|
53
|
+
return '已交';
|
|
54
|
+
if (s === 2)
|
|
55
|
+
return '已批阅';
|
|
56
|
+
const str = String(status).trim();
|
|
57
|
+
return str || '未知';
|
|
58
|
+
}
|
|
59
|
+
/** Fetch enrolled course list via backclazzdata JSON API. */
|
|
60
|
+
export async function getCourses(page) {
|
|
61
|
+
const resp = await fetchChaoxing(page, 'https://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1');
|
|
62
|
+
if (!resp || typeof resp !== 'object')
|
|
63
|
+
return [];
|
|
64
|
+
const channelList = resp.channelList ?? [];
|
|
65
|
+
const courses = [];
|
|
66
|
+
for (const channel of channelList) {
|
|
67
|
+
const content = channel?.content;
|
|
68
|
+
if (!content)
|
|
69
|
+
continue;
|
|
70
|
+
const courseData = content.course?.data;
|
|
71
|
+
if (!Array.isArray(courseData))
|
|
72
|
+
continue;
|
|
73
|
+
for (const c of courseData) {
|
|
74
|
+
courses.push({
|
|
75
|
+
courseId: String(c.id ?? ''),
|
|
76
|
+
classId: String(content.id ?? ''),
|
|
77
|
+
cpi: String(channel.cpi ?? ''),
|
|
78
|
+
title: String(c.name ?? ''),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return courses;
|
|
83
|
+
}
|
|
84
|
+
// ── Session & course entry ───────────────────────────────────────────
|
|
85
|
+
/** Navigate to the interaction page to establish a Chaoxing session. */
|
|
86
|
+
export async function initSession(page) {
|
|
87
|
+
await page.goto('https://mooc2-ans.chaoxing.com/mooc2-ans/visit/interaction');
|
|
88
|
+
await page.wait(3);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Enter a course via stucoursemiddle redirect (establishes course session + enc).
|
|
92
|
+
* After this call the browser is on the course page.
|
|
93
|
+
*/
|
|
94
|
+
export async function enterCourse(page, course) {
|
|
95
|
+
const url = `https://mooc1.chaoxing.com/visit/stucoursemiddle` +
|
|
96
|
+
`?courseid=${course.courseId}&clazzid=${course.classId}&cpi=${course.cpi}&ismooc2=1&v=2`;
|
|
97
|
+
await page.goto(url);
|
|
98
|
+
await page.wait(3);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* On the course page, click a tab (作业 / 考试) and return the iframe src
|
|
102
|
+
* that gets loaded. Returns empty string if the tab is not found.
|
|
103
|
+
*/
|
|
104
|
+
export async function getTabIframeUrl(page, tabName) {
|
|
105
|
+
const nameJs = JSON.stringify(tabName);
|
|
106
|
+
const result = await page.evaluate(`
|
|
107
|
+
async () => {
|
|
108
|
+
const tabs = document.querySelectorAll('a[data-url]');
|
|
109
|
+
let target = null;
|
|
110
|
+
for (const tab of tabs) {
|
|
111
|
+
if ((tab.innerText || '').trim() === ${nameJs}) { target = tab; break; }
|
|
112
|
+
}
|
|
113
|
+
if (!target) return '';
|
|
114
|
+
target.click();
|
|
115
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
116
|
+
const iframe = document.getElementById('frame_content-hd') || document.querySelector('iframe');
|
|
117
|
+
return iframe?.src || '';
|
|
118
|
+
}
|
|
119
|
+
`);
|
|
120
|
+
return typeof result === 'string' ? result : '';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse assignments from the current page DOM (the 作业列表 page).
|
|
124
|
+
* The page uses `.ulDiv li` items with status/deadline/score info.
|
|
125
|
+
*/
|
|
126
|
+
export async function parseAssignmentsFromDom(page, courseName) {
|
|
127
|
+
const raw = await page.evaluate(`
|
|
128
|
+
(() => {
|
|
129
|
+
const items = [];
|
|
130
|
+
// Each assignment is a li or div block; try multiple selectors
|
|
131
|
+
const blocks = document.querySelectorAll('.ulDiv li, .work-list-item, .listContent > div, ul > li');
|
|
132
|
+
for (const block of blocks) {
|
|
133
|
+
const text = (block.innerText || '').trim();
|
|
134
|
+
if (!text || text.length < 3) continue;
|
|
135
|
+
// Skip filter buttons and headers
|
|
136
|
+
if (/^(全部|已完成|未完成|筛选)$/.test(text)) continue;
|
|
137
|
+
items.push(text);
|
|
138
|
+
}
|
|
139
|
+
// Fallback: split body text by common patterns
|
|
140
|
+
if (items.length === 0) {
|
|
141
|
+
const body = (document.body?.innerText || '').trim();
|
|
142
|
+
return [body];
|
|
143
|
+
}
|
|
144
|
+
return items;
|
|
145
|
+
})()
|
|
146
|
+
`) ?? [];
|
|
147
|
+
const rows = [];
|
|
148
|
+
for (const text of raw) {
|
|
149
|
+
if (typeof text !== 'string' || text.length < 3)
|
|
150
|
+
continue;
|
|
151
|
+
// Skip noise
|
|
152
|
+
if (/^(全部|已完成|未完成|筛选|暂无|提交的作业将经过)/.test(text))
|
|
153
|
+
continue;
|
|
154
|
+
const lines = text.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
155
|
+
if (!lines.length)
|
|
156
|
+
continue;
|
|
157
|
+
// First meaningful line is the title
|
|
158
|
+
const title = lines[0].replace(/\s+/g, ' ').trim();
|
|
159
|
+
if (!title || /^(全部|已完成|未完成|筛选)$/.test(title))
|
|
160
|
+
continue;
|
|
161
|
+
// Extract status: 未交 / 待批阅 / 已完成 / 已批阅
|
|
162
|
+
const statusMatch = text.match(/(未交|待批阅|已完成|已批阅)/);
|
|
163
|
+
const status = statusMatch?.[1] ?? '';
|
|
164
|
+
// Extract deadline: "剩余XXX" or date pattern
|
|
165
|
+
const remainMatch = text.match(/(剩余[\d天小时分钟秒]+)/);
|
|
166
|
+
const dateMatch = text.match(/(\d{4}[-/.]\d{1,2}[-/.]\d{1,2}(?:\s+\d{1,2}:\d{2})?)/);
|
|
167
|
+
const deadline = remainMatch?.[1] ?? dateMatch?.[1] ?? '';
|
|
168
|
+
// Extract score (exclude "分钟")
|
|
169
|
+
const scoreMatch = text.match(/(\d+(?:\.\d+)?)\s*分(?!钟)/);
|
|
170
|
+
const score = scoreMatch?.[1] ?? '';
|
|
171
|
+
rows.push({ course: courseName, title, deadline, status, score });
|
|
172
|
+
}
|
|
173
|
+
return rows;
|
|
174
|
+
}
|
|
175
|
+
/** Parse exams from the current page DOM (the 考试列表 page). */
|
|
176
|
+
export async function parseExamsFromDom(page, courseName) {
|
|
177
|
+
const raw = await page.evaluate(`
|
|
178
|
+
(() => {
|
|
179
|
+
const items = [];
|
|
180
|
+
const blocks = document.querySelectorAll('.ulDiv li, .exam-list-item, .listContent > div, ul > li');
|
|
181
|
+
for (const block of blocks) {
|
|
182
|
+
const text = (block.innerText || '').trim();
|
|
183
|
+
if (!text || text.length < 3) continue;
|
|
184
|
+
if (/^(全部|已完成|未完成|筛选|暂无)$/.test(text)) continue;
|
|
185
|
+
items.push(text);
|
|
186
|
+
}
|
|
187
|
+
if (items.length === 0) {
|
|
188
|
+
const body = (document.body?.innerText || '').trim();
|
|
189
|
+
return [body];
|
|
190
|
+
}
|
|
191
|
+
return items;
|
|
192
|
+
})()
|
|
193
|
+
`) ?? [];
|
|
194
|
+
// Check for "暂无考试"
|
|
195
|
+
if (raw.length === 1 && typeof raw[0] === 'string' && raw[0].includes('暂无考试')) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const rows = [];
|
|
199
|
+
for (const text of raw) {
|
|
200
|
+
if (typeof text !== 'string' || text.length < 3)
|
|
201
|
+
continue;
|
|
202
|
+
if (/^(全部|已完成|未完成|筛选|暂无)/.test(text))
|
|
203
|
+
continue;
|
|
204
|
+
const lines = text.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
205
|
+
if (!lines.length)
|
|
206
|
+
continue;
|
|
207
|
+
const title = lines[0].replace(/\s+/g, ' ').trim();
|
|
208
|
+
if (!title || /^(全部|已完成|未完成|筛选)$/.test(title))
|
|
209
|
+
continue;
|
|
210
|
+
// Extract dates
|
|
211
|
+
const dates = text.match(/\d{4}[-/.]\d{1,2}[-/.]\d{1,2}\s+\d{1,2}:\d{2}/g) ?? [];
|
|
212
|
+
const start = dates[0] ?? '';
|
|
213
|
+
const end = dates[1] ?? '';
|
|
214
|
+
// Status
|
|
215
|
+
const statusMatch = text.match(/(未开始|进行中|已结束|已完成|未交|待批阅)/);
|
|
216
|
+
let status = statusMatch?.[1] ?? '';
|
|
217
|
+
if (!status && text.includes('剩余'))
|
|
218
|
+
status = '进行中';
|
|
219
|
+
// Score (exclude "分钟")
|
|
220
|
+
const scoreMatch = text.match(/(\d+(?:\.\d+)?)\s*分(?!钟)/);
|
|
221
|
+
const score = scoreMatch?.[1] ?? '';
|
|
222
|
+
rows.push({ course: courseName, title, start, end, status, score });
|
|
223
|
+
}
|
|
224
|
+
return rows;
|
|
225
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { formatTimestamp, workStatusLabel } from './chaoxing.js';
|
|
3
|
+
function localDatePrefixFromMillis(ts) {
|
|
4
|
+
const d = new Date(ts);
|
|
5
|
+
const yyyy = d.getFullYear();
|
|
6
|
+
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
7
|
+
const dd = String(d.getDate()).padStart(2, '0');
|
|
8
|
+
return `${yyyy}-${mm}-${dd}`;
|
|
9
|
+
}
|
|
10
|
+
describe('formatTimestamp', () => {
|
|
11
|
+
it('formats millisecond timestamp', () => {
|
|
12
|
+
const ts = new Date('2026-01-15T00:30:00Z').getTime();
|
|
13
|
+
const result = formatTimestamp(ts);
|
|
14
|
+
expect(result).toMatch(new RegExp(`^${localDatePrefixFromMillis(ts)}\\s`));
|
|
15
|
+
});
|
|
16
|
+
it('formats second timestamp', () => {
|
|
17
|
+
const millis = new Date('2026-06-01T12:00:00Z').getTime();
|
|
18
|
+
const ts = Math.floor(millis / 1000);
|
|
19
|
+
const result = formatTimestamp(ts);
|
|
20
|
+
expect(result).toMatch(new RegExp(`^${localDatePrefixFromMillis(millis)}\\s`));
|
|
21
|
+
});
|
|
22
|
+
it('returns empty for null/undefined/0', () => {
|
|
23
|
+
expect(formatTimestamp(null)).toBe('');
|
|
24
|
+
expect(formatTimestamp(undefined)).toBe('');
|
|
25
|
+
expect(formatTimestamp(0)).toBe('');
|
|
26
|
+
expect(formatTimestamp('')).toBe('');
|
|
27
|
+
});
|
|
28
|
+
it('passes through readable date strings', () => {
|
|
29
|
+
expect(formatTimestamp('2026-03-20 23:59')).toBe('2026-03-20 23:59');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('workStatusLabel', () => {
|
|
33
|
+
it('maps numeric status codes', () => {
|
|
34
|
+
expect(workStatusLabel(0)).toBe('未交');
|
|
35
|
+
expect(workStatusLabel(1)).toBe('已交');
|
|
36
|
+
expect(workStatusLabel(2)).toBe('已批阅');
|
|
37
|
+
});
|
|
38
|
+
it('passes through string status', () => {
|
|
39
|
+
expect(workStatusLabel('已交')).toBe('已交');
|
|
40
|
+
});
|
|
41
|
+
it('returns 未知 for empty/null', () => {
|
|
42
|
+
expect(workStatusLabel(null)).toBe('未知');
|
|
43
|
+
expect(workStatusLabel('')).toBe('未知');
|
|
44
|
+
});
|
|
45
|
+
});
|