// ==UserScript==
// @name 东南大学抢课助手new
// @namespace http://tampermonkey.net/
// @version 0.3
// @description 听说你抢不到课
// @author realhuhu
// @match http://newxk.urp.seu.edu.cn/xsxk/elective/grablessons?*
// @icon https://huhu-1304907527.cos.ap-nanjing.myqcloud.com/share/qkzs
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
onload;
// let jwt = sessionStorage.token;
let ajax = axios.create();
grablessonsVue.grabList = {
"TJKC": [],
"FANKC": [],
"FAWKC": [],
"TYKC": [],
"XGKC": [],
};
grablessonsVue.grabRes = [];
(self => {
let app = document.getElementById("xsxkapp")
self.mount = () => {
self.createTag()
self.createPanel()
}
self._createWrap = id => {
let wrap = document.createElement("div")
wrap.setAttribute("id", id)
return wrap
}
self.createTag = () => {
let wrap = self._createWrap("tag")
wrap.innerHTML = `
`
app.appendChild(wrap)
}
self.createPanel = () => {
let wrap = self._createWrap("panel")
wrap.style.display = "none"
wrap.innerHTML = `
东大抢课脚本
还未选择课程
显示结果
课程代码:课程号+教师号
`
app.appendChild(wrap)
}
})(grablessonsVue.Components = grablessonsVue.Components || {});
grablessonsVue.patch = {
toggle() {
let node = document.getElementById("panel")
node.style.display === "block" ? node.style.display = "none" : node.style.display = "block"
},
enterCourse(e) {
let evt = window.event || e;
if (evt.keyCode === 13) {
let target = document.getElementById("enter")
let id = "202120221" + target.value.toUpperCase()
let type = grablessonsVue.teachingClassType
let course = {}
if (type === "TYKC") {
for (let i of grablessonsVue.courseList[0].tcList) {
if (i.JXBID === id) {
course["id"] = id
course["name"] = i.KCM
course["teacher"] = i.SKJS
course["key"] = i.secretVal
}
}
} else if (type === "XGKC") {
for (let i of grablessonsVue.courseList) {
if (i.JXBID === id) {
course["id"] = id
course["name"] = i.KCM
course["teacher"] = i.SKJS
course["key"] = i.secretVal
}
}
} else {
for (let i of grablessonsVue.courseList) {
for (let j of i.tcList) {
if (j.JXBID === id) {
course["id"] = id
course["name"] = j.KCM
course["teacher"] = j.SKJS
course["key"] = j.secretVal
}
}
}
}
if (JSON.stringify(course) !== '{}') {
grablessonsVue.grabList[type].push(course)
grablessonsVue.$message({
type: "success",
message: "添加成功"
})
} else {
grablessonsVue.$message({
type: "warning",
message: "课程代码错误,请检查后重新输入"
})
}
target.value = ""
document.getElementById("list-wrap").innerHTML = grablessonsVue.patch.createList()
}
},
grab() {
grablessonsVue.grabRes = []
let data = []
for (let type of Object.keys(grablessonsVue.grabList)) {
for (let raw of grablessonsVue.grabList[type]) {
data.push({
clazz: raw.name,
dic: {
clazz: raw.name,
clazzType: type,
clazzId: raw.id,
secretVal: raw.key
}
})
}
}
document.getElementById("grab").innerText = "请耐心等待"
axios.all(data.map(raw => {
return ajax({
url: "/elective/clazz/add",
method: "POST",
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
data: Qs.stringify(raw.dic)
}).then(function (response) {
let type = response.data.code === 100 ? "success" : "warning"
grablessonsVue.grabRes.push({
clazz: raw.clazz,
msg: response.data.msg
})
grablessonsVue.$message({
type,
message: raw.clazz + ":" + response.data.msg
})
}).catch(function (error) {
grablessonsVue.$message({
type: "error",
message: "未知错误:" + error
});
})
})).then(function () {
if (Object.keys(grablessonsVue.grabList).map(type => grablessonsVue.grabList[type].length).reduce((x, y) => x + y)) {
grablessonsVue.$message({
type: "success",
message: "抢课结束"
})
document.getElementById("grab").innerText = "再次抢课"
} else {
grablessonsVue.$message({
type: "warning",
message: "请选择课程"
})
document.getElementById("grab").innerText = "一键抢课"
}
}
)
},
createList() {
let courses = []
for (let type of Object.keys(grablessonsVue.grabList)) {
for (let course of grablessonsVue.grabList[type]) {
courses.push({
id: course.id,
name: course.name,
teacher: course.teacher
})
}
}
if (courses.length === 0) {
return `还未选择课程
`
} else {
let html = `
课程 |
教师 |
操作 |
`
for (let course of courses) {
html += '' + course.name + ' | ' + course.teacher + ' | |
'
}
html += "
"
return html
}
},
removeCourse(id) {
console.log(id);
let n = 0
for (let type of Object.keys(grablessonsVue.grabList)) {
for (let course of grablessonsVue.grabList[type]) {
if (course.id === id) {
n = grablessonsVue.grabList[type].indexOf(course)
grablessonsVue.grabList[type].splice(n, 1);
}
}
}
document.getElementById("list-wrap").innerHTML = grablessonsVue.patch.createList()
},
show() {
alert(grablessonsVue.grabRes.map(res => res.clazz + ":" + res.msg).join("\n"))
}
};
grablessonsVue.Components.mount();
})();