// ==UserScript==
// @name HEU课表生成器
// @namespace greasyfork.org/zh-CN/users/816568-chichow5
// @version 0.5
// @home-url https://greasyfork.org/zh-CN/users/816568-chichow5
// @description 哈尔滨工程大学 / HEU course iCalendar generator/ HEU ics格式课表生成器
// @author Chi Chow 201906
// @match *://*.hrbeu.edu.cn/jsxsd/xskb/*
// @grant none
// @downloadURL https://update.greasyfork.icu/scripts/432589/HEU%E8%AF%BE%E8%A1%A8%E7%94%9F%E6%88%90%E5%99%A8.user.js
// @updateURL https://update.greasyfork.icu/scripts/432589/HEU%E8%AF%BE%E8%A1%A8%E7%94%9F%E6%88%90%E5%99%A8.meta.js
// ==/UserScript==
'use strict';
var mp = [];
var courses = [];
var type;
var alarm = -1;
var reminder = -1;
var box;
var year, month, day;
class Course{
constructor(raw, w, tweek){
this.weekday = w
this.name = raw[0]
if(raw[1].endsWith('\(周\)')){
this.teacher = raw[0]
let t = raw[1].indexOf('-')
if (t === -1){
this.start_week = this.end_week = parseInt(raw[1])
}else{
this.start_week = parseInt(raw[1].substring(0, t))
this.end_week = parseInt(raw[1].substring(t+1))
}
t = raw[2].substring(0, raw[2].length-2)
this.start_time = parseInt(t.substring(1, 3))
this.end_time = parseInt(t.substring(t.length-2))
this.location = raw[3]
this.flag = (this.start_time === this.end_time && this.start_time === 1);
this.wasted = false;
}
else{
this.teacher = raw[1]
let t = tweek.indexOf('-')
if (t === -1){
this.start_week = this.end_week = parseInt(tweek)
}else{
this.start_week = parseInt(tweek.substring(0, t))
this.end_week = parseInt(tweek.substring(t+1))
}
t = raw[3].substring(0, raw[3].length-2)
this.start_time = parseInt(t.substring(1, 3))
this.end_time = parseInt(t.substring(t.length-2))
this.location = raw[4]
this.flag = (this.start_time === this.end_time && this.start_time === 1);
this.wasted = false;
}
}
show(){
return 'Week:' + this.weekday + '\n'
+ 'Name:' + this.name + '\n'
+ 'Teac:' + this.teacher + '\n'
+ 'Dura:' + this.start_week + '-' + this.end_week + '\n'
+ 'Time:' + this.start_time + '-' + this.end_time + '\n'
+ 'Loca:' + this.location + '\n';
}
generateEvent(){
let result = ""
+ "BEGIN:VEVENT\r\n"
+ "CATEGORIES:课程\r\n";
let det = 7 * this.start_week + this.weekday - 8;
result += "DTSTART;TZID=Asia/Shanghai:" + mp[det]
+ getStartTime(type, this.start_time, this.end_time) + '\r\n';
result += "DTEND;TZID=Asia/Shanghai:" + mp[det]
+ getEndTime(type, this.start_time, this.end_time) + '\r\n';
//result += "UID:" + uuidv4()+'\r\n';
//result += "DTSTAMP:20210919T111500Z\r\n"
if (this.start_week != this.end_week){
result += ""
+ "RRULE:FREQ=WEEKLY;WKST=MO;COUNT="
+ (this.end_week-this.start_week+1)
+ ";BYDAY=" + getWeekEn(this.weekday)+'\r\n';
}
result += ""
+ "DESCRIPTION:"+this.teacher+'\r\n'
+ "LOCATION:"+this.location+'\r\n'
+ "SUMMARY:"+this.name+'\r\n';
result += ""
+ "SEQUENCE:0\r\n"
+ "TRANSP:OPAQUE\r\n";
if (reminder != -1){
result += ""
+ "BEGIN:VALARM\r\n"
//+ "X-WR-ALARMUID:" + uuidv4()+'\r\n'
+ "TRIGGER:-PT" + reminder + "M\r\n"
+ "ACTION:DISPLAY\r\n"
+ "DESCRIPTION:" + this.location + " "+ this.name + "\r\n"
+ "END:VALARM\r\n";
}
if (alarm != -1){
result += ""
+ "BEGIN:VALARM\r\n"
+ "TRIGGER:-PT" + alarm + "M\r\n"
+ "ACTION:AUDIO\r\n"
+ "END:VALARM\r\n"
}
result += "END:VEVENT\r\n";
return result;
}
}
UI();
function doit(){
/*初始化重新读入*/
alarm = -1;
reminder = -1;
let re = getParam();
//console.log(alarm);
if (re === false){
console.log('param get error');
return;
}
let ics = generateCalendar();
let ele = document.createElement('a');
ele.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(ics));
ele.setAttribute('download', 'output.ics');
ele.style.display = 'none';
box.appendChild(ele);
alert("课表不保证完全正确,请导入到新建的日历表中,便于管理");
ele.click();
box.removeChild(ele);
}
function UI(){
if (document.getElementById('kbtable') == null) return;
box = document.createElement('div');
box.id = 'myAlertBox';
box.innerHTML += '请输入当前学期第一周周一的年月日
'
+ ' '
+ ' '
+ ' '
+ '