zjsru_01.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. // 浙江树人学院(浙江树人大学)拾光课程表适配脚本
  2. // 学校: 浙江树人学院 / 浙江树人大学 (zjsru.edu.cn, ZJSRU)
  3. // 教务: xk.jwc.zjsru.edu.cn —— 正方教务 ASP.NET WebForms 版(xskbcx.aspx 学生个人课表)
  4. // 登录: 统一身份认证 CAS (rz.zjsru.edu.cn),教务首页会自动跳转
  5. //
  6. // 与 SHUFEZJ / UJS 的正方适配不同:这里是 WebForms 版,课表为服务端渲染的 HTML 表格
  7. // (table#Table1.schedule),单元格以 <br> 分行、且一格可能并排多门课,故按「周X第N节」
  8. // 锚点切分;学年/学期是服务端控件,切换需要 __EVENTTARGET 回发。
  9. // 软件是在点击「执行导入」时把脚本注入当前页执行一次,CAS 登录后一般停在教务首页,
  10. // 因此脚本会在同域内自行拉取课表页取数。
  11. //
  12. // 作息时间取自学校官方校历底部《上课时间表》
  13. // (https://www.zjsru.edu.cn/info/1411/54428.htm),拱宸桥 / 杨汛桥两校区不同,
  14. // 导入时由用户选择,见 ZJSRU_CAMPUS_TIME_SLOTS。
  15. //
  16. // 取数基址由 location.pathname 推导,因此若用户经 WebVPN 打开教务(页面地址形如
  17. // /https/webvpn<hash>/xskbcx.aspx),脚本同样可以正常工作。
  18. //
  19. // 参考: SUDA(同为 table#Table1.schedule 结构);多校区作息参照 GDPU / HNSF
  20. // Author: CagierAsh123
  21. // ========================== 常量 ==========================
  22. // 课表页里「周X第N节{周次}」这一行的形态
  23. const ZJSRU_PERIOD_RE = /^周([一二三四五六日天])第([0-9]+(?:,[0-9]+)*)节(?:\{([^}]*)\})?$/;
  24. const ZJSRU_DAY_MAP = { "一": 1, "二": 2, "三": 3, "四": 4, "五": 5, "六": 6, "日": 7, "天": 7 };
  25. const ZJSRU_TERM_NAMES = { "1": "第1学期", "2": "第2学期", "3": "第3学期(短)" };
  26. const ZJSRU_TABLE_SELECTOR = "table#Table1.schedule";
  27. const ZJSRU_MIN_TOTAL_WEEKS = 18; // 学期总周数下限,避免个别短课表把学期截断
  28. // ========================== 作息时间(来源:学校官方校历) ==========================
  29. // https://www.zjsru.edu.cn/info/1411/54428.htm 底部《上课时间表》
  30. // 注:杨汛桥校区不设第五节。软件的作息校验要求节次必须从 1 起连续编号
  31. // (validateTimeSlotsOrThrow),否则导入会直接报错;而教务系统给杨汛桥
  32. // 学生排课时仍按全校统一节次返回(下午第一节就是「第六节」,并未坍缩为
  33. // -1 或重编号),所以这里虚拟一个第 5 节占位以保持节次连续,
  34. // 使第六节仍然落在 6 号上。
  35. const ZJSRU_CAMPUS_TIME_SLOTS = {
  36. gongchenqiao: {
  37. label: "拱宸桥校区",
  38. slots: [
  39. { number: 1, startTime: "08:10", endTime: "08:50" },
  40. { number: 2, startTime: "09:00", endTime: "09:40" },
  41. { number: 3, startTime: "09:55", endTime: "10:35" },
  42. { number: 4, startTime: "10:45", endTime: "11:25" },
  43. { number: 5, startTime: "11:35", endTime: "12:15" },
  44. { number: 6, startTime: "13:30", endTime: "14:10" },
  45. { number: 7, startTime: "14:20", endTime: "15:00" },
  46. { number: 8, startTime: "15:10", endTime: "15:50" },
  47. { number: 9, startTime: "16:00", endTime: "16:40" },
  48. { number: 10, startTime: "18:10", endTime: "18:50" },
  49. { number: 11, startTime: "19:00", endTime: "19:40" },
  50. { number: 12, startTime: "19:50", endTime: "20:30" }
  51. ]
  52. },
  53. yangxunqiao: {
  54. label: "杨汛桥校区",
  55. slots: [
  56. { number: 1, startTime: "08:30", endTime: "09:10" },
  57. { number: 2, startTime: "09:15", endTime: "09:55" },
  58. { number: 3, startTime: "10:10", endTime: "10:50" },
  59. { number: 4, startTime: "10:55", endTime: "11:35" },
  60. { number: 5, startTime: "11:35", endTime: "12:15" },
  61. { number: 6, startTime: "13:30", endTime: "14:10" },
  62. { number: 7, startTime: "14:15", endTime: "14:55" },
  63. { number: 8, startTime: "15:05", endTime: "15:45" },
  64. { number: 9, startTime: "15:50", endTime: "16:30" },
  65. { number: 10, startTime: "18:00", endTime: "18:40" },
  66. { number: 11, startTime: "18:45", endTime: "19:25" },
  67. { number: 12, startTime: "19:30", endTime: "20:10" }
  68. ]
  69. }
  70. };
  71. // ========================== 表格解析 ==========================
  72. /**
  73. * 取出单元格的文本行。正方的课程信息用 <br> 分行,需要先把 <br> 还原成换行。
  74. */
  75. function zjsruCellLines(cell) {
  76. const doc = cell.ownerDocument || document;
  77. const html = (cell.innerHTML || "").replace(/<br\s*\/?>/gi, "\n");
  78. const tmp = doc.createElement("div");
  79. tmp.innerHTML = html;
  80. return (tmp.textContent || "")
  81. .split("\n")
  82. .map(s => s.replace(/\s+/g, " ").trim())
  83. .filter(Boolean);
  84. }
  85. /**
  86. * 解析花括号里的周次,兼容:
  87. * "第2-18周" / "第9-9周" / "第3-17周|单周" / "第2-18周|双周" / "第1-5,7-9周"
  88. * 返回升序去重后的周次数组。
  89. */
  90. function zjsruParseWeeks(brace) {
  91. if (!brace) return [];
  92. const weeks = new Set();
  93. const odd = /\|?\s*单周/.test(brace);
  94. const even = /\|?\s*双周/.test(brace);
  95. const body = brace.split("|")[0].replace(/第/g, "").replace(/周/g, "");
  96. for (const seg of body.split(",")) {
  97. const part = seg.trim();
  98. if (!part) continue;
  99. const range = part.match(/(\d+)\s*[-~-—]\s*(\d+)/);
  100. let start, end;
  101. if (range) {
  102. start = parseInt(range[1], 10);
  103. end = parseInt(range[2], 10);
  104. } else {
  105. const single = part.match(/(\d+)/);
  106. if (!single) continue;
  107. start = end = parseInt(single[1], 10);
  108. }
  109. if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
  110. if (start > end) [start, end] = [end, start];
  111. if (end > 60) end = 60; // 防御异常数据
  112. for (let w = start; w <= end; w++) {
  113. if (odd && w % 2 === 0) continue;
  114. if (even && w % 2 === 1) continue;
  115. weeks.add(w);
  116. }
  117. }
  118. return [...weeks].sort((a, b) => a - b);
  119. }
  120. /**
  121. * 解析一个单元格里的所有课程。
  122. * 结构: 课程名 / 周X第N节{周次} / 教师 / 教室 [/ 附加信息...],多门课依次排列。
  123. * 星期取自课程自身的「周X」,不依赖表格列序,列布局变化也不会错位。
  124. */
  125. function zjsruParseCell(cell) {
  126. const lines = zjsruCellLines(cell);
  127. const anchors = [];
  128. for (let i = 0; i < lines.length; i++) {
  129. if (ZJSRU_PERIOD_RE.test(lines[i])) anchors.push(i);
  130. }
  131. const courses = [];
  132. for (let a = 0; a < anchors.length; a++) {
  133. const k = anchors[a];
  134. const name = (lines[k - 1] || "").trim();
  135. if (!name) continue;
  136. const m = lines[k].match(ZJSRU_PERIOD_RE);
  137. if (!m) continue;
  138. const day = ZJSRU_DAY_MAP[m[1]];
  139. if (!day) continue;
  140. const sections = m[2].split(",").map(s => parseInt(s, 10)).filter(Number.isFinite);
  141. if (!sections.length) continue;
  142. const weeks = zjsruParseWeeks(m[3]);
  143. if (!weeks.length) continue;
  144. // 本门课的附加行:下一门课的课名行为界
  145. const stop = (a + 1 < anchors.length) ? anchors[a + 1] - 1 : lines.length;
  146. const rest = lines.slice(k + 1, stop);
  147. courses.push({
  148. name: name,
  149. teacher: (rest[0] || "").trim(),
  150. position: (rest[1] || "").trim(),
  151. day: day,
  152. startSection: Math.min(...sections),
  153. endSection: Math.max(...sections),
  154. weeks: weeks
  155. });
  156. }
  157. return courses;
  158. }
  159. /**
  160. * 解析整个课表表格。正方的 rowspan 单元格在 DOM 里只属于一行,
  161. * 直接遍历所有 td 不会重复;星期由每门课自己的「周X」决定。
  162. */
  163. function zjsruParseTable(table) {
  164. const courses = [];
  165. for (const cell of table.querySelectorAll("td")) {
  166. for (const c of zjsruParseCell(cell)) courses.push(c);
  167. }
  168. return mergeAndDistinctCourses(courses);
  169. }
  170. /**
  171. * 节次与周次合并去重。
  172. * 直接取自 wiki《课程合并与去重函数》提供的参考实现,未做改动:
  173. * https://github.com/XingHeYuZhuan/shiguangschedule/wiki/课程合并与去重函数
  174. */
  175. function mergeAndDistinctCourses(courses) {
  176. if (!Array.isArray(courses) || courses.length <= 1) return courses;
  177. const list = courses.map(c => ({
  178. ...c,
  179. name: c.name || '',
  180. teacher: c.teacher || '',
  181. position: c.position || '',
  182. weeks: Array.isArray(c.weeks) ? [...c.weeks].sort((a, b) => a - b) : []
  183. }));
  184. list.sort((a, b) => {
  185. return a.name.localeCompare(b.name) ||
  186. a.teacher.localeCompare(b.teacher) ||
  187. a.position.localeCompare(b.position) ||
  188. (a.day || 0) - (b.day || 0) ||
  189. a.weeks.join(',').localeCompare(b.weeks.join(',')) ||
  190. (a.startSection || 0) - (b.startSection || 0);
  191. });
  192. const step1Merged = [];
  193. let current = list[0];
  194. for (let i = 1; i < list.length; i++) {
  195. const next = list[i];
  196. const isSameCourseAndWeeks =
  197. current.name === next.name &&
  198. current.teacher === next.teacher &&
  199. current.position === next.position &&
  200. current.day === next.day &&
  201. current.weeks.join(',') === next.weeks.join(',');
  202. const isContinuous = current.endSection + 1 === next.startSection;
  203. const isDuplicate = current.startSection === next.startSection && current.endSection === next.endSection;
  204. if (isSameCourseAndWeeks && isContinuous) {
  205. current.endSection = next.endSection;
  206. } else if (isSameCourseAndWeeks && isDuplicate) {
  207. continue;
  208. } else {
  209. step1Merged.push(current);
  210. current = next;
  211. }
  212. }
  213. step1Merged.push(current);
  214. step1Merged.sort((a, b) => {
  215. return a.name.localeCompare(b.name) ||
  216. a.teacher.localeCompare(b.teacher) ||
  217. a.position.localeCompare(b.position) ||
  218. (a.day || 0) - (b.day || 0) ||
  219. (a.startSection || 0) - (b.startSection || 0) ||
  220. (a.endSection || 0) - (b.endSection || 0);
  221. });
  222. const step2Merged = [];
  223. let cur = step1Merged[0];
  224. for (let i = 1; i < step1Merged.length; i++) {
  225. const nxt = step1Merged[i];
  226. const isSameCourseAndSection =
  227. cur.name === nxt.name &&
  228. cur.teacher === nxt.teacher &&
  229. cur.position === nxt.position &&
  230. cur.day === nxt.day &&
  231. cur.startSection === nxt.startSection &&
  232. cur.endSection === nxt.endSection;
  233. if (isSameCourseAndSection) {
  234. cur.weeks = Array.from(new Set([...cur.weeks, ...nxt.weeks])).sort((a, b) => a - b);
  235. } else {
  236. step2Merged.push(cur);
  237. cur = nxt;
  238. }
  239. }
  240. step2Merged.push(cur);
  241. return step2Merged;
  242. }
  243. // ========================== 页面定位与取数 ==========================
  244. /**
  245. * 查找课表表格,兼容直接打开课表页与同源 iframe 嵌套
  246. */
  247. function zjsruFindTable(doc) {
  248. doc = doc || document;
  249. let table = doc.querySelector(ZJSRU_TABLE_SELECTOR);
  250. if (table) return table;
  251. for (const iframe of doc.querySelectorAll("iframe")) {
  252. try {
  253. const inner = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
  254. if (!inner) continue;
  255. table = inner.querySelector(ZJSRU_TABLE_SELECTOR);
  256. if (table) return table;
  257. } catch (_) { /* 跨域忽略 */ }
  258. }
  259. return null;
  260. }
  261. /**
  262. * 识别学号:优先取当前 URL 的 xh 参数,其次找教务首页菜单里的 xh=xxxx 链接。
  263. */
  264. function zjsruDetectStudentId(doc) {
  265. doc = doc || document;
  266. try {
  267. const fromUrl = new URLSearchParams(location.search).get("xh");
  268. if (fromUrl && /^\d{4,}$/.test(fromUrl.trim())) return fromUrl.trim();
  269. } catch (_) { /* ignore */ }
  270. for (const a of doc.querySelectorAll("a[href*='xh=']")) {
  271. const m = (a.getAttribute("href") || "").match(/[?&]xh=(\d{4,})/);
  272. if (m) return m[1];
  273. }
  274. const m2 = (doc.documentElement ? doc.documentElement.innerHTML : "").match(/[?&]xh=(\d{4,})/);
  275. return m2 ? m2[1] : "";
  276. }
  277. /**
  278. * 课表页地址。基址取自当前路径,因此校内直连与 WebVPN 代理路径都适用。
  279. */
  280. function zjsruScheduleUrl(studentId) {
  281. const base = location.origin + location.pathname.replace(/[^/]*$/, "");
  282. const qs = studentId ? ("?xh=" + encodeURIComponent(studentId) + "&type=1") : "?type=1";
  283. return new URL("xskbcx.aspx" + qs, base).toString();
  284. }
  285. async function zjsruFetchDoc(url) {
  286. const res = await fetch(url, { method: "GET", credentials: "include" });
  287. if (!res.ok) return null;
  288. const html = await res.text();
  289. return new DOMParser().parseFromString(html, "text/html");
  290. }
  291. /**
  292. * 读取课表页上的学年/学期下拉项
  293. */
  294. function zjsruReadTermOptions(doc) {
  295. const yearSel = doc.querySelector("select#xnd");
  296. const termSel = doc.querySelector("select#xqd");
  297. if (!yearSel || !termSel) return null;
  298. const years = [...yearSel.options].map(o => o.value).filter(v => v);
  299. const terms = [...termSel.options].map(o => o.value).filter(v => v);
  300. if (!years.length || !terms.length) return null;
  301. const combos = [];
  302. for (const y of years) {
  303. for (const t of terms) combos.push({ year: y, term: t });
  304. }
  305. const current = combos.findIndex(c => c.year === yearSel.value && c.term === termSel.value);
  306. return { combos: combos, currentIndex: current < 0 ? 0 : current };
  307. }
  308. /**
  309. * 切换学年/学期:正方用 __EVENTTARGET 回发,必须带上当前页的 __VIEWSTATE
  310. */
  311. async function zjsruFetchTermDoc(url, doc, year, term) {
  312. const pick = (name) => {
  313. const el = doc.querySelector("input[name='" + name + "']");
  314. return el ? el.value : "";
  315. };
  316. const body = new URLSearchParams();
  317. body.set("__EVENTTARGET", "xnd");
  318. body.set("__EVENTARGUMENT", "");
  319. body.set("__LASTFOCUS", "");
  320. body.set("__VIEWSTATE", pick("__VIEWSTATE"));
  321. body.set("__VIEWSTATEGENERATOR", pick("__VIEWSTATEGENERATOR"));
  322. body.set("xnd", year);
  323. body.set("xqd", term);
  324. const res = await fetch(url, {
  325. method: "POST",
  326. credentials: "include",
  327. headers: { "Content-Type": "application/x-www-form-urlencoded" },
  328. body: body.toString()
  329. });
  330. if (!res.ok) return null;
  331. const html = await res.text();
  332. return new DOMParser().parseFromString(html, "text/html");
  333. }
  334. // ========================== 业务步骤 ==========================
  335. /**
  336. * 公告与前置确认
  337. */
  338. async function zjsruPromptUserToStart() {
  339. return await window.shiguangBridgePromise.showAlert(
  340. "浙江树人学院 · 教务导入",
  341. "请先在本页面完成统一身份认证(CAS)登录。\n\n"
  342. + "导入时会自动拉取「学生个人课表」,并识别可选的学年/学期供你选择,"
  343. + "不需要手动打开课表页。",
  344. "我已登录,开始导入"
  345. );
  346. }
  347. /**
  348. * 定位课表:当前页就是课表页则直接用,否则在同域内自行拉取
  349. * @returns {Promise<{doc: Document, table: Element, url: string}|null>}
  350. */
  351. async function zjsruLocateSchedule() {
  352. const table = zjsruFindTable(document);
  353. if (table) return { doc: document, table: table, url: "" };
  354. if (!/(^|\.)zjsru\.edu\.cn$/.test(location.hostname)) {
  355. window.shiguangBridge.showToast("当前不在浙江树人学院教务系统页面,请先登录教务系统。");
  356. return null;
  357. }
  358. window.shiguangBridge.showToast("正在获取课表页面...");
  359. const url = zjsruScheduleUrl(zjsruDetectStudentId(document));
  360. const doc = await zjsruFetchDoc(url);
  361. if (!doc) {
  362. window.shiguangBridge.showToast("课表页请求失败,请检查登录状态或网络环境。");
  363. return null;
  364. }
  365. const fetchedTable = zjsruFindTable(doc);
  366. if (!fetchedTable) {
  367. window.shiguangBridge.showToast("未获取到课表,请确认已登录统一身份认证(CAS)。");
  368. return null;
  369. }
  370. return { doc: doc, table: fetchedTable, url: url };
  371. }
  372. /**
  373. * 选择并切换到目标学年/学期(默认当前学期)
  374. * @returns {Promise<{doc: Document, table: Element, url: string}|null>}
  375. */
  376. async function zjsruChooseTerm(schedule) {
  377. const termInfo = zjsruReadTermOptions(schedule.doc);
  378. if (!termInfo || termInfo.combos.length <= 1) return schedule;
  379. const labels = termInfo.combos.map(c =>
  380. c.year + " 学年 " + (ZJSRU_TERM_NAMES[c.term] || ("第" + c.term + "学期")));
  381. const picked = await window.shiguangBridgePromise.showSingleSelection(
  382. "选择要导入的学期",
  383. JSON.stringify(labels),
  384. termInfo.currentIndex
  385. );
  386. if (picked === null || picked === undefined || picked < 0) {
  387. window.shiguangBridge.showToast("导入已取消。");
  388. return null;
  389. }
  390. const target = termInfo.combos[picked];
  391. const shownYear = (schedule.doc.querySelector("select#xnd") || {}).value;
  392. const shownTerm = (schedule.doc.querySelector("select#xqd") || {}).value;
  393. if (target.year === shownYear && target.term === shownTerm) return schedule;
  394. window.shiguangBridge.showToast("正在切换到 " + labels[picked] + "...");
  395. const pageUrl = schedule.url || (location.origin + location.pathname + location.search);
  396. const switched = await zjsruFetchTermDoc(pageUrl, schedule.doc, target.year, target.term);
  397. const switchedTable = switched ? zjsruFindTable(switched) : null;
  398. if (!switchedTable) {
  399. window.shiguangBridge.showToast("切换学期失败,请稍后重试。");
  400. return null;
  401. }
  402. return { doc: switched, table: switchedTable, url: schedule.url };
  403. }
  404. /**
  405. * 选择所在校区(决定导入哪一套作息时间)
  406. * @returns {Promise<string|null>} 校区 key
  407. */
  408. async function zjsruSelectCampus() {
  409. const keys = Object.keys(ZJSRU_CAMPUS_TIME_SLOTS);
  410. const labels = keys.map(k => ZJSRU_CAMPUS_TIME_SLOTS[k].label);
  411. const idx = await window.shiguangBridgePromise.showSingleSelection(
  412. "选择所在校区",
  413. JSON.stringify(labels),
  414. 0
  415. );
  416. if (idx === null || idx === undefined || idx < 0 || idx >= keys.length) {
  417. window.shiguangBridge.showToast("导入已取消,未选择校区。");
  418. return null;
  419. }
  420. return keys[idx];
  421. }
  422. /**
  423. * 提交课程数据
  424. */
  425. async function zjsruSaveCourses(courses) {
  426. window.shiguangBridge.showToast("正在保存 " + courses.length + " 条课程...");
  427. try {
  428. await window.shiguangBridgePromise.saveImportedCourses(JSON.stringify(courses));
  429. return true;
  430. } catch (error) {
  431. window.shiguangBridge.showToast("课程保存失败: " + error.message);
  432. return false;
  433. }
  434. }
  435. /**
  436. * 提交课表配置。学期开始日期留空:各学期开学日不是固定公式,
  437. * 写死会导致整张课表周次偏移,交由用户在软件内设置。
  438. */
  439. async function zjsruSaveConfig(courses) {
  440. const maxWeek = courses.reduce((mx, c) => Math.max(mx, ...c.weeks), 0);
  441. const config = {
  442. semesterStartDate: null,
  443. semesterTotalWeeks: Math.max(ZJSRU_MIN_TOTAL_WEEKS, maxWeek)
  444. };
  445. try {
  446. await window.shiguangBridgePromise.saveCourseConfig(JSON.stringify(config));
  447. } catch (error) {
  448. console.error("JS: 保存课表配置失败:", error);
  449. }
  450. }
  451. /**
  452. * 提交所选校区的作息时间
  453. */
  454. async function zjsruImportTimeSlots(campusKey) {
  455. const campus = ZJSRU_CAMPUS_TIME_SLOTS[campusKey];
  456. if (!campus) return;
  457. window.shiguangBridge.showToast("正在导入" + campus.label + "作息时间...");
  458. try {
  459. await window.shiguangBridgePromise.savePresetTimeSlots(JSON.stringify(campus.slots));
  460. console.log("JS: 已导入 " + campus.label + " 作息 " + campus.slots.length + " 节");
  461. } catch (error) {
  462. window.shiguangBridge.showToast("作息时间导入失败: " + error.message);
  463. }
  464. }
  465. // ========================== 主流程 ==========================
  466. async function runImportFlow() {
  467. // 1. 公告与前置确认
  468. const confirmed = await zjsruPromptUserToStart();
  469. if (!confirmed) {
  470. window.shiguangBridge.showToast("用户取消了导入。");
  471. return;
  472. }
  473. // 2. 定位课表页
  474. const schedule = await zjsruLocateSchedule();
  475. if (!schedule) return;
  476. // 3. 选择学期
  477. const chosen = await zjsruChooseTerm(schedule);
  478. if (!chosen) return;
  479. // 4. 选择校区
  480. const campusKey = await zjsruSelectCampus();
  481. if (!campusKey) return;
  482. // 5. 解析课程
  483. const courses = zjsruParseTable(chosen.table);
  484. console.log("JS: 解析到 " + courses.length + " 条课程记录");
  485. if (courses.length === 0) {
  486. window.shiguangBridge.showToast("未解析到任何课程,该学期可能没有排课。");
  487. return;
  488. }
  489. // 6. 保存课程
  490. const saved = await zjsruSaveCourses(courses);
  491. if (!saved) return;
  492. // 7. 保存课表配置
  493. await zjsruSaveConfig(courses);
  494. // 8. 导入作息时间(失败不阻断整体流程)
  495. await zjsruImportTimeSlots(campusKey);
  496. // 9. 流程完全成功
  497. window.shiguangBridge.showToast("课程导入成功,共导入 " + courses.length + " 条课程!");
  498. window.shiguangBridge.notifyTaskCompletion();
  499. }
  500. runImportFlow();