Skip to content

Commit dfe8cf8

Browse files
authored
Merge pull request #874 from XMOJ-Script-dev/dev
Release
2 parents 7950ae8 + d299080 commit dfe8cf8

3 files changed

Lines changed: 177 additions & 5 deletions

File tree

Update.json

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,6 +3080,118 @@
30803080
}
30813081
],
30823082
"Notes": "请尽快升级至本版本!"
3083+
},
3084+
"2.4.1": {
3085+
"UpdateDate": 1759412851092,
3086+
"Prerelease": true,
3087+
"UpdateContents": [
3088+
{
3089+
"PR": 861,
3090+
"Description": "Update CSS selector"
3091+
}
3092+
],
3093+
"Notes": "No release notes were provided for this release."
3094+
},
3095+
"2.4.2": {
3096+
"UpdateDate": 1759413584731,
3097+
"Prerelease": true,
3098+
"UpdateContents": [
3099+
{
3100+
"PR": 863,
3101+
"Description": "修复“NaN年前“"
3102+
}
3103+
],
3104+
"Notes": "修复“NaN年前“"
3105+
},
3106+
"2.4.3": {
3107+
"UpdateDate": 1759414259108,
3108+
"Prerelease": true,
3109+
"UpdateContents": [
3110+
{
3111+
"PR": 865,
3112+
"Description": "删除获取数据功能"
3113+
}
3114+
],
3115+
"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 ..."
3127+
},
3128+
"2.4.5": {
3129+
"UpdateDate": 1759487413226,
3130+
"Prerelease": true,
3131+
"UpdateContents": [
3132+
{
3133+
"PR": 869,
3134+
"Description": "Update CSS selector (again...)"
3135+
}
3136+
],
3137+
"Notes": "为什么这个破东西老是换位置"
3138+
},
3139+
"2.4.6": {
3140+
"UpdateDate": 1759548958578,
3141+
"Prerelease": true,
3142+
"UpdateContents": [
3143+
{
3144+
"PR": 871,
3145+
"Description": "Add tooltip for ProblemSwitcher"
3146+
}
3147+
],
3148+
"Notes": "现在, 你只需要将鼠标悬浮在比赛题目切换器上方, 即可查看题目名称"
3149+
},
3150+
"2.4.7": {
3151+
"UpdateDate": 1759549826774,
3152+
"Prerelease": true,
3153+
"UpdateContents": [
3154+
{
3155+
"PR": 872,
3156+
"Description": "修复获取数据"
3157+
}
3158+
],
3159+
"Notes": "funny"
3160+
},
3161+
"2.5.0": {
3162+
"UpdateDate": 1759568103629,
3163+
"Prerelease": false,
3164+
"UpdateContents": [
3165+
{
3166+
"PR": 861,
3167+
"Description": "Update CSS selector"
3168+
},
3169+
{
3170+
"PR": 863,
3171+
"Description": "修复“NaN年前“"
3172+
},
3173+
{
3174+
"PR": 865,
3175+
"Description": "删除获取数据功能"
3176+
},
3177+
{
3178+
"PR": 866,
3179+
"Description": "比赛题目页面里左侧栏加入题目序号列表"
3180+
},
3181+
{
3182+
"PR": 869,
3183+
"Description": "Update CSS selector (again...)"
3184+
},
3185+
{
3186+
"PR": 871,
3187+
"Description": "Add tooltip for ProblemSwitcher"
3188+
},
3189+
{
3190+
"PR": 872,
3191+
"Description": "修复获取数据"
3192+
}
3193+
],
3194+
"Notes": "XMOJ-Script 2.5.0 新增了比赛题目切换器,方便您在题目之间快速切换。此功能默认启用,您也可以在设置中禁用它。本版本还修复了一个导致时间显示为“NaN年前”的错误, 更新了一些 CSS selector,以适应 XMOJ 网站的最新变化."
30833195
}
30843196
}
30853197
}

XMOJ.user.js

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 2.4.0
3+
// @version 2.5.0
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -81,7 +81,7 @@ let SmartAlert = (Message) => {
8181
*/
8282
let GetRelativeTime = (Input) => {
8383
try {
84-
Input = new Date(Input);
84+
Input = new Date(parseInt(Input));
8585
let Now = new Date().getTime();
8686
let Delta = Now - Input.getTime();
8787
let RelativeName = "";
@@ -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}" title="${problemList[i].title.trim()}" 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 = "没有此题目或题目对你不可见";
@@ -1669,6 +1723,12 @@ async function main() {
16691723
if (SubmitLink == null) {
16701724
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(9)');
16711725
}
1726+
if (SubmitLink == null) { //为什么这个破东西老是换位置
1727+
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(7)');
1728+
}
1729+
if (SubmitLink == null) { //tmd又换位置
1730+
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(8)');
1731+
}
16721732
let SubmitButton = document.createElement('button');
16731733
SubmitButton.id = 'SubmitButton';
16741734
SubmitButton.className = 'btn btn-outline-secondary';
@@ -3470,7 +3530,7 @@ int main()
34703530
break;
34713531
Input.push_back(Data);
34723532
}
3473-
throw runtime_error("[" + Base64Encode(Input.c_str()) + "]");
3533+
throw logic_error("[" + Base64Encode(Input.c_str()) + "]");
34743534
return 0;
34753535
}`;
34763536

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

0 commit comments

Comments
 (0)