diff --git a/Update.json b/Update.json index 2ae346f5..7c45a663 100644 --- a/Update.json +++ b/Update.json @@ -3080,6 +3080,118 @@ } ], "Notes": "请尽快升级至本版本!" + }, + "2.4.1": { + "UpdateDate": 1759412851092, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 861, + "Description": "Update CSS selector" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.4.2": { + "UpdateDate": 1759413584731, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 863, + "Description": "修复“NaN年前“" + } + ], + "Notes": "修复“NaN年前“" + }, + "2.4.3": { + "UpdateDate": 1759414259108, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 865, + "Description": "删除获取数据功能" + } + ], + "Notes": "因为它利用的bug被修复了" + }, + "2.4.4": { + "UpdateDate": 1759417362937, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 866, + "Description": "比赛题目页面里左侧栏加入题目序号列表" + } + ], + "Notes": "#860 ..." + }, + "2.4.5": { + "UpdateDate": 1759487413226, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 869, + "Description": "Update CSS selector (again...)" + } + ], + "Notes": "为什么这个破东西老是换位置" + }, + "2.4.6": { + "UpdateDate": 1759548958578, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 871, + "Description": "Add tooltip for ProblemSwitcher" + } + ], + "Notes": "现在, 你只需要将鼠标悬浮在比赛题目切换器上方, 即可查看题目名称" + }, + "2.4.7": { + "UpdateDate": 1759549826774, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 872, + "Description": "修复获取数据" + } + ], + "Notes": "funny" + }, + "2.5.0": { + "UpdateDate": 1759568103629, + "Prerelease": false, + "UpdateContents": [ + { + "PR": 861, + "Description": "Update CSS selector" + }, + { + "PR": 863, + "Description": "修复“NaN年前“" + }, + { + "PR": 865, + "Description": "删除获取数据功能" + }, + { + "PR": 866, + "Description": "比赛题目页面里左侧栏加入题目序号列表" + }, + { + "PR": 869, + "Description": "Update CSS selector (again...)" + }, + { + "PR": 871, + "Description": "Add tooltip for ProblemSwitcher" + }, + { + "PR": 872, + "Description": "修复获取数据" + } + ], + "Notes": "XMOJ-Script 2.5.0 新增了比赛题目切换器,方便您在题目之间快速切换。此功能默认启用,您也可以在设置中禁用它。本版本还修复了一个导致时间显示为“NaN年前”的错误, 更新了一些 CSS selector,以适应 XMOJ 网站的最新变化." } } } \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index 7236b5a8..9382516b 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 2.4.0 +// @version 2.5.0 // @description XMOJ增强脚本 // @author @XMOJ-Script-dev, @langningchen and the community // @namespace https://github/langningchen @@ -81,7 +81,7 @@ let SmartAlert = (Message) => { */ let GetRelativeTime = (Input) => { try { - Input = new Date(Input); + Input = new Date(parseInt(Input)); let Now = new Date().getTime(); let Delta = Now - Input.getTime(); let RelativeName = ""; @@ -1506,6 +1506,8 @@ async function main() { }, { "ID": "RefreshSolution", "Type": "F", "Name": "状态页面结果自动刷新每次只能刷新一个" }, {"ID": "CopyMD", "Type": "A", "Name": "复制题目或题解内容"}, { + "ID": "ProblemSwitcher", "Type": "A", "Name": "比赛题目切换器" + }, { "ID": "OpenAllProblem", "Type": "A", "Name": "比赛题目界面一键打开所有题目" }, { "ID": "CheckCode", "Type": "A", "Name": "提交代码前对代码进行检查", "Children": [{ @@ -1642,8 +1644,60 @@ async function main() { } } else if (location.pathname == "/problem.php") { await RenderMathJax(); - if (SearchParams.get("cid") != null) { + if (SearchParams.get("cid") != null && UtilityEnabled("ProblemSwitcher")) { document.getElementsByTagName("h2")[0].innerHTML += " (" + localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID") + ")"; + 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); + } + } + + let problemSwitcher = document.createElement("div"); + problemSwitcher.style.position = "fixed"; + problemSwitcher.style.top = "50%"; + problemSwitcher.style.left = "0"; + problemSwitcher.style.transform = "translateY(-50%)"; + problemSwitcher.style.maxHeight = "80vh"; + problemSwitcher.style.overflowY = "auto"; + if (document.querySelector("html").getAttribute("data-bs-theme") == "dark") { + problemSwitcher.style.backgroundColor = "rgba(0, 0, 0, 0.8)"; + } else { + problemSwitcher.style.backgroundColor = "rgba(255, 255, 255, 0.8)"; + } + problemSwitcher.style.padding = "10px"; + problemSwitcher.style.borderRadius = "0 10px 10px 0"; + problemSwitcher.style.display = "flex"; + problemSwitcher.style.flexDirection = "column"; + + let problemList = JSON.parse(ContestProblemList); + for (let i = 0; i < problemList.length; i++) { + let buttonText = ""; + if (i < 26) { + buttonText = String.fromCharCode(65 + i); + } else { + buttonText = String.fromCharCode(97 + (i - 26)); + } + let activeClass = ""; + if (problemList[i].url === location.href) { + activeClass = "active"; + } + problemSwitcher.innerHTML += `${buttonText}`; + } + document.body.appendChild(problemSwitcher); } if (document.querySelector("body > div > div.mt-3 > h2") != null) { document.querySelector("body > div > div.mt-3").innerHTML = "没有此题目或题目对你不可见"; @@ -1669,6 +1723,12 @@ async function main() { if (SubmitLink == null) { SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(9)'); } + if (SubmitLink == null) { //为什么这个破东西老是换位置 + SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(7)'); + } + if (SubmitLink == null) { //tmd又换位置 + SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(8)'); + } let SubmitButton = document.createElement('button'); SubmitButton.id = 'SubmitButton'; SubmitButton.className = 'btn btn-outline-secondary'; @@ -3470,7 +3530,7 @@ int main() break; Input.push_back(Data); } - throw runtime_error("[" + Base64Encode(Input.c_str()) + "]"); + throw logic_error("[" + Base64Encode(Input.c_str()) + "]"); return 0; }`; diff --git a/package.json b/package.json index dbafb19a..b0598518 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmoj-script", - "version": "2.4.0", + "version": "2.5.0", "description": "an improvement script for xmoj.tech", "main": "AddonScript.js", "scripts": {