|
1 | 1 | // ==UserScript== |
2 | 2 | // @name XMOJ |
3 | | -// @version 2.5.1 |
| 3 | +// @version 2.5.2 |
4 | 4 | // @description XMOJ增强脚本 |
5 | 5 | // @author @XMOJ-Script-dev, @langningchen and the community |
6 | 6 | // @namespace https://github/langningchen |
@@ -1645,7 +1645,28 @@ async function main() { |
1645 | 1645 | } else if (location.pathname == "/problem.php") { |
1646 | 1646 | await RenderMathJax(); |
1647 | 1647 | if (SearchParams.get("cid") != null && UtilityEnabled("ProblemSwitcher")) { |
1648 | | - document.getElementsByTagName("h2")[0].innerHTML += " (" + localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID") + ")"; |
| 1648 | + let pid = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID"); |
| 1649 | + if (!pid) { |
| 1650 | + const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid")); |
| 1651 | + const res = await contestReq.text(); |
| 1652 | + if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) { |
| 1653 | + const parser = new DOMParser(); |
| 1654 | + const dom = parser.parseFromString(res, "text/html"); |
| 1655 | + const rows = (dom.querySelector("#problemset > tbody")).rows; |
| 1656 | + for (let i = 0; i < rows.length; i++) { |
| 1657 | + let problemIdText = rows[i].children[1].innerText; // Get the text content |
| 1658 | + let match = problemIdText.match(/\d+/); // Extract the number |
| 1659 | + if (match) { |
| 1660 | + let extractedPid = match[0]; |
| 1661 | + localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + i + "-PID", extractedPid); |
| 1662 | + } |
| 1663 | + } |
| 1664 | + pid = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID"); |
| 1665 | + } |
| 1666 | + } |
| 1667 | + if (pid) { |
| 1668 | + document.getElementsByTagName("h2")[0].innerHTML += " (" + pid + ")"; |
| 1669 | + } |
1649 | 1670 | let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList"); |
1650 | 1671 | if (ContestProblemList == null) { |
1651 | 1672 | const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid")); |
@@ -1727,8 +1748,7 @@ async function main() { |
1727 | 1748 | // Remove the button's outer [] |
1728 | 1749 | let str = document.querySelector('.mt-3 > center:nth-child(1)').innerHTML; |
1729 | 1750 | let target = SubmitButton.outerHTML; |
1730 | | - let result = str.replace(new RegExp(`(.?)${target}(.?)`, 'g'), target); |
1731 | | - document.querySelector('.mt-3 > center:nth-child(1)').innerHTML = result; |
| 1751 | + document.querySelector('.mt-3 > center:nth-child(1)').innerHTML = str.replace(new RegExp(`(.?)${target}(.?)`, 'g'), target); |
1732 | 1752 | document.querySelector('html body.placeholder-glow div.container div.mt-3 center button#SubmitButton.btn.btn-outline-secondary').onclick = function () { |
1733 | 1753 | window.location.href = SubmitLink.href; |
1734 | 1754 | console.log(SubmitLink.href); |
|
0 commit comments