From 57f9b3472cc45fcf2f98281f5e46274c8bcde244 Mon Sep 17 00:00:00 2001 From: boomzero Date: Tue, 7 Oct 2025 21:30:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20problem=20PID=20=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E4=B8=BA=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XMOJ.user.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index cf08940d..0ba077bf 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1645,7 +1645,28 @@ async function main() { } else if (location.pathname == "/problem.php") { await RenderMathJax(); 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 pid = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID"); + if (!pid) { + 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; + for (let i = 0; i < rows.length; i++) { + let problemIdText = rows[i].children[1].innerText; // Get the text content + let match = problemIdText.match(/\d+/); // Extract the number + if (match) { + let extractedPid = match[0]; + localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + i + "-PID", extractedPid); + } + } + pid = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID"); + } + } + if (pid) { + document.getElementsByTagName("h2")[0].innerHTML += " (" + 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")); @@ -1727,8 +1748,7 @@ async function main() { // Remove the button's outer [] let str = document.querySelector('.mt-3 > center:nth-child(1)').innerHTML; let target = SubmitButton.outerHTML; - let result = str.replace(new RegExp(`(.?)${target}(.?)`, 'g'), target); - document.querySelector('.mt-3 > center:nth-child(1)').innerHTML = result; + document.querySelector('.mt-3 > center:nth-child(1)').innerHTML = str.replace(new RegExp(`(.?)${target}(.?)`, 'g'), target); document.querySelector('html body.placeholder-glow div.container div.mt-3 center button#SubmitButton.btn.btn-outline-secondary').onclick = function () { window.location.href = SubmitLink.href; console.log(SubmitLink.href); From 4245d11addd4041f8350afe6419254d4ba9aa3c6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 7 Oct 2025 14:00:14 +0000 Subject: [PATCH 2/3] 2.5.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7dc97daa..b70e2ba3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmoj-script", - "version": "2.5.1", + "version": "2.5.2", "description": "an improvement script for xmoj.tech", "main": "AddonScript.js", "scripts": { From f2f20a69c9b6f61afefd68f8a14ffe7701159814 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 7 Oct 2025 14:00:20 +0000 Subject: [PATCH 3/3] Update version info to 2.5.2 --- Update.json | 11 +++++++++++ XMOJ.user.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Update.json b/Update.json index 127f787f..043b5b37 100644 --- a/Update.json +++ b/Update.json @@ -3203,6 +3203,17 @@ } ], "Notes": "No release notes were provided for this release." + }, + "2.5.2": { + "UpdateDate": 1759845614758, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 877, + "Description": "fix: problem PID 可能为 null" + } + ], + "Notes": "No release notes were provided for this release." } } } \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index 0ba077bf..389809d0 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 2.5.1 +// @version 2.5.2 // @description XMOJ增强脚本 // @author @XMOJ-Script-dev, @langningchen and the community // @namespace https://github/langningchen