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/*
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 = / g y m C l a s s L i s t .d o / i;
1818 var reg_read = / r e a d R e n e w C o u r s e L i s t .d o / i;
1919 var reg_dis = / d i s c u s s R e n e w C o u r s e L i s t / i;
20- var reg_open = / o p e n R e n e w C o u r s e L i s t / i;
20+ var reg_open = / o p e n R e n e w C o u r s e / i;
2121 var reg_common = / c o m m o n C o u r s e R e n e w L i s t / i;
2222
2323 var mode = "" ;
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 ,
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 = `
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