Skip to content

Commit 10d6806

Browse files
fix: problem PID 可能为 null (#877)
* fix: problem PID 可能为 null * 2.5.2 * Update version info to 2.5.2 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 9f5c208 commit 10d6806

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

Update.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,17 @@
32033203
}
32043204
],
32053205
"Notes": "No release notes were provided for this release."
3206+
},
3207+
"2.5.2": {
3208+
"UpdateDate": 1759845614758,
3209+
"Prerelease": true,
3210+
"UpdateContents": [
3211+
{
3212+
"PR": 877,
3213+
"Description": "fix: problem PID 可能为 null"
3214+
}
3215+
],
3216+
"Notes": "No release notes were provided for this release."
32063217
}
32073218
}
32083219
}

XMOJ.user.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 2.5.1
3+
// @version 2.5.2
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -1645,7 +1645,28 @@ async function main() {
16451645
} else if (location.pathname == "/problem.php") {
16461646
await RenderMathJax();
16471647
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+
}
16491670
let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList");
16501671
if (ContestProblemList == null) {
16511672
const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
@@ -1727,8 +1748,7 @@ async function main() {
17271748
// Remove the button's outer []
17281749
let str = document.querySelector('.mt-3 > center:nth-child(1)').innerHTML;
17291750
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);
17321752
document.querySelector('html body.placeholder-glow div.container div.mt-3 center button#SubmitButton.btn.btn-outline-secondary').onclick = function () {
17331753
window.location.href = SubmitLink.href;
17341754
console.log(SubmitLink.href);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xmoj-script",
3-
"version": "2.5.1",
3+
"version": "2.5.2",
44
"description": "an improvement script for xmoj.tech",
55
"main": "AddonScript.js",
66
"scripts": {

0 commit comments

Comments
 (0)