-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBIT-物理实验中心-下载日历.user.js
52 lines (50 loc) · 2.4 KB
/
BIT-物理实验中心-下载日历.user.js
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
// ==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')
})
})()