|
1 | 1 | // ==UserScript== |
2 | 2 | // @name XMOJ |
3 | | -// @version 2.4.3 |
| 3 | +// @version 2.4.4 |
4 | 4 | // @description XMOJ增强脚本 |
5 | 5 | // @author @XMOJ-Script-dev, @langningchen and the community |
6 | 6 | // @namespace https://github/langningchen |
@@ -1506,6 +1506,8 @@ async function main() { |
1506 | 1506 | }, { |
1507 | 1507 | "ID": "RefreshSolution", "Type": "F", "Name": "状态页面结果自动刷新每次只能刷新一个" |
1508 | 1508 | }, {"ID": "CopyMD", "Type": "A", "Name": "复制题目或题解内容"}, { |
| 1509 | + "ID": "ProblemSwitcher", "Type": "A", "Name": "比赛题目切换器" |
| 1510 | + }, { |
1509 | 1511 | "ID": "OpenAllProblem", "Type": "A", "Name": "比赛题目界面一键打开所有题目" |
1510 | 1512 | }, { |
1511 | 1513 | "ID": "CheckCode", "Type": "A", "Name": "提交代码前对代码进行检查", "Children": [{ |
@@ -1642,8 +1644,60 @@ async function main() { |
1642 | 1644 | } |
1643 | 1645 | } else if (location.pathname == "/problem.php") { |
1644 | 1646 | await RenderMathJax(); |
1645 | | - if (SearchParams.get("cid") != null) { |
| 1647 | + if (SearchParams.get("cid") != null && UtilityEnabled("ProblemSwitcher")) { |
1646 | 1648 | 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}" class="btn btn-outline-secondary mb-2 ${activeClass}">${buttonText}</a>`; |
| 1699 | + } |
| 1700 | + document.body.appendChild(problemSwitcher); |
1647 | 1701 | } |
1648 | 1702 | if (document.querySelector("body > div > div.mt-3 > h2") != null) { |
1649 | 1703 | document.querySelector("body > div > div.mt-3").innerHTML = "没有此题目或题目对你不可见"; |
|
0 commit comments