Skip to content

Commit 462621a

Browse files
Merge pull request #891 from XMOJ-Script-dev/dev
Sync Dev
2 parents 54d39cf + 8e01ee2 commit 462621a

11 files changed

Lines changed: 147 additions & 38 deletions

.github/workflows/AutoLabelIssue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v5
12+
uses: actions/checkout@v6
1313
with:
1414
fetch-depth: 0
1515
- name: Generate a token

.github/workflows/CodeQL.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
steps:
22-
- uses: actions/checkout@v5
22+
- uses: actions/checkout@v6
2323
- uses: github/codeql-action/init@v3
2424
with:
2525
languages: "javascript"

.github/workflows/DependencyScan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ jobs:
99
dependency-review:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v5
12+
- uses: actions/checkout@v6
1313
- uses: actions/dependency-review-action@v4

.github/workflows/Prerelease.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ jobs:
2121
with:
2222
node-version: 16
2323
registry-url: https://registry.npmjs.org/
24-
- uses: actions/checkout@v5
24+
- uses: actions/checkout@v6
2525
with:
2626
fetch-depth: 0
27-
- name: Publish to npm
28-
run: npm publish --provenance
29-
env:
30-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
27+
# - name: Publish to npm
28+
# run: npm publish --provenance
29+
# env:
30+
# NODE_AUTH_TOKEN: ${{secrets.npm_token}}
3131
- name: Get version
3232
env:
3333
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}

.github/workflows/Release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
with:
2121
node-version: 16
2222
registry-url: https://registry.npmjs.org/
23-
- uses: actions/checkout@v5
23+
- uses: actions/checkout@v6
2424
with:
2525
fetch-depth: 0
2626
- name: Get version

.github/workflows/UpdateVersion.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ jobs:
1414
pull-requests: write
1515
contents: write
1616
runs-on: ubuntu-latest
17+
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'github-actions[bot]'
1718
steps:
1819
- name: Generate a token
1920
id: generate_token
2021
uses: actions/create-github-app-token@v2
2122
with:
2223
app-id: ${{ secrets.APP_ID }}
2324
private-key: ${{ secrets.APP_PRIVATE_KEY }}
24-
- uses: actions/checkout@v5
25+
- uses: actions/checkout@v6
2526
- name: Update version
2627
env:
2728
PR_BODY: ${{ github.event.pull_request.body }}

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
pull-requests: write
1616
checks: write
1717
steps:
18-
- uses: actions/checkout@v5
18+
- uses: actions/checkout@v6
1919
with:
2020
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
2121
fetch-depth: 0 # a full history is required for pull request analysis

.github/workflows/sync-to-extern-contrib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Syncing branches
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v5
13+
uses: actions/checkout@v6
1414
- name: Set up Node
1515
uses: actions/setup-node@v4
1616
with:

Update.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,102 @@
31923192
}
31933193
],
31943194
"Notes": "XMOJ-Script 2.5.0 新增了比赛题目切换器,方便您在题目之间快速切换。此功能默认启用,您也可以在设置中禁用它。本版本还修复了一个导致时间显示为“NaN年前”的错误, 更新了一些 CSS selector,以适应 XMOJ 网站的最新变化."
3195+
},
3196+
"2.5.1": {
3197+
"UpdateDate": 1759830659949,
3198+
"Prerelease": true,
3199+
"UpdateContents": [
3200+
{
3201+
"PR": 876,
3202+
"Description": "refactor: simplify SubmitLink selection by querying all anchors and finding by text"
3203+
}
3204+
],
3205+
"Notes": "No release notes were provided for this release."
3206+
},
3207+
"2.5.2": {
3208+
"UpdateDate": 1759845614758,
3209+
"Prerelease": true,
3210+
"UpdateContents": [
3211+
{
3212+
"PR": 877,
3213+
"Description": "fix: problem PID 可能为 null"
3214+
}
3215+
],
3216+
"Notes": "No release notes were provided for this release."
3217+
},
3218+
"2.5.3": {
3219+
"UpdateDate": 1770358959413,
3220+
"Prerelease": true,
3221+
"UpdateContents": [
3222+
{
3223+
"PR": 888,
3224+
"Description": "Fix AC code export for 5-digit question IDs"
3225+
}
3226+
],
3227+
"Notes": "No release notes were provided for this release."
3228+
},
3229+
"2.6.0": {
3230+
"UpdateDate": 1770426020324,
3231+
"Prerelease": false,
3232+
"UpdateContents": [
3233+
{
3234+
"PR": 876,
3235+
"Description": "refactor: simplify SubmitLink selection by querying all anchors and finding by text"
3236+
},
3237+
{
3238+
"PR": 877,
3239+
"Description": "fix: problem PID 可能为 null"
3240+
},
3241+
{
3242+
"PR": 888,
3243+
"Description": "Fix AC code export for 5-digit question IDs"
3244+
}
3245+
],
3246+
"Notes": "No release notes were provided for this release."
3247+
},
3248+
"2.6.1": {
3249+
"UpdateDate": 1770426401298,
3250+
"Prerelease": true,
3251+
"UpdateContents": [
3252+
{
3253+
"PR": 892,
3254+
"Description": "Update to release 2.6.0"
3255+
}
3256+
],
3257+
"Notes": "No release notes were provided for this release."
3258+
},
3259+
"2.7.0": {
3260+
"UpdateDate": 1770426883598,
3261+
"Prerelease": false,
3262+
"UpdateContents": [
3263+
{
3264+
"PR": 892,
3265+
"Description": "Update to release 2.6.0"
3266+
}
3267+
],
3268+
"Notes": "No release notes were provided for this release."
3269+
},
3270+
"2.7.1": {
3271+
"UpdateDate": 1770426896026,
3272+
"Prerelease": true,
3273+
"UpdateContents": [
3274+
{
3275+
"PR": 895,
3276+
"Description": "Update to release 2.7.0"
3277+
}
3278+
],
3279+
"Notes": "No release notes were provided for this release."
3280+
},
3281+
"2.7.2": {
3282+
"UpdateDate": 1770429143486,
3283+
"Prerelease": true,
3284+
"UpdateContents": [
3285+
{
3286+
"PR": 896,
3287+
"Description": "Update to release 2.7.0"
3288+
}
3289+
],
3290+
"Notes": "No release notes were provided for this release."
31953291
}
31963292
}
31973293
}

XMOJ.user.js

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 2.5.0
3+
// @version 2.7.2
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -1645,7 +1645,28 @@ async function main() {
16451645
} else if (location.pathname == "/problem.php") {
16461646
await RenderMathJax();
16471647
if (SearchParams.get("cid") != null && UtilityEnabled("ProblemSwitcher")) {
1648-
document.getElementsByTagName("h2")[0].innerHTML += " (" + localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID") + ")";
1648+
let pid = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID");
1649+
if (!pid) {
1650+
const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
1651+
const res = await contestReq.text();
1652+
if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) {
1653+
const parser = new DOMParser();
1654+
const dom = parser.parseFromString(res, "text/html");
1655+
const rows = (dom.querySelector("#problemset > tbody")).rows;
1656+
for (let i = 0; i < rows.length; i++) {
1657+
let problemIdText = rows[i].children[1].innerText; // Get the text content
1658+
let match = problemIdText.match(/\d+/); // Extract the number
1659+
if (match) {
1660+
let extractedPid = match[0];
1661+
localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + i + "-PID", extractedPid);
1662+
}
1663+
}
1664+
pid = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID");
1665+
}
1666+
}
1667+
if (pid) {
1668+
document.getElementsByTagName("h2")[0].innerHTML += " (" + pid + ")";
1669+
}
16491670
let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList");
16501671
if (ContestProblemList == null) {
16511672
const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
@@ -1710,25 +1731,8 @@ async function main() {
17101731
document.querySelector("body > div > div.mt-3 > center").lastElementChild.style.marginLeft = "10px";
17111732
}
17121733
//修复提交按钮
1713-
let SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(12)');
1714-
if (SubmitLink == null) { //a special type of problem
1715-
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(10)');
1716-
}
1717-
if (SubmitLink == null) {
1718-
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(11)');
1719-
}
1720-
if (SubmitLink == null) {
1721-
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(13)');
1722-
}
1723-
if (SubmitLink == null) {
1724-
SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(9)');
1725-
}
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-
}
1734+
const links = document.querySelectorAll('.mt-3 > center:nth-child(1) > a');
1735+
const SubmitLink = Array.from(links).find(a => a.textContent.trim() === '提交');
17321736
let SubmitButton = document.createElement('button');
17331737
SubmitButton.id = 'SubmitButton';
17341738
SubmitButton.className = 'btn btn-outline-secondary';
@@ -1744,8 +1748,7 @@ async function main() {
17441748
// Remove the button's outer []
17451749
let str = document.querySelector('.mt-3 > center:nth-child(1)').innerHTML;
17461750
let target = SubmitButton.outerHTML;
1747-
let result = str.replace(new RegExp(`(.?)${target}(.?)`, 'g'), target);
1748-
document.querySelector('.mt-3 > center:nth-child(1)').innerHTML = result;
1751+
document.querySelector('.mt-3 > center:nth-child(1)').innerHTML = str.replace(new RegExp(`(.?)${target}(.?)`, 'g'), target);
17491752
document.querySelector('html body.placeholder-glow div.container div.mt-3 center button#SubmitButton.btn.btn-outline-secondary').onclick = function () {
17501753
window.location.href = SubmitLink.href;
17511754
console.log(SubmitLink.href);
@@ -2999,8 +3002,17 @@ async function main() {
29993002
for (let i = 0; i < ACCode.length; i++) {
30003003
let CurrentCode = ACCode[i];
30013004
if (CurrentCode != "") {
3002-
let CurrentQuestionID = CurrentCode.substring(7, 11);
3003-
CurrentCode = CurrentCode.substring(14);
3005+
let lineBreakPos = CurrentCode.search(/[\r\n]/);
3006+
if (lineBreakPos === -1) continue;
3007+
let headerLine = CurrentCode.slice(0, lineBreakPos);
3008+
let digitMatch = headerLine.match(/\d+/);
3009+
if (!digitMatch) continue;
3010+
let CurrentQuestionID = digitMatch[0];
3011+
let bodyStart = lineBreakPos + 1;
3012+
if (CurrentCode[lineBreakPos] === '\r' && CurrentCode[lineBreakPos + 1] === '\n') {
3013+
bodyStart = lineBreakPos + 2;
3014+
}
3015+
CurrentCode = CurrentCode.slice(bodyStart);
30043016
CurrentCode = CurrentCode.replaceAll("\r", "");
30053017
Zip.file(CurrentQuestionID + ".cpp", CurrentCode);
30063018
}

0 commit comments

Comments
 (0)