Skip to content
This repository was archived by the owner on Aug 4, 2024. It is now read-only.

Commit efd35a6

Browse files
authored
Update potatojw_upgraded.user.js
v0.0.3.1 +>支持跨专业选课
1 parent 10680b6 commit efd35a6

File tree

1 file changed

+62
-12
lines changed

1 file changed

+62
-12
lines changed

potatojw_upgraded.user.js

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name potatojw_upgraded
33
// @namespace https://cubiccm.ddns.net
4-
// @version 0.0.3
4+
// @version 0.0.3.1
55
// @description 土豆改善工程!
66
// @author Limosity
77
// @match *://*.nju.edu.cn/jiaowu/*
@@ -10,14 +10,14 @@
1010
// ==/UserScript==
1111
(function() {
1212
'use strict';
13-
$$ = jQuery.noConflict();
14-
console.log("potatojw_upgraded v0.0.3 by Limosity");
13+
var $$ = jQuery.noConflict();
14+
console.log("potatojw_upgraded v0.0.3.1 by Limosity");
1515
// Your code here...
1616
$$("head").append('<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">');
1717
var reg_gym = /gymClassList.do/i;
1818
var reg_read = /readRenewCourseList.do/i;
1919
var reg_dis = /discussRenewCourseList/i;
20-
var reg_open = /openRenewCourseList/i;
20+
var reg_open = /openRenewCourse/i;
2121
var reg_common = /commonCourseRenewList/i;
2222

2323
var mode = "";
@@ -141,7 +141,7 @@
141141
};
142142
} else if (mode == "dis") {
143143
window.selectClass = function(class_ID) {
144-
console.log(class_ID);
144+
console.log("Select: " + class_ID);
145145
var g_campus = $$('#campusList')[0].options[$$('#campusList')[0].selectedIndex].value;
146146
$$.ajax({
147147
url: "/jiaowu/student/elective/courseList.do?method=submitDiscussRenew&classId=" + classId + "&campus=" + g_campus,
@@ -181,6 +181,49 @@
181181
window.isClassFull = function(element) {
182182
return parseInt($$(element).children("td:eq(7)").html()) >= parseInt($$(element).children("td:eq(6)").html());
183183
};
184+
} else if (mode == "open") {
185+
window.campusChange = function() {};
186+
window.selectedClass = function(class_ID, course_name) {
187+
console.log("Select: " + course_name);
188+
var academy_ID = $$('#academyList').val();
189+
$$.ajax({
190+
url: "http://jw.nju.edu.cn:80/jiaowu/student/elective/courseList.do?method=submitOpenRenew&classId=" + class_ID + "&academy=" + academy_ID,
191+
type: "GET",
192+
success: function(res) {
193+
console.log("Success!");
194+
initClassList();
195+
}
196+
});
197+
}
198+
199+
window.optimizeClassList = function() {
200+
$$("#iframeTable").after(`<div id="tbCourseList"></div>`);
201+
$$("#iframeTable").remove();
202+
}
203+
204+
$$(document).ready(function() {
205+
optimizeClassList();
206+
});
207+
208+
window.initClassList = function() {
209+
$$.ajax({
210+
url: "http://jw.nju.edu.cn:80/jiaowu/student/elective/courseList.do?method=openRenewCourse&campus="+document.getElementById('campusList').value+"&academy="+document.getElementById('academyList').value,
211+
type: "GET",
212+
success: function(res) {
213+
$$("#tbCourseList").html($$(res).find("table.TABLE_BODY").html());
214+
updateFilterList();
215+
applyFilter();
216+
}
217+
});
218+
};
219+
220+
window.searchCourseList = function(truenmn) {
221+
initClassList();
222+
}
223+
224+
window.isClassFull = function(element) {
225+
return parseInt($$(element).children("td:eq(8)").html()) >= parseInt($$(element).children("td:eq(7)").html());
226+
};
184227
} else return;
185228

186229
const filter_setting_html = `
@@ -202,7 +245,7 @@
202245
<br>
203246
<button onclick="hideFilterSetting();">应用设置并关闭</button>
204247
<br>
205-
<span>potatojw_upgraded Beta v0.0.3 暂时不支持跨专业选课 注:自动选课是按过滤器选课~ 更多功能开发中~</span>
248+
<span>potatojw_upgraded Beta v0.0.3.1 注:自动选课是按过滤器选课,正在改善~ 更多功能开发中~</span>
206249
<br>
207250
<span>字体美化已启用</span>
208251
</div>
@@ -277,7 +320,7 @@ body {
277320
$$("body").append("<br><br><br><style>" + css + "</style>");
278321

279322
window.applyFilter = function() {
280-
$$("tbody > tr").each(function() {
323+
getAllClassDOM().each(function() {
281324
$$(this).css("display", (filterClass(this) ? "table-row" : "none"));
282325
});
283326
};
@@ -317,22 +360,29 @@ body {
317360
"gym": 5,
318361
"read": 6,
319362
"common": 9,
320-
"dis": 10
363+
"dis": 10,
364+
"open": 9
321365
};
322366

323367
const class_name_index = {
324368
"gym": 0,
325369
"read": 1,
326370
"common": 2,
327-
"dis": 2
371+
"dis": 2,
372+
"open": 2
328373
};
329374

330375
const class_time_index = {
331376
"gym": 1,
332377
"common": 4,
333-
"dis": 4
378+
"dis": 4,
379+
"open": 5
334380
};
335381

382+
window.getAllClassDOM = function() {
383+
return (mode == "open" ? $$("div#tbCourseList > tbody > tr:gt(0)") : $$("tbody > tr"));
384+
}
385+
336386
// Update class list automatically
337387
// 自动更新
338388
window.startAutoRefresh = function() {
@@ -348,7 +398,7 @@ body {
348398
// Select qualified class automatically
349399
// 自动选择符合过滤器的课程
350400
window.doAutoClassSelect = function() {
351-
$$("tbody > tr").each(function() {
401+
getAllClassDOM().each(function() {
352402
if (!filterClass(this)) return;
353403
if (!isClassFull(this)) {
354404
$$(this).children("td:eq(" + select_class_button_index[mode] + ")").children("a").click();
@@ -366,7 +416,7 @@ body {
366416
window.time_list = new Array();
367417
window.updateFilterList = function() {
368418
var date_num = 0;
369-
$$("tbody > tr").each(function() {
419+
getAllClassDOM().each(function() {
370420
if (typeof(class_time_index[mode]) != "undefined") {
371421
var current_time_val = getClassTime(this);
372422
var str_array = current_time_val.split("<br>");

0 commit comments

Comments
 (0)