diff --git a/.github/workflows/AutoLabelIssue.yml b/.github/workflows/AutoLabelIssue.yml index 7a11f5863..58ccb0494 100644 --- a/.github/workflows/AutoLabelIssue.yml +++ b/.github/workflows/AutoLabelIssue.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: fetch-depth: 0 - name: Generate a token diff --git a/.github/workflows/CodeQL.yml b/.github/workflows/CodeQL.yml index 425a2cfcb..ceb39ff13 100644 --- a/.github/workflows/CodeQL.yml +++ b/.github/workflows/CodeQL.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: github/codeql-action/init@v3 with: languages: "javascript" diff --git a/.github/workflows/DependencyScan.yml b/.github/workflows/DependencyScan.yml index 73b3298d7..605309c7e 100644 --- a/.github/workflows/DependencyScan.yml +++ b/.github/workflows/DependencyScan.yml @@ -9,5 +9,5 @@ jobs: dependency-review: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: actions/dependency-review-action@v4 diff --git a/.github/workflows/Prerelease.yml b/.github/workflows/Prerelease.yml index fc97e2da5..387437f08 100644 --- a/.github/workflows/Prerelease.yml +++ b/.github/workflows/Prerelease.yml @@ -21,13 +21,13 @@ jobs: with: node-version: 16 registry-url: https://registry.npmjs.org/ - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: fetch-depth: 0 - - name: Publish to npm - run: npm publish --provenance - env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + # - name: Publish to npm + # run: npm publish --provenance + # env: + # NODE_AUTH_TOKEN: ${{secrets.npm_token}} - name: Get version env: GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 548b0e02e..e9c591396 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -20,7 +20,7 @@ jobs: with: node-version: 16 registry-url: https://registry.npmjs.org/ - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Get version diff --git a/.github/workflows/UpdateToRelease.yml b/.github/workflows/UpdateToRelease.yml index e401f757a..5f82aa0fb 100644 --- a/.github/workflows/UpdateToRelease.yml +++ b/.github/workflows/UpdateToRelease.yml @@ -11,11 +11,13 @@ on: jobs: UpdateToRelease: runs-on: ubuntu-latest + # 添加条件:如果是 bot 触发的则跳过,避免无限循环 + if: github.event.pull_request.user.login != 'github-actions[bot]' permissions: pull-requests: write contents: write steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Update to release @@ -25,7 +27,7 @@ jobs: gh pr comment ${{ github.event.pull_request.number }} --body "请向\`dev\`分支提交pull request, 本pull request将被自动关闭" gh pr close ${{ github.event.pull_request.number }} else - node ./Update/UpdateToRelease.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }} "$PR_BODY" + node ./Update/UpdateToRelease.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.pull_request.number }} "$PR_BODY" fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/UpdateVersion.yml b/.github/workflows/UpdateVersion.yml index b71fbb1f2..74a492246 100644 --- a/.github/workflows/UpdateVersion.yml +++ b/.github/workflows/UpdateVersion.yml @@ -14,6 +14,7 @@ jobs: pull-requests: write contents: write runs-on: ubuntu-latest + if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'github-actions[bot]' steps: - name: Generate a token id: generate_token @@ -21,7 +22,7 @@ jobs: with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Update version env: PR_BODY: ${{ github.event.pull_request.body }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 73a6a4412..fdd59cbdb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: pull-requests: write checks: write steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit fetch-depth: 0 # a full history is required for pull request analysis diff --git a/.github/workflows/sync-to-extern-contrib.yml b/.github/workflows/sync-to-extern-contrib.yml index d9a0da5b1..2bb08cb94 100644 --- a/.github/workflows/sync-to-extern-contrib.yml +++ b/.github/workflows/sync-to-extern-contrib.yml @@ -10,7 +10,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Set up Node uses: actions/setup-node@v4 with: diff --git a/Update.json b/Update.json index 7c45a663d..1c7bd178f 100644 --- a/Update.json +++ b/Update.json @@ -3192,6 +3192,102 @@ } ], "Notes": "XMOJ-Script 2.5.0 新增了比赛题目切换器,方便您在题目之间快速切换。此功能默认启用,您也可以在设置中禁用它。本版本还修复了一个导致时间显示为“NaN年前”的错误, 更新了一些 CSS selector,以适应 XMOJ 网站的最新变化." + }, + "2.5.1": { + "UpdateDate": 1759830659949, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 876, + "Description": "refactor: simplify SubmitLink selection by querying all anchors and finding by text" + } + ], + "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." + }, + "2.5.3": { + "UpdateDate": 1770358959413, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 888, + "Description": "Fix AC code export for 5-digit question IDs" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.6.0": { + "UpdateDate": 1770426020324, + "Prerelease": false, + "UpdateContents": [ + { + "PR": 876, + "Description": "refactor: simplify SubmitLink selection by querying all anchors and finding by text" + }, + { + "PR": 877, + "Description": "fix: problem PID 可能为 null" + }, + { + "PR": 888, + "Description": "Fix AC code export for 5-digit question IDs" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.6.1": { + "UpdateDate": 1770426401298, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 892, + "Description": "Update to release 2.6.0" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.7.0": { + "UpdateDate": 1770426883598, + "Prerelease": false, + "UpdateContents": [ + { + "PR": 892, + "Description": "Update to release 2.6.0" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.7.1": { + "UpdateDate": 1770426896026, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 895, + "Description": "Update to release 2.7.0" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.7.2": { + "UpdateDate": 1770429143486, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 896, + "Description": "Update to release 2.7.0" + } + ], + "Notes": "No release notes were provided for this release." } } } \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index 9382516ba..035aa0e00 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 2.5.0 +// @version 2.7.2 // @description XMOJ增强脚本 // @author @XMOJ-Script-dev, @langningchen and the community // @namespace https://github/langningchen @@ -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")); @@ -1710,25 +1731,8 @@ async function main() { document.querySelector("body > div > div.mt-3 > center").lastElementChild.style.marginLeft = "10px"; } //修复提交按钮 - let SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(12)'); - if (SubmitLink == null) { //a special type of problem - SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(10)'); - } - if (SubmitLink == null) { - SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(11)'); - } - if (SubmitLink == null) { - SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(13)'); - } - if (SubmitLink == null) { - SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(9)'); - } - if (SubmitLink == null) { //为什么这个破东西老是换位置 - SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(7)'); - } - if (SubmitLink == null) { //tmd又换位置 - SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(8)'); - } + const links = document.querySelectorAll('.mt-3 > center:nth-child(1) > a'); + const SubmitLink = Array.from(links).find(a => a.textContent.trim() === '提交'); let SubmitButton = document.createElement('button'); SubmitButton.id = 'SubmitButton'; SubmitButton.className = 'btn btn-outline-secondary'; @@ -1744,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); @@ -2999,8 +3002,17 @@ async function main() { for (let i = 0; i < ACCode.length; i++) { let CurrentCode = ACCode[i]; if (CurrentCode != "") { - let CurrentQuestionID = CurrentCode.substring(7, 11); - CurrentCode = CurrentCode.substring(14); + let lineBreakPos = CurrentCode.search(/[\r\n]/); + if (lineBreakPos === -1) continue; + let headerLine = CurrentCode.slice(0, lineBreakPos); + let digitMatch = headerLine.match(/\d+/); + if (!digitMatch) continue; + let CurrentQuestionID = digitMatch[0]; + let bodyStart = lineBreakPos + 1; + if (CurrentCode[lineBreakPos] === '\r' && CurrentCode[lineBreakPos + 1] === '\n') { + bodyStart = lineBreakPos + 2; + } + CurrentCode = CurrentCode.slice(bodyStart); CurrentCode = CurrentCode.replaceAll("\r", ""); Zip.file(CurrentQuestionID + ".cpp", CurrentCode); } diff --git a/package.json b/package.json index b05985188..d558b7acf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmoj-script", - "version": "2.5.0", + "version": "2.7.2", "description": "an improvement script for xmoj.tech", "main": "AddonScript.js", "scripts": {