Skip to content

Commit 0a1055c

Browse files
Merge pull request #867 from XMOJ-Script-dev/dev
sync: dev to extern-contrib
2 parents 233b268 + 491d3b6 commit 0a1055c

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

Update.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,17 @@
31133113
}
31143114
],
31153115
"Notes": "因为它利用的bug被修复了"
3116+
},
3117+
"2.4.4": {
3118+
"UpdateDate": 1759417362937,
3119+
"Prerelease": true,
3120+
"UpdateContents": [
3121+
{
3122+
"PR": 866,
3123+
"Description": "比赛题目页面里左侧栏加入题目序号列表"
3124+
}
3125+
],
3126+
"Notes": "#860 ..."
31163127
}
31173128
}
31183129
}

XMOJ.user.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 2.4.3
3+
// @version 2.4.4
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -1506,6 +1506,8 @@ async function main() {
15061506
}, {
15071507
"ID": "RefreshSolution", "Type": "F", "Name": "状态页面结果自动刷新每次只能刷新一个"
15081508
}, {"ID": "CopyMD", "Type": "A", "Name": "复制题目或题解内容"}, {
1509+
"ID": "ProblemSwitcher", "Type": "A", "Name": "比赛题目切换器"
1510+
}, {
15091511
"ID": "OpenAllProblem", "Type": "A", "Name": "比赛题目界面一键打开所有题目"
15101512
}, {
15111513
"ID": "CheckCode", "Type": "A", "Name": "提交代码前对代码进行检查", "Children": [{
@@ -1642,8 +1644,60 @@ async function main() {
16421644
}
16431645
} else if (location.pathname == "/problem.php") {
16441646
await RenderMathJax();
1645-
if (SearchParams.get("cid") != null) {
1647+
if (SearchParams.get("cid") != null && UtilityEnabled("ProblemSwitcher")) {
16461648
document.getElementsByTagName("h2")[0].innerHTML += " (" + localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID") + ")";
1649+
let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList");
1650+
if (ContestProblemList == null) {
1651+
const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
1652+
const res = await contestReq.text();
1653+
if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) {
1654+
const parser = new DOMParser();
1655+
const dom = parser.parseFromString(res, "text/html");
1656+
const rows = (dom.querySelector("#problemset > tbody")).rows;
1657+
let problemList = [];
1658+
for (let i = 0; i < rows.length; i++) {
1659+
problemList.push({
1660+
"title": rows[i].children[2].innerText,
1661+
"url": rows[i].children[2].children[0].href
1662+
});
1663+
}
1664+
localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList", JSON.stringify(problemList));
1665+
ContestProblemList = JSON.stringify(problemList);
1666+
}
1667+
}
1668+
1669+
let problemSwitcher = document.createElement("div");
1670+
problemSwitcher.style.position = "fixed";
1671+
problemSwitcher.style.top = "50%";
1672+
problemSwitcher.style.left = "0";
1673+
problemSwitcher.style.transform = "translateY(-50%)";
1674+
problemSwitcher.style.maxHeight = "80vh";
1675+
problemSwitcher.style.overflowY = "auto";
1676+
if (document.querySelector("html").getAttribute("data-bs-theme") == "dark") {
1677+
problemSwitcher.style.backgroundColor = "rgba(0, 0, 0, 0.8)";
1678+
} else {
1679+
problemSwitcher.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
1680+
}
1681+
problemSwitcher.style.padding = "10px";
1682+
problemSwitcher.style.borderRadius = "0 10px 10px 0";
1683+
problemSwitcher.style.display = "flex";
1684+
problemSwitcher.style.flexDirection = "column";
1685+
1686+
let problemList = JSON.parse(ContestProblemList);
1687+
for (let i = 0; i < problemList.length; i++) {
1688+
let buttonText = "";
1689+
if (i < 26) {
1690+
buttonText = String.fromCharCode(65 + i);
1691+
} else {
1692+
buttonText = String.fromCharCode(97 + (i - 26));
1693+
}
1694+
let activeClass = "";
1695+
if (problemList[i].url === location.href) {
1696+
activeClass = "active";
1697+
}
1698+
problemSwitcher.innerHTML += `<a href="${problemList[i].url}" class="btn btn-outline-secondary mb-2 ${activeClass}">${buttonText}</a>`;
1699+
}
1700+
document.body.appendChild(problemSwitcher);
16471701
}
16481702
if (document.querySelector("body > div > div.mt-3 > h2") != null) {
16491703
document.querySelector("body > div > div.mt-3").innerHTML = "没有此题目或题目对你不可见";

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.4.3",
3+
"version": "2.4.4",
44
"description": "an improvement script for xmoj.tech",
55
"main": "AddonScript.js",
66
"scripts": {

0 commit comments

Comments
 (0)