-
Notifications
You must be signed in to change notification settings - Fork 6
fix: 修复已结束比赛提交回退功能失效 #1017 #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: extern-contrib
Are you sure you want to change the base?
Changes from all commits
162d588
d724438
8b4a2c1
e40b292
c8ed5aa
e4f659f
d24fe86
1a75572
b789bf2
13058b6
c22fd31
6adac8d
f86a45e
84474cc
7950ae8
dfe8cf8
54d39cf
462621a
27863a7
280bc24
4a671fc
e3bbe9e
fab6593
2f7e9d6
e14e33c
7551f8c
d833b40
bdd5dc7
2126971
a6251c3
1aa1b02
5fe3558
5f70e73
d65ae84
6e587af
238bc2c
825161e
0e0a5eb
9f07ee2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4211,98 +4211,133 @@ async function main() { | |
| } | ||
|
|
||
| PassCheck.addEventListener("click", async () => { | ||
| ErrorElement.style.display = "none"; | ||
| document.querySelector("#Submit").disabled = true; | ||
| document.querySelector("#Submit").value = "正在提交..."; | ||
| let o2Switch = "&enable_O2=on"; | ||
| if (!document.querySelector("#enable_O2").checked) o2Switch = ""; | ||
| await fetch("https://www.xmoj.tech/submit.php", { | ||
| "headers": { | ||
| "content-type": "application/x-www-form-urlencoded" | ||
| }, | ||
| "referrer": location.href, | ||
| "method": "POST", | ||
| "body": (SearchParams.get("id") != null ? "id=" + SearchParams.get("id") : "cid=" + SearchParams.get("cid") + "&pid=" + SearchParams.get("pid")) + "&language=1&" + "source=" + encodeURIComponent(CodeMirrorElement.getValue()) + o2Switch | ||
| }).then(async (Response) => { | ||
| if (Response.redirected) { | ||
| location.href = Response.url; | ||
| } else { | ||
| const text = await Response.text(); | ||
| if (text.indexOf("没有这个比赛!") !== -1 && new URL(location.href).searchParams.get("pid") !== null) { | ||
| // Credit: https://github.com/boomzero/quicksubmit/blob/main/index.ts | ||
| // Also licensed under GPL-3.0 | ||
| const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + new URL(location.href).searchParams.get("cid")); | ||
| const res = await contestReq.text(); | ||
| if ( | ||
| contestReq.status !== 200 || | ||
| res.indexOf("比赛尚未开始或私有,不能查看题目。") !== -1 | ||
| ) { | ||
| console.error(`Failed to get contest page!`); | ||
| return; | ||
| } | ||
| const parser = new DOMParser(); | ||
| const dom = parser.parseFromString(res, "text/html"); | ||
| const contestProblems = []; | ||
| const rows = (dom.querySelector( | ||
| "#problemset > tbody", | ||
| )).rows; | ||
| for (let i = 0; i < rows.length; i++) { | ||
| contestProblems.push( | ||
| rows[i].children[1].textContent.substring(2, 6).replaceAll( | ||
| "\t", | ||
| "", | ||
| ), | ||
| ); | ||
| } | ||
| rPID = contestProblems[new URL(location.href).searchParams.get("pid")]; | ||
| if (UtilityEnabled("DebugMode")) { | ||
| console.log("Contest Problems:", contestProblems); | ||
| console.log("Real PID:", rPID); | ||
| } | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "red"; | ||
| try { _xmoj_disposeErrorMessageEditors(); } catch (e) { | ||
| console.error(e); | ||
| if (UtilityEnabled("DebugMode")) { | ||
| SmartAlert("XMOJ-Script internal error!\n\n" + e + "\n\n" + "If you see this message, please report it to the developer.\nDon't forget to include console logs and a way to reproduce the error!\n\nDon't want to see this message? Disable DebugMode."); | ||
| } | ||
| } | ||
| ErrorMessage.innerText = "比赛已结束, 正在尝试向题目 " + rPID + " 提交"; | ||
| console.log("比赛已结束, 正在尝试向题目 " + rPID + " 提交"); | ||
| let o2Switch = "&enable_O2=on"; | ||
| if (!document.querySelector("#enable_O2").checked) o2Switch = ""; | ||
| await fetch("https://www.xmoj.tech/submit.php", { | ||
| "headers": { | ||
| "content-type": "application/x-www-form-urlencoded" | ||
| }, | ||
| "referrer": location.href, | ||
| "method": "POST", | ||
| "body": "id=" + rPID + "&language=1&" + "source=" + encodeURIComponent(CodeMirrorElement.getValue()) + o2Switch | ||
| }).then(async (Response) => { | ||
| if (Response.redirected) { | ||
| location.href = Response.url; | ||
| } | ||
| console.log(await Response.text()); | ||
| }); | ||
| ErrorElement.style.display = "none"; | ||
| document.querySelector("#Submit").disabled = true; | ||
| document.querySelector("#Submit").value = "正在提交..."; | ||
| let o2Switch = "&enable_O2=on"; | ||
| if (!document.querySelector("#enable_O2").checked) o2Switch = ""; | ||
|
|
||
| const response = await fetch("https://www.xmoj.tech/submit.php", { | ||
| "headers": { | ||
| "content-type": "application/x-www-form-urlencoded" | ||
| }, | ||
| "referrer": location.href, | ||
| "method": "POST", | ||
| "body": (SearchParams.get("id") != null ? "id=" + SearchParams.get("id") : "cid=" + SearchParams.get("cid") + "&pid=" + SearchParams.get("pid")) + "&language=1&" + "source=" + encodeURIComponent(CodeMirrorElement.getValue()) + o2Switch | ||
| }); | ||
|
|
||
| } | ||
| if (UtilityEnabled("DebugMode")) { | ||
| console.log("Submission failed! Response:", text); | ||
| } | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "red"; | ||
| try { _xmoj_disposeErrorMessageEditors(); } catch (e) { | ||
| console.error(e); | ||
| if (UtilityEnabled("DebugMode")) { | ||
| SmartAlert("XMOJ-Script internal error!\n\n" + e + "\n\n" + "If you see this message, please report it to the developer.\nDon't forget to include console logs and a way to reproduce the error!\n\nDon't want to see this message? Disable DebugMode."); | ||
| } | ||
| } | ||
| ErrorMessage.innerText = "提交失败!请关闭脚本后重试!"; | ||
| Submit.disabled = false; | ||
| Submit.value = "提交"; | ||
| } | ||
| }) | ||
| }); | ||
| if (response.redirected) { | ||
| location.href = response.url; | ||
| return; | ||
| } | ||
|
|
||
| const text = await response.text(); | ||
|
|
||
| // 回退处理:比赛已结束或不存在,尝试直接提交到真实题目 | ||
| if ((text.indexOf("没有这个比赛!") !== -1 || text.indexOf("比赛已结束") !== -1) && new URL(location.href).searchParams.get("pid") !== null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The entire new block is indented at 4 spaces while the surrounding code of the PassCheck Prompt for AI agents |
||
| // Credit: https://github.com/boomzero/quicksubmit/blob/main/index.ts (GPL-3.0) | ||
| const cid = new URL(location.href).searchParams.get("cid"); | ||
| const pidIndex = new URL(location.href).searchParams.get("pid"); | ||
|
|
||
| const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + cid); | ||
| const res = await contestReq.text(); | ||
|
|
||
| if (contestReq.status !== 200 || res.indexOf("比赛尚未开始或私有,不能查看题目。") !== -1) { | ||
| console.error("Failed to get contest page!"); | ||
| _xmoj_disposeErrorMessageEditors(); | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "red"; | ||
| ErrorMessage.innerText = "无法获取比赛信息,请手动提交。"; | ||
| Submit.disabled = false; | ||
| Submit.value = "提交"; | ||
| return; | ||
| } | ||
|
|
||
| const parser = new DOMParser(); | ||
| const dom = parser.parseFromString(res, "text/html"); | ||
| const rows = dom.querySelector("#problemset > tbody").rows; | ||
| const contestProblems = []; | ||
|
|
||
| for (let i = 0; i < rows.length; i++) { | ||
| const cell = rows[i].children[1]; | ||
| const textContent = cell.textContent.trim(); | ||
| const match = textContent.match(/\d+/); | ||
| contestProblems.push(match ? match[0] : null); | ||
| } | ||
|
|
||
| const rPID = contestProblems[parseInt(pidIndex)]; | ||
| if (!rPID) { | ||
| _xmoj_disposeErrorMessageEditors(); | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "red"; | ||
| ErrorMessage.innerText = "无法解析真实题目 ID,请手动提交。"; | ||
| Submit.disabled = false; | ||
| Submit.value = "提交"; | ||
| return; | ||
| } | ||
|
|
||
| _xmoj_disposeErrorMessageEditors(); | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "orange"; | ||
| ErrorMessage.innerText = "比赛已结束,正在尝试向题目 " + rPID + " 提交…"; | ||
| console.log("比赛已结束,正在尝试向题目 " + rPID + " 提交"); | ||
|
|
||
| let o2Switch2 = "&enable_O2=on"; | ||
| if (!document.querySelector("#enable_O2").checked) o2Switch2 = ""; | ||
|
|
||
| const retryResp = await fetch("https://www.xmoj.tech/submit.php", { | ||
| "headers": { | ||
| "content-type": "application/x-www-form-urlencoded" | ||
| }, | ||
| "referrer": location.href, | ||
| "method": "POST", | ||
| "body": "id=" + rPID + "&language=1&source=" + encodeURIComponent(CodeMirrorElement.getValue()) + o2Switch2 | ||
| }); | ||
|
|
||
| // 检查是否提交成功(重定向 或 响应含成功标记) | ||
| // 检查是否提交成功(重定向 或 响应含成功标记) | ||
| if (retryResp.redirected) { | ||
| location.href = retryResp.url; | ||
| return; | ||
| } else { | ||
| const retryText = await retryResp.text(); | ||
| // ❌ 删除这里的成功关键词判断 —— 进入 else 就是失败 | ||
|
|
||
| // ✅ 直接从响应中提取错误信息 | ||
| let errorMsg = "提交失败,请重试。"; | ||
| try { | ||
| const dom2 = new DOMParser().parseFromString(retryText, "text/html"); | ||
| const jumbotron = dom2.querySelector(".jumbotron"); | ||
| if (jumbotron) { | ||
| errorMsg = jumbotron.textContent.trim(); | ||
| } else { | ||
| const textOnly = retryText.replace(/<[^>]*>/g, "").trim(); | ||
| errorMsg = textOnly.substring(0, 100) || errorMsg; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P0: The extra closing brace makes Prompt for AI agents |
||
| } catch (_) { | ||
| // 解析失败则使用默认信息 | ||
| } | ||
| _xmoj_disposeErrorMessageEditors(); | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "red"; | ||
| ErrorMessage.innerText = "❌ 回退提交失败:" + errorMsg; | ||
| Submit.disabled = false; | ||
| Submit.value = "提交"; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 如果未进入回退分支,显示通用错误 | ||
| if (UtilityEnabled("DebugMode")) { | ||
| console.log("Submission failed! Response:", text); | ||
| } | ||
| ErrorElement.style.display = "block"; | ||
| ErrorMessage.style.color = "red"; | ||
| ErrorMessage.innerText = "提交失败!请关闭脚本后重试!"; | ||
| Submit.disabled = false; | ||
| Submit.value = "提交"; | ||
| }); // ← 这是唯一正确的结束 | ||
|
|
||
| Submit.addEventListener("click", async () => { | ||
| PassCheck.style.display = "none"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| google.com, pub-6214673028530012, DIRECT, f08c47fec0942fa0 |
Uh oh!
There was an error while loading. Please reload this page.