forked from Durden-T/BUPTtakeCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbupt-take-specific-course.js
More file actions
196 lines (166 loc) · 6.11 KB
/
bupt-take-specific-course.js
File metadata and controls
196 lines (166 loc) · 6.11 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// ==UserScript==
// @name BUPT Course Grabber
// @namespace http://tampermonkey.net/
// @version 1.3
// @description BUPT抢课脚本
// @author Shxuuer
// @match *://*/jsxsd/xsxk/xsxk_index*
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
(function () {
'use strict';
var courses = GM_getValue('courses', []);
var interval = GM_getValue('interval', 3000);
var targets = [];
var running = false;
var intervalId;
let startButton, stopButton, statusLabel;
function getCourses() {
let params = {
sEcho: 1,
iColumns: 11,
iDisplayStart: 0,
iDisplayLength: 99999,
};
let paths = [
'/jsxsd/xsxkkc/xsxkBxxk',
'/jsxsd/xsxkkc/xsxkXxxk',
'/jsxsd/xsxkkc/xsxkGgxxkxk',
];
for (let path of paths) {
$.post(path, params, processData);
}
}
function processData(resp) {
let data = $.parseJSON(resp).aaData;
for (let course of data) {
if (courses.includes(course.kcmc)) {
targets.push([course.kch, course.jx0404id]);
}
}
}
function takeCourses() {
if (!targets.length) getCourses();
for (let target of targets) {
$.ajax({
url: "/jsxsd/xsxkkc/xxxkOper",
data: {
kcid: target[0],
jx0404id: target[1]
}
});
}
}
function start() {
if (running) return;
running = true;
intervalId = setInterval(takeCourses, interval);
updateUI();
}
function stop() {
if (!running) return;
running = false;
clearInterval(intervalId);
updateUI();
}
function saveData() {
GM_setValue('courses', courses);
GM_setValue('interval', interval);
}
function updateUI() {
startButton.style.display = running ? 'none' : 'inline-block';
stopButton.style.display = running ? 'inline-block' : 'none';
statusLabel.textContent = running ? '状态: 正在运行' : '状态: 未运行';
}
function createUI() {
const container = document.createElement('div');
container.style = `
position: fixed;
top: 10px;
right: 10px;
padding: 20px;
background: #fff;
border: 1px solid #ddd;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 8px;
z-index: 10000;
font-family: Arial, sans-serif;
`;
const title = document.createElement('h4');
title.textContent = '抢课工具';
title.style.marginBottom = '10px';
container.appendChild(title);
const intervalLabel = document.createElement('label');
intervalLabel.textContent = '时间间隔 (ms):';
intervalLabel.style.marginRight = '8px';
const intervalInput = document.createElement('input');
intervalInput.type = 'number';
intervalInput.value = interval;
intervalInput.style = 'width: 60px; padding: 4px; margin-bottom: 10px;';
intervalInput.onchange = () => {
interval = parseInt(intervalInput.value) || 300;
saveData();
};
container.appendChild(intervalLabel);
container.appendChild(intervalInput);
const courseInput = document.createElement('input');
courseInput.type = 'text';
courseInput.placeholder = '输入课程名称';
courseInput.style = 'width: calc(100% - 90px); padding: 6px; margin-bottom: 10px;';
const addButton = document.createElement('button');
addButton.textContent = '添加';
addButton.style = 'padding: 6px 12px; margin-left: 8px;';
addButton.onclick = () => {
const courseName = courseInput.value.trim();
if (courseName && !courses.includes(courseName)) {
courses.push(courseName);
updateCourseList();
saveData();
}
courseInput.value = '';
};
container.appendChild(courseInput);
container.appendChild(addButton);
const courseList = document.createElement('ul');
courseList.style = 'list-style: none; padding: 0; margin-top: 10px;';
function updateCourseList() {
courseList.innerHTML = '';
courses.forEach((course, index) => {
const li = document.createElement('li');
li.style = 'margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;';
const courseText = document.createElement('span');
courseText.textContent = course;
const deleteButton = document.createElement('button');
deleteButton.textContent = '删除';
deleteButton.style = 'padding: 4px 8px;';
deleteButton.onclick = () => {
courses.splice(index, 1);
updateCourseList();
saveData();
};
li.appendChild(courseText);
li.appendChild(deleteButton);
courseList.appendChild(li);
});
}
container.appendChild(courseList);
updateCourseList();
startButton = document.createElement('button');
startButton.textContent = '开始';
startButton.style = 'padding: 8px 16px; margin-right: 10px;';
startButton.onclick = start;
stopButton = document.createElement('button');
stopButton.textContent = '暂停';
stopButton.style = 'padding: 8px 16px; display: none;';
stopButton.onclick = stop;
statusLabel = document.createElement('span');
statusLabel.textContent = '状态: 未运行';
statusLabel.style = 'margin-left: 10px; font-weight: bold;';
container.appendChild(startButton);
container.appendChild(stopButton);
container.appendChild(statusLabel);
document.body.appendChild(container);
}
createUI();
})();