diff --git a/Update.json b/Update.json index e12d6229..65325b1f 100644 --- a/Update.json +++ b/Update.json @@ -3433,6 +3433,17 @@ } ], "Notes": "No release notes were provided for this release." + }, + "3.3.2": { + "UpdateDate": 1773495619873, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 933, + "Description": "Fix problem switcher not update" + } + ], + "Notes": "Fix ProblemSwitcher Not Update" } } } \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index 49538eed..897238fe 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 3.3.1 +// @version 3.3.2 // @description XMOJ增强脚本 // @author @XMOJ-Script-dev, @langningchen and the community // @namespace https://github/langningchen @@ -533,6 +533,29 @@ let RequestAPI = (Action, Data, CallBack) => { } }; +unsafeWindow.GetContestProblemList = async function(RefreshList) { + try { + const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid")); + const res = await contestReq.text(); + if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) { + const parser = new DOMParser(); + const dom = parser.parseFromString(res, "text/html"); + const rows = (dom.querySelector("#problemset > tbody")).rows; + let problemList = []; + for (let i = 0; i < rows.length; i++) { + problemList.push({ + "title": rows[i].children[2].innerText, + "url": rows[i].children[2].children[0].href + }); + } + localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList", JSON.stringify(problemList)); + if (RefreshList) location.reload(); + } + } catch (e) { + console.error(e); + } +} + // WebSocket Notification System let NotificationSocket = null; let NotificationSocketReconnectAttempts = 0; @@ -1551,6 +1574,9 @@ async function main() { display: none !important; } } + .refreshList { + cursor: pointer; + } /* Contain images */ img { @@ -1616,6 +1642,11 @@ async function main() { border: 1px solid var(--bs-secondary-bg); border-top: none; border-radius: 0 0 0.3rem 0.3rem; + } + .refreshList { + cursor: pointer; + color: #6c757d; + text-decoration: none; }`; } if (UtilityEnabled("AddAnimation")) { @@ -2272,22 +2303,8 @@ async function main() { } let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList"); if (ContestProblemList == null) { - const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid")); - const res = await contestReq.text(); - if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) { - const parser = new DOMParser(); - const dom = parser.parseFromString(res, "text/html"); - const rows = (dom.querySelector("#problemset > tbody")).rows; - let problemList = []; - for (let i = 0; i < rows.length; i++) { - problemList.push({ - "title": rows[i].children[2].innerText, - "url": rows[i].children[2].children[0].href - }); - } - localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList", JSON.stringify(problemList)); - ContestProblemList = JSON.stringify(problemList); - } + await unsafeWindow.GetContestProblemList(false); + ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList"); } let problemSwitcher = document.createElement("div"); @@ -2310,6 +2327,7 @@ async function main() { problemSwitcher.style.flexDirection = "column"; let problemList = JSON.parse(ContestProblemList); + problemSwitcher.innerHTML += `刷新`; for (let i = 0; i < problemList.length; i++) { let buttonText = ""; if (i < 26) { @@ -6069,4 +6087,4 @@ int main() main().then(r => { console.log("XMOJ-Script loaded successfully!"); -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index 9ffb1aa4..7a191097 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmoj-script", - "version": "3.3.1", + "version": "3.3.2", "description": "an improvement script for xmoj.tech", "main": "AddonScript.js", "scripts": {