-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBIT-本硕博一体化-课表.user.js
73 lines (65 loc) · 2.6 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ==UserScript==
// @name BIT-本硕博一体化-课表
// @namespace http://tampermonkey.net/
// @version 0.3.1
// @description 去除课表中的“本”、课程及教学班编号、星期等以简化信息
// @license GPL-3.0-or-later
// @supportURL https://github.com/YDX-2147483647/BIT-enhanced/issues
// @author Y.D.X.
// @match http://jxzxehallapp.bit.edu.cn/jwapp/sys/wdkbby/*
// @match https://jxzxehallapp.bit.edu.cn/jwapp/sys/wdkbby/*
// @grant none
// ==/UserScript==
(function () {
'use strict'
// interval's unit: ms.
function wait_until_presence (selector, interval) {
return new Promise((resolve, reject) => {
const check = setInterval(function () {
if (document.querySelector(selector)) {
clearInterval(check)
resolve(document.querySelector(selector))
}
}, interval)
})
}
function shrink_titles () {
// 这里选出来的是每节课中的“本”或“研”字
// 根据 weekUnitTableInfo.js ,存在漏选的理论可能性
document.querySelectorAll('.mtt_item_kcmc > span.mtt_item_bybz').forEach(icon => {
// 课程名称
const course_name = icon.parentNode
course_name.textContent = icon.nextSibling.textContent.replace(
/^\d{8,9}\s(.+)\[(\d{2}|\d{9})\]$/, '$1')
// 课程详细信息
const course_detail = course_name.parentNode.querySelector('.mtt_item_room')
course_detail.textContent =
course_detail.textContent
.replace(/(良乡|中关村)校区,?/, '')
.replace(/星期[\d一二三四五六日],/, '')
.replace('节-第', '-')
// 例:第8节-第10节 -> 第8-10节
})
}
function wait_and_shrink_titles () {
wait_until_presence('#kcb_container', 200).then(shrink_titles)
}
wait_until_presence('#kcb_container', 1000).then(function () {
shrink_titles()
// 周/学期课表切换栏
const change_buttons_selectors = [
'i.icon-keyboardarrowleft', 'i.icon-keyboardarrowright',
"[data-action='周课表学年学期']", "[data-action='周课表周课表']"
]
for (const s of change_buttons_selectors) {
document.querySelector(s).addEventListener('click', wait_and_shrink_titles)
}
})
wait_until_presence("#dqxnxq2 + a[data-action='更改2']", 1000).then(button => {
// 更改学期时的对话框是每次现画的……所以每次更改都要加
button.addEventListener('click', function () {
document.querySelector('#buttons > button.bh-btn-primary').addEventListener(
'click', wait_and_shrink_titles)
})
})
})()