-
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
a516f91
b0a0020
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4474,6 +4474,20 @@ 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 = ""; | ||||||
|
|
||||||
| 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 | ||||||
| }); | ||||||
| // This is the request that actually reaches submit.php, so the captcha is checked | ||||||
| // here as well as in the 提交 handler above. | ||||||
| if (CaptchaIsMissing()) return; | ||||||
|
|
@@ -4571,25 +4585,91 @@ async function main() { | |||||
| } | ||||||
| console.log(await Response.text()); | ||||||
| }); | ||||||
|
|
||||||
| } | ||||||
| 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."); | ||||||
| if (response.redirected) { | ||||||
|
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. P1: For a non-redirect response, the preceding Prompt for AI agents |
||||||
| location.href = response.url; | ||||||
| return; | ||||||
| } | ||||||
| } | ||||||
| ErrorMessage.innerText = "提交失败!请关闭脚本后重试!"; | ||||||
| Submit.disabled = false; | ||||||
| Submit.value = "提交"; | ||||||
| } | ||||||
| }) | ||||||
| }); | ||||||
| const text = await response.text(); | ||||||
| if ((text.indexOf("没有这个比赛!") !== -1 || text.indexOf("比赛已结束") !== -1) && new URL(location.href).searchParams.get("pid") !== null) { | ||||||
| // 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 | ||||||
|
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. P1: When the server requires a captcha, the retry submission omits the entered Prompt for AI agents
Suggested change
|
||||||
| }); | ||||||
| if (retryResp.redirected) { | ||||||
|
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: This replacement leaves the retry conditional and fetch callback unterminated before the next listener registration, so the userscript cannot parse. Restore the missing closing Prompt for AI agents |
||||||
| location.href = retryResp.url; | ||||||
| return; | ||||||
| const retryText = await retryResp.text(); | ||||||
| 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; | ||||||
| } | ||||||
| } catch (_) { | ||||||
| // 解析失败则使用默认信息 | ||||||
| } | ||||||
|
|
||||||
| _xmoj_disposeErrorMessageEditors(); | ||||||
| ErrorElement.style.display = "block"; | ||||||
| ErrorMessage.style.color = "red"; | ||||||
| ErrorMessage.innerText = "❌ 回退提交失败:" + errorMsg; | ||||||
| Submit.disabled = false; | ||||||
| Submit.value = "提交"; | ||||||
| return; | ||||||
|
|
||||||
| 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.