Skip to content

Commit 49512fe

Browse files
boomzeroclaude
andcommitted
merge: incorporate fix-problem-switcher-not-update (#933)
Takes all logic fixes from PR #933 (GetContestProblemList helper, null-safe init, XSS fix, ImageEnlarger) while keeping the ↻ button UI from this branch instead of #933's inline 'refreshList' text link. - Removed .refreshList CSS and the inline onclick "刷新" element - Resolved Update.json version conflict: both PRs credited under 3.3.2 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 parents 852178b + c87d08f commit 49512fe

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

Update.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,10 @@
34383438
"UpdateDate": 1773497073852,
34393439
"Prerelease": true,
34403440
"UpdateContents": [
3441+
{
3442+
"PR": 933,
3443+
"Description": "Fix problem switcher not update"
3444+
},
34413445
{
34423446
"PR": 934,
34433447
"Description": "feat: add refresh button to ProblemSwitcher"

XMOJ.user.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,29 @@ let RequestAPI = (Action, Data, CallBack) => {
533533
}
534534
};
535535

536+
unsafeWindow.GetContestProblemList = async function(RefreshList) {
537+
try {
538+
const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
539+
const res = await contestReq.text();
540+
if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) {
541+
const parser = new DOMParser();
542+
const dom = parser.parseFromString(res, "text/html");
543+
const rows = (dom.querySelector("#problemset > tbody")).rows;
544+
let problemList = [];
545+
for (let i = 0; i < rows.length; i++) {
546+
problemList.push({
547+
"title": rows[i].children[2].innerText,
548+
"url": rows[i].children[2].children[0].href
549+
});
550+
}
551+
localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList", JSON.stringify(problemList));
552+
if (RefreshList) location.reload();
553+
}
554+
} catch (e) {
555+
console.error(e);
556+
}
557+
}
558+
536559
// WebSocket Notification System
537560
let NotificationSocket = null;
538561
let NotificationSocketReconnectAttempts = 0;
@@ -1616,7 +1639,8 @@ async function main() {
16161639
border: 1px solid var(--bs-secondary-bg);
16171640
border-top: none;
16181641
border-radius: 0 0 0.3rem 0.3rem;
1619-
}`;
1642+
}
1643+
`;
16201644
}
16211645
if (UtilityEnabled("AddAnimation")) {
16221646
Style.innerHTML += `.status, .test-case {
@@ -2272,22 +2296,8 @@ async function main() {
22722296
}
22732297
let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList");
22742298
if (ContestProblemList == null) {
2275-
const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
2276-
const res = await contestReq.text();
2277-
if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) {
2278-
const parser = new DOMParser();
2279-
const dom = parser.parseFromString(res, "text/html");
2280-
const rows = (dom.querySelector("#problemset > tbody")).rows;
2281-
let problemList = [];
2282-
for (let i = 0; i < rows.length; i++) {
2283-
problemList.push({
2284-
"title": rows[i].children[2].innerText,
2285-
"url": rows[i].children[2].children[0].href
2286-
});
2287-
}
2288-
localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList", JSON.stringify(problemList));
2289-
ContestProblemList = JSON.stringify(problemList);
2290-
}
2299+
await unsafeWindow.GetContestProblemList(false);
2300+
ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList");
22912301
}
22922302

22932303
let problemSwitcher = document.createElement("div");
@@ -6093,4 +6103,4 @@ int main()
60936103

60946104
main().then(r => {
60956105
console.log("XMOJ-Script loaded successfully!");
6096-
});
6106+
});

0 commit comments

Comments
 (0)