@@ -533,6 +533,29 @@ let RequestAPI = (Action, Data, CallBack) => {
533533 }
534534} ;
535535
536+ unsafeWindow . GetContestProblemList = async function ( RefreshList ) {
537+ try {
538+ const contestReq = await fetch ( "https://www.xmoj.tech/contest.php?cid=" + SearchParams . get ( "cid" ) ) ;
539+ const res = await contestReq . text ( ) ;
540+ if ( contestReq . status === 200 && res . indexOf ( "比赛尚未开始或私有,不能查看题目。" ) === - 1 ) {
541+ const parser = new DOMParser ( ) ;
542+ const dom = parser . parseFromString ( res , "text/html" ) ;
543+ const rows = ( dom . querySelector ( "#problemset > tbody" ) ) . rows ;
544+ let problemList = [ ] ;
545+ for ( let i = 0 ; i < rows . length ; i ++ ) {
546+ problemList . push ( {
547+ "title" : rows [ i ] . children [ 2 ] . innerText ,
548+ "url" : rows [ i ] . children [ 2 ] . children [ 0 ] . href
549+ } ) ;
550+ }
551+ localStorage . setItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-ProblemList" , JSON . stringify ( problemList ) ) ;
552+ if ( RefreshList ) location . reload ( ) ;
553+ }
554+ } catch ( e ) {
555+ console . error ( e ) ;
556+ }
557+ }
558+
536559// WebSocket Notification System
537560let NotificationSocket = null ;
538561let NotificationSocketReconnectAttempts = 0 ;
@@ -1616,7 +1639,8 @@ async function main() {
16161639 border: 1px solid var(--bs-secondary-bg);
16171640 border-top: none;
16181641 border-radius: 0 0 0.3rem 0.3rem;
1619- }` ;
1642+ }
1643+ ` ;
16201644 }
16211645 if ( UtilityEnabled ( "AddAnimation" ) ) {
16221646 Style . innerHTML += `.status, .test-case {
@@ -2272,22 +2296,8 @@ async function main() {
22722296 }
22732297 let ContestProblemList = localStorage . getItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-ProblemList" ) ;
22742298 if ( ContestProblemList == null ) {
2275- const contestReq = await fetch ( "https://www.xmoj.tech/contest.php?cid=" + SearchParams . get ( "cid" ) ) ;
2276- const res = await contestReq . text ( ) ;
2277- if ( contestReq . status === 200 && res . indexOf ( "比赛尚未开始或私有,不能查看题目。" ) === - 1 ) {
2278- const parser = new DOMParser ( ) ;
2279- const dom = parser . parseFromString ( res , "text/html" ) ;
2280- const rows = ( dom . querySelector ( "#problemset > tbody" ) ) . rows ;
2281- let problemList = [ ] ;
2282- for ( let i = 0 ; i < rows . length ; i ++ ) {
2283- problemList . push ( {
2284- "title" : rows [ i ] . children [ 2 ] . innerText ,
2285- "url" : rows [ i ] . children [ 2 ] . children [ 0 ] . href
2286- } ) ;
2287- }
2288- localStorage . setItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-ProblemList" , JSON . stringify ( problemList ) ) ;
2289- ContestProblemList = JSON . stringify ( problemList ) ;
2290- }
2299+ await unsafeWindow . GetContestProblemList ( false ) ;
2300+ ContestProblemList = localStorage . getItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-ProblemList" ) ;
22912301 }
22922302
22932303 let problemSwitcher = document . createElement ( "div" ) ;
@@ -6093,4 +6103,4 @@ int main()
60936103
60946104main ( ) . then ( r => {
60956105 console . log ( "XMOJ-Script loaded successfully!" ) ;
6096- } ) ;
6106+ } ) ;
0 commit comments