-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: CJJ-amateur-programmer <161215070+CJJ-amateur-programmer@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2ae11f4
commit 2d62693
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# BIT-物理实验中心-下载日历 | ||
|
||
在[北京理工大学物理实验选课系统](http://10.133.22.200:7100)上发送并处理网络请求,将课程表下载为 iCalendar 格式(`*.ics`),可供导入一般日历软件。 | ||
|
||
在脚本管理器(如[篡改猴](https://www.tampermonkey.net/))的菜单中可以找到“导出当前物理实验课表”选项,单击即可。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ==UserScript== | ||
// @name BIT-物理实验中心-下载日历 | ||
// @namespace http://tampermonkey.net/ | ||
// @version 0.1.1 | ||
// @description 生成课程表的 iCalendar 文件并下载 | ||
// @license GPL-3.0-or-later | ||
// @supportURL https://github.com/YDX-2147483647/BIT-enhanced/issues | ||
// @author CJJ | ||
// @match http://10.133.22.200:7100/* | ||
// @grant GM_registerMenuCommand | ||
// ==/UserScript== | ||
|
||
(function () { | ||
'use strict' | ||
/* global GM_registerMenuCommand */ | ||
|
||
GM_registerMenuCommand('导出当前物理实验课表', function () { | ||
const xhr = new XMLHttpRequest() | ||
xhr.open('POST', 'http://10.133.22.200:7100/XPK/StuCourseElective/LoadUsedLabCourses', true) | ||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState === 4 && xhr.status === 200) { | ||
let content = | ||
`BEGIN:VCALENDAR | ||
VERSION:2.0 | ||
PRODID:-//BIT-enhanced//PHYEXP// | ||
TZID:Asia/Shanghai | ||
X-WR-CALNAME:物理实验课程表 | ||
` | ||
const downloadLink = document.createElement('a') | ||
const phyexp = JSON.parse(xhr.responseText) | ||
for (let i = 0; i < phyexp.rows.length; i++) { | ||
content += | ||
`BEGIN:VEVENT | ||
SUMMARY:${phyexp.rows[i].CourseName} ${phyexp.rows[i].LabName} | ||
LOCATION:物理实验中心${phyexp.rows[i].ClassRoom} | ||
DESCRIPTION:${phyexp.rows[i].TeacherName} | ${phyexp.rows[i].Weeks}周 ${phyexp.rows[i].WeekName} ${phyexp.rows[i].TimePartName} ${phyexp.rows[i].ClassRoom} 座位号${phyexp.rows[i].SeatNo} | ||
DTSTART:${phyexp.rows[i].ClassDate.replace(/(\w+)\/(\w+)\/(\w+)/, (all, y, m, d) => y + m.padStart(2, '0') + d.padStart(2, '0')).substr(0, 8)}T${phyexp.rows[i].StartTime.replace(':', '')}00 | ||
DTEND:${phyexp.rows[i].ClassDate.replace(/(\w+)\/(\w+)\/(\w+)/, (all, y, m, d) => y + m.padStart(2, '0') + d.padStart(2, '0')).substr(0, 8)}T${phyexp.rows[i].EndTime.replace(':', '')}00 | ||
UID:${phyexp.rows[i].TeacherID}-${phyexp.rows[i].Weeks}-${phyexp.rows[i].TimePartID}-${phyexp.rows[i].LabID}-${phyexp.rows[i].LabClassNo} | ||
END:VEVENT | ||
` | ||
} | ||
content += 'END:VCALENDAR' | ||
downloadLink.href = URL.createObjectURL(new Blob([content], { type: 'text/calendar' })) | ||
downloadLink.download = '物理实验课程表.ics' | ||
downloadLink.click() | ||
} | ||
} | ||
xhr.send('courseID=36&StuIds=' + document.cookie.match(/(?<=COOKIES_KEY_USERNAME=)[0-9]+/)[0] + '&isBatch=0&SemesterID=14&page=1&rows=100') | ||
}) | ||
})() |