Skip to content

Instantly share code, notes, and snippets.

@helloqiu
Last active September 5, 2017 08:54
Show Gist options
  • Save helloqiu/6055929ac8a15af2e50a5ba02885dafd to your computer and use it in GitHub Desktop.
Save helloqiu/6055929ac8a15af2e50a5ba02885dafd to your computer and use it in GitHub Desktop.
Simple js which can export course table from uestc.
$.getScript('https://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js', function() {
const table_rows = $('#manualArrangeCourseTable').children('tbody')[0].children
let course_result = []
for (let i = 0; i < 12; i++) {
const row = table_rows[i]
for (let j = 0; j < 8; j++) {
const block = row.children[j]
if (block && block.hasAttribute('title')) {
const data = /(.*)\s([^ \(]*)\(.*(\d+)\-(\d+)\,(.*)\)/.exec(block.title)
course_result.push({
teacher: data[1],
name: data[2],
start_week: parseInt(data[3]),
end_week: parseInt(data[4]),
location: data[5],
weekday: j,
start_time: i + 1,
length: block.rowSpan
})
}
}
}
let export_course = document.createElement('input')
export_course.type = 'submit'
export_course.value = '导出课表'
export_course.onclick = function () {
saveAs(
new Blob([JSON.stringify(course_result)], {type: 'application/json'}),
'course.json'
)
}
$('#courseTableForm div')[1].append(export_course)
})
@helloqiu
Copy link
Author

helloqiu commented Sep 5, 2017

update regex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment