From 73301183ce82fe2f96b23d0fca65187494be7a85 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 03:52:59 +0000 Subject: [PATCH 1/6] Initial plan From 064685c75ba82872234401a0900500432a995dbb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 03:59:55 +0000 Subject: [PATCH 2/6] Fix double submission bug by adding isPassCheckRunning guard Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com> --- XMOJ.user.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index 002c5a83..7e7979f7 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -2589,7 +2589,16 @@ async function main() { }); } + let isSubmitting = false; + let isPassCheckRunning = false; PassCheck.addEventListener("click", async () => { + if (isPassCheckRunning) { + if (UtilityEnabled("DebugMode")) { + console.log("PassCheck already running, ignoring click"); + } + return; + } + isPassCheckRunning = true; ErrorElement.style.display = "none"; document.querySelector("#Submit").disabled = true; document.querySelector("#Submit").value = "正在提交..."; @@ -2668,11 +2677,11 @@ async function main() { Submit.disabled = false; Submit.value = "提交"; isSubmitting = false; + isPassCheckRunning = false; } }) }); - let isSubmitting = false; Submit.addEventListener("click", async () => { if (isSubmitting) { return; From 4e8b29ed3b48ca1a2a98db782af483059d80bc96 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 04:01:04 +0000 Subject: [PATCH 3/6] Add comprehensive error handling for submission flows Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com> --- XMOJ.user.js | 68 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index 7e7979f7..db3316a5 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -522,7 +522,30 @@ let RequestAPI = (Action, Data, CallBack) => { CallBack(JSON.parse(Response.responseText)); } catch (Error) { console.log(Response.responseText); + // Call callback with error response + CallBack({ + Success: false, + Message: "解析响应失败,请重试" + }); + } + }, + onerror: (Error) => { + if (UtilityEnabled("DebugMode")) { + console.error("Request error for", Action + ":", Error); } + CallBack({ + Success: false, + Message: "网络请求失败,请检查网络连接" + }); + }, + ontimeout: () => { + if (UtilityEnabled("DebugMode")) { + console.error("Request timeout for", Action); + } + CallBack({ + Success: false, + Message: "请求超时,请重试" + }); } }); } catch (e) { @@ -2626,6 +2649,10 @@ async function main() { res.indexOf("比赛尚未开始或私有,不能查看题目。") !== -1 ) { console.error(`Failed to get contest page!`); + Submit.disabled = false; + Submit.value = "提交"; + isSubmitting = false; + isPassCheckRunning = false; return; } const parser = new DOMParser(); @@ -2679,6 +2706,17 @@ async function main() { isSubmitting = false; isPassCheckRunning = false; } + }).catch((error) => { + if (UtilityEnabled("DebugMode")) { + console.error("Submission request failed:", error); + } + ErrorElement.style.display = "block"; + ErrorMessage.style.color = "red"; + ErrorMessage.innerText = "提交失败!请检查网络后重试!"; + Submit.disabled = false; + Submit.value = "提交"; + isSubmitting = false; + isPassCheckRunning = false; }) }); @@ -2771,17 +2809,25 @@ async function main() { } }); }); - let Response = JSON.parse(ResponseData.responseText); - if (Response.returncode) { - PassCheck.style.display = ""; - ErrorElement.style.display = "block"; - if (UtilityEnabled("DarkMode")) ErrorMessage.style.color = "yellow"; else ErrorMessage.style.color = "red"; - ErrorMessage.innerText = "编译错误:\n" + Response.stderr.trim(); - document.querySelector("#Submit").disabled = false; - document.querySelector("#Submit").value = "提交"; - isSubmitting = false; - return false; - } else { + try { + let Response = JSON.parse(ResponseData.responseText); + if (Response.returncode) { + PassCheck.style.display = ""; + ErrorElement.style.display = "block"; + if (UtilityEnabled("DarkMode")) ErrorMessage.style.color = "yellow"; else ErrorMessage.style.color = "red"; + ErrorMessage.innerText = "编译错误:\n" + Response.stderr.trim(); + document.querySelector("#Submit").disabled = false; + document.querySelector("#Submit").value = "提交"; + isSubmitting = false; + return false; + } else { + PassCheck.click(); + } + } catch (error) { + if (UtilityEnabled("DebugMode")) { + console.error("Failed to parse compile check response:", error); + } + // If parse fails, proceed with submission anyway PassCheck.click(); } } else { From 6c2013043ed527f53efd2b51921c02f5d1f97556 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 05:12:19 +0000 Subject: [PATCH 4/6] Fix EditArea conflict and add PassCheck.disabled guard Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com> --- XMOJ.user.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/XMOJ.user.js b/XMOJ.user.js index db3316a5..faca0f69 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -2566,6 +2566,16 @@ async function main() { } } } else if (location.pathname == "/submitpage.php") { + // Disable EditArea if it's loaded by the original page + if (typeof editAreaLoader !== 'undefined') { + try { + editAreaLoader.delete_instance('source'); + } catch (e) { + if (UtilityEnabled("DebugMode")) { + console.log("EditArea cleanup failed (expected):", e); + } + } + } document.title = "提交代码: " + (SearchParams.get("id") != null ? "题目" + Number(SearchParams.get("id")) : "比赛" + Number(SearchParams.get("cid"))); document.querySelector("body > div > div.mt-3").innerHTML = `