Last active
August 29, 2015 14:13
-
-
Save hepesu/dd099d1c7ebf2548d5a2 to your computer and use it in GitHub Desktop.
厦门大学教务系统课程表导出
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
//For ssfw.xmu.edu.cn | |
console.log(function (window, document) { | |
return ['BEGIN:VCALENDAR\nPRODID:-//Google Inc//Google Calendar 70.9054//EN\nVERSION:2.0\n'].concat([] | |
//Get target | |
.slice.call(document.querySelectorAll('div')) | |
.filter(function (el) { | |
return el.className.indexOf('fcSpanDiv') > -1; | |
}) | |
//Extract content | |
.map(function (el) { | |
return { | |
rowIndex : el.parentNode.parentNode.parentNode.rowIndex, | |
cellIndex : el.parentNode.parentNode.cellIndex, | |
content : el.parentNode.parentNode.innerText | |
}; | |
}) | |
//Play with content | |
.map(function (el) { | |
//TODO:Enter start date of term(monday) !! | |
var startDateCode = "2014-06-30"; | |
var chunkSize = 4, | |
content = el.content.trim().split('\n'); | |
function patternDate(date, fmt) { | |
var o = { | |
"M+" : date.getMonth() + 1, //月份 | |
"d+" : date.getDate(), //日 | |
"h+" : date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, //小时 | |
"H+" : date.getHours(), //小时 | |
"m+" : date.getMinutes(), //分 | |
"s+" : date.getSeconds(), //秒 | |
"q+" : Math.floor((date.getMonth() + 3) / 3), //季度 | |
"S" : date.getMilliseconds() //毫秒 | |
}; | |
var week = { | |
"0" : "\u65e5", | |
"1" : "\u4e00", | |
"2" : "\u4e8c", | |
"3" : "\u4e09", | |
"4" : "\u56db", | |
"5" : "\u4e94", | |
"6" : "\u516d" | |
}; | |
if (/(y+)/.test(fmt)) { | |
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); | |
} | |
if (/(E+)/.test(fmt)) { | |
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "\u661f\u671f" : "\u5468") : "") + week[date.getDay() + ""]); | |
} | |
for (var k in o) { | |
if (new RegExp("(" + k + ")").test(fmt)) { | |
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); | |
} | |
} | |
return fmt; | |
}; | |
function getCourseTime(courseTimeCode, isEnd) { | |
var timeTMP = { | |
1 : new Date().setHours(0, 0, 0), | |
2 : new Date().setHours(0, 55, 0), | |
3 : new Date().setHours(2, 10, 0), | |
4 : new Date().setHours(3, 05, 0), | |
5 : new Date().setHours(6, 30, 0), | |
6 : new Date().setHours(7, 25, 0), | |
7 : new Date().setHours(8, 40, 0), | |
8 : new Date().setHours(9, 35, 0), | |
9 : new Date().setHours(11, 10, 0), | |
10 : new Date().setHours(12, 05, 0), | |
11 : new Date().setHours(13, 00, 0), | |
} | |
[courseTimeCode]; | |
if (!isEnd) | |
return patternDate(new Date(timeTMP), 'HHmmss'); | |
else | |
return patternDate(new Date(timeTMP + 2700000), 'HHmmss'); | |
}; | |
return [] | |
.concat.apply([], content.map(function (elem, i) { | |
return i % chunkSize ? [] : [content.slice(i, i + chunkSize)]; | |
})) | |
.map(function (_el) { | |
var weekDay = el.cellIndex - 1, | |
weekDaySymbol = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'][weekDay], | |
courseWeekCode = /(\d+)-(\d+)周/.exec(_el[2]) || [0, 1, 1], | |
courseTimeCode = /(\d+)-(\d+)节/.exec(_el[2]) || [0, 1, 1], | |
startDate = patternDate(new Date(new Date(startDateCode).getTime() + (weekDay - 1) * 86400000 + (courseWeekCode[1] - 1) * 7 * 86400000), "yyyyMMdd"); | |
return ['BEGIN:VEVENT\nDESCRIPTION:', | |
'DTEND:' + startDate + 'T' + getCourseTime(courseTimeCode[2], true) + 'Z', | |
'DTSTART:' + startDate + 'T' + getCourseTime(courseTimeCode[1]) + 'Z', | |
'DTSTAMP:' + startDate + 'T' + getCourseTime(courseTimeCode[1]) + 'Z', | |
'LOCATION:' + _el[3], | |
'SUMMARY:' + _el[0] + "(" + _el[1] + ")", | |
'RRULE:FREQ=WEEKLY;BYDAY=' + weekDaySymbol + ';INTERVAL=' + 1 + ';COUNT=' + courseWeekCode[2], | |
'TRANSP:OPAQUE\nEND:VEVENT\n'].join('\n'); | |
}) | |
.join('\n'); | |
})) | |
.concat('END:VCALENDAR') | |
.join('\n') | |
}(window, document)); | |
//For bkxk.xmu.edu.cn | |
console.log(function (window, document) { | |
return ['BEGIN:VCALENDAR\nPRODID:-//Google Inc//Google Calendar 70.9054//EN\nVERSION:2.0\n'].concat([] | |
//Get target | |
.slice.call(document.querySelectorAll('#xskbTable td')) | |
.filter(function (el) { | |
return el.innerText.trim().length > 4; | |
}) | |
//Extract content | |
.map(function (el) { | |
return { | |
rowIndex : el.parentNode.rowIndex, | |
cellIndex : el.cellIndex, | |
content : el.innerText | |
}; | |
}) | |
//Play with content | |
.map(function (el) { | |
//TODO:Enter start date of term(monday) !! | |
var startDateCode = "2015-03-02"; | |
var chunkSize = 4, | |
content = el.content.trim().split('\n'); | |
function patternDate(date, fmt) { | |
var o = { | |
"M+" : date.getMonth() + 1, //月份 | |
"d+" : date.getDate(), //日 | |
"h+" : date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, //小时 | |
"H+" : date.getHours(), //小时 | |
"m+" : date.getMinutes(), //分 | |
"s+" : date.getSeconds(), //秒 | |
"q+" : Math.floor((date.getMonth() + 3) / 3), //季度 | |
"S" : date.getMilliseconds() //毫秒 | |
}; | |
var week = { | |
"0" : "\u65e5", | |
"1" : "\u4e00", | |
"2" : "\u4e8c", | |
"3" : "\u4e09", | |
"4" : "\u56db", | |
"5" : "\u4e94", | |
"6" : "\u516d" | |
}; | |
if (/(y+)/.test(fmt)) { | |
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); | |
} | |
if (/(E+)/.test(fmt)) { | |
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "\u661f\u671f" : "\u5468") : "") + week[date.getDay() + ""]); | |
} | |
for (var k in o) { | |
if (new RegExp("(" + k + ")").test(fmt)) { | |
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); | |
} | |
} | |
return fmt; | |
}; | |
function getCourseTime(courseTimeCode, isEnd) { | |
var timeTMP = { | |
1 : new Date().setHours(0, 0, 0), | |
2 : new Date().setHours(0, 55, 0), | |
3 : new Date().setHours(2, 10, 0), | |
4 : new Date().setHours(3, 05, 0), | |
5 : new Date().setHours(6, 30, 0), | |
6 : new Date().setHours(7, 25, 0), | |
7 : new Date().setHours(8, 40, 0), | |
8 : new Date().setHours(9, 35, 0), | |
9 : new Date().setHours(11, 10, 0), | |
10 : new Date().setHours(12, 05, 0), | |
11 : new Date().setHours(13, 00, 0), | |
} | |
[courseTimeCode]; | |
if (!isEnd) | |
return patternDate(new Date(timeTMP), 'HHmmss'); | |
else | |
return patternDate(new Date(timeTMP + 2700000), 'HHmmss'); | |
}; | |
return [] | |
.concat.apply([], content.map(function (elem, i) { | |
return i % chunkSize ? [] : [content.slice(i, i + chunkSize)]; | |
})) | |
.map(function (_el) { | |
var weekDay = el.cellIndex, | |
weekDaySymbol = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'][weekDay], | |
courseWeekCode = /(\d+)-(\d+)周/.exec(_el[2]) || [0, 1, 1], | |
courseTimeCode = /(\d+)-(\d+)节/.exec(_el[2]) || [0, 1, 1], | |
startDate = patternDate(new Date(new Date(startDateCode).getTime() + (weekDay - 1) * 86400000 + (courseWeekCode[1] - 1) * 7 * 86400000), "yyyyMMdd"); | |
console.log(el.cellIndex,_el[0]) | |
return ['BEGIN:VEVENT\nDESCRIPTION:', | |
'DTEND:' + startDate + 'T' + getCourseTime(courseTimeCode[2], true) + 'Z', | |
'DTSTART:' + startDate + 'T' + getCourseTime(courseTimeCode[1]) + 'Z', | |
'DTSTAMP:' + startDate + 'T' + getCourseTime(courseTimeCode[1]) + 'Z', | |
'LOCATION:' + _el[3], | |
'SUMMARY:' + _el[0] + "(" + _el[1] + ")", | |
'RRULE:FREQ=WEEKLY;BYDAY=' + weekDaySymbol + ';INTERVAL=' + 1 + ';COUNT=' + courseWeekCode[2], | |
'TRANSP:OPAQUE\nEND:VEVENT\n'].join('\n'); | |
}) | |
.join('\n'); | |
})) | |
.concat('END:VCALENDAR') | |
.join('\n') | |
}(window, document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment