Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
28 changes: 24 additions & 4 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down