11// ==UserScript==
22// @name XMOJ
3- // @version 2.4 .0
3+ // @version 2.5 .0
44// @description XMOJ增强脚本
55// @author @XMOJ -Script-dev, @langningchen and the community
66// @namespace https://github/langningchen
@@ -81,7 +81,7 @@ let SmartAlert = (Message) => {
8181 */
8282let GetRelativeTime = ( Input ) => {
8383 try {
84- Input = new Date ( Input ) ;
84+ Input = new Date ( parseInt ( Input ) ) ;
8585 let Now = new Date ( ) . getTime ( ) ;
8686 let Delta = Now - Input . getTime ( ) ;
8787 let RelativeName = "" ;
@@ -1506,6 +1506,8 @@ async function main() {
15061506 } , {
15071507 "ID" : "RefreshSolution" , "Type" : "F" , "Name" : "状态页面结果自动刷新每次只能刷新一个"
15081508 } , { "ID" : "CopyMD" , "Type" : "A" , "Name" : "复制题目或题解内容" } , {
1509+ "ID" : "ProblemSwitcher" , "Type" : "A" , "Name" : "比赛题目切换器"
1510+ } , {
15091511 "ID" : "OpenAllProblem" , "Type" : "A" , "Name" : "比赛题目界面一键打开所有题目"
15101512 } , {
15111513 "ID" : "CheckCode" , "Type" : "A" , "Name" : "提交代码前对代码进行检查" , "Children" : [ {
@@ -1642,8 +1644,60 @@ async function main() {
16421644 }
16431645 } else if ( location . pathname == "/problem.php" ) {
16441646 await RenderMathJax ( ) ;
1645- if ( SearchParams . get ( "cid" ) != null ) {
1647+ if ( SearchParams . get ( "cid" ) != null && UtilityEnabled ( "ProblemSwitcher" ) ) {
16461648 document . getElementsByTagName ( "h2" ) [ 0 ] . innerHTML += " (" + localStorage . getItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-Problem-" + SearchParams . get ( "pid" ) + "-PID" ) + ")" ;
1649+ let ContestProblemList = localStorage . getItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-ProblemList" ) ;
1650+ if ( ContestProblemList == null ) {
1651+ const contestReq = await fetch ( "https://www.xmoj.tech/contest.php?cid=" + SearchParams . get ( "cid" ) ) ;
1652+ const res = await contestReq . text ( ) ;
1653+ if ( contestReq . status === 200 && res . indexOf ( "比赛尚未开始或私有,不能查看题目。" ) === - 1 ) {
1654+ const parser = new DOMParser ( ) ;
1655+ const dom = parser . parseFromString ( res , "text/html" ) ;
1656+ const rows = ( dom . querySelector ( "#problemset > tbody" ) ) . rows ;
1657+ let problemList = [ ] ;
1658+ for ( let i = 0 ; i < rows . length ; i ++ ) {
1659+ problemList . push ( {
1660+ "title" : rows [ i ] . children [ 2 ] . innerText ,
1661+ "url" : rows [ i ] . children [ 2 ] . children [ 0 ] . href
1662+ } ) ;
1663+ }
1664+ localStorage . setItem ( "UserScript-Contest-" + SearchParams . get ( "cid" ) + "-ProblemList" , JSON . stringify ( problemList ) ) ;
1665+ ContestProblemList = JSON . stringify ( problemList ) ;
1666+ }
1667+ }
1668+
1669+ let problemSwitcher = document . createElement ( "div" ) ;
1670+ problemSwitcher . style . position = "fixed" ;
1671+ problemSwitcher . style . top = "50%" ;
1672+ problemSwitcher . style . left = "0" ;
1673+ problemSwitcher . style . transform = "translateY(-50%)" ;
1674+ problemSwitcher . style . maxHeight = "80vh" ;
1675+ problemSwitcher . style . overflowY = "auto" ;
1676+ if ( document . querySelector ( "html" ) . getAttribute ( "data-bs-theme" ) == "dark" ) {
1677+ problemSwitcher . style . backgroundColor = "rgba(0, 0, 0, 0.8)" ;
1678+ } else {
1679+ problemSwitcher . style . backgroundColor = "rgba(255, 255, 255, 0.8)" ;
1680+ }
1681+ problemSwitcher . style . padding = "10px" ;
1682+ problemSwitcher . style . borderRadius = "0 10px 10px 0" ;
1683+ problemSwitcher . style . display = "flex" ;
1684+ problemSwitcher . style . flexDirection = "column" ;
1685+
1686+ let problemList = JSON . parse ( ContestProblemList ) ;
1687+ for ( let i = 0 ; i < problemList . length ; i ++ ) {
1688+ let buttonText = "" ;
1689+ if ( i < 26 ) {
1690+ buttonText = String . fromCharCode ( 65 + i ) ;
1691+ } else {
1692+ buttonText = String . fromCharCode ( 97 + ( i - 26 ) ) ;
1693+ }
1694+ let activeClass = "" ;
1695+ if ( problemList [ i ] . url === location . href ) {
1696+ activeClass = "active" ;
1697+ }
1698+ problemSwitcher . innerHTML += `<a href="${ problemList [ i ] . url } " title="${ problemList [ i ] . title . trim ( ) } " class="btn btn-outline-secondary mb-2 ${ activeClass } ">${ buttonText } </a>` ;
1699+ }
1700+ document . body . appendChild ( problemSwitcher ) ;
16471701 }
16481702 if ( document . querySelector ( "body > div > div.mt-3 > h2" ) != null ) {
16491703 document . querySelector ( "body > div > div.mt-3" ) . innerHTML = "没有此题目或题目对你不可见" ;
@@ -1669,6 +1723,12 @@ async function main() {
16691723 if ( SubmitLink == null ) {
16701724 SubmitLink = document . querySelector ( '.mt-3 > center:nth-child(1) > a:nth-child(9)' ) ;
16711725 }
1726+ if ( SubmitLink == null ) { //为什么这个破东西老是换位置
1727+ SubmitLink = document . querySelector ( '.mt-3 > center:nth-child(1) > a:nth-child(7)' ) ;
1728+ }
1729+ if ( SubmitLink == null ) { //tmd又换位置
1730+ SubmitLink = document . querySelector ( '.mt-3 > center:nth-child(1) > a:nth-child(8)' ) ;
1731+ }
16721732 let SubmitButton = document . createElement ( 'button' ) ;
16731733 SubmitButton . id = 'SubmitButton' ;
16741734 SubmitButton . className = 'btn btn-outline-secondary' ;
@@ -3470,7 +3530,7 @@ int main()
34703530 break;
34713531 Input.push_back(Data);
34723532 }
3473- throw runtime_error ("[" + Base64Encode(Input.c_str()) + "]");
3533+ throw logic_error ("[" + Base64Encode(Input.c_str()) + "]");
34743534 return 0;
34753535}` ;
34763536
0 commit comments