diff --git a/XMOJ.user.js b/XMOJ.user.js
index 002c5a83..c97feffa 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) {
@@ -2543,6 +2566,17 @@ 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) {
+ // EditArea instance may not exist yet or already deleted - this is fine
+ if (UtilityEnabled("DebugMode")) {
+ console.log("EditArea instance not found or already deleted:", e);
+ }
+ }
+ }
document.title = "提交代码: " + (SearchParams.get("id") != null ? "题目" + Number(SearchParams.get("id")) : "比赛" + Number(SearchParams.get("cid")));
document.querySelector("body > div > div.mt-3").innerHTML = `
` + `提交代码
` + (SearchParams.get("id") != null ? `题目${Number(SearchParams.get("id"))}` : `比赛${Number(SearchParams.get("cid")) + ` 题目` + String.fromCharCode(65 + parseInt(SearchParams.get("pid")))}`) + `
@@ -2589,7 +2623,23 @@ async function main() {
});
}
+ let isSubmitting = false;
+ let isPassCheckRunning = false;
PassCheck.addEventListener("click", async () => {
+ if (UtilityEnabled("DebugMode")) {
+ console.log("PassCheck clicked, isPassCheckRunning =", isPassCheckRunning, "PassCheck.disabled =", PassCheck.disabled);
+ }
+ if (isPassCheckRunning || PassCheck.disabled) {
+ if (UtilityEnabled("DebugMode")) {
+ console.log("PassCheck already running or disabled, ignoring click");
+ }
+ return;
+ }
+ isPassCheckRunning = true;
+ PassCheck.disabled = true;
+ if (UtilityEnabled("DebugMode")) {
+ console.log("PassCheck starting submission");
+ }
ErrorElement.style.display = "none";
document.querySelector("#Submit").disabled = true;
document.querySelector("#Submit").value = "正在提交...";
@@ -2617,6 +2667,11 @@ async function main() {
res.indexOf("比赛尚未开始或私有,不能查看题目。") !== -1
) {
console.error(`Failed to get contest page!`);
+ Submit.disabled = false;
+ Submit.value = "提交";
+ PassCheck.disabled = false;
+ isSubmitting = false;
+ isPassCheckRunning = false;
return;
}
const parser = new DOMParser();
@@ -2667,14 +2722,33 @@ async function main() {
ErrorMessage.innerText = "提交失败!请关闭脚本后重试!";
Submit.disabled = false;
Submit.value = "提交";
+ PassCheck.disabled = false;
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 = "提交";
+ PassCheck.disabled = false;
+ isSubmitting = false;
+ isPassCheckRunning = false;
})
});
- let isSubmitting = false;
Submit.addEventListener("click", async () => {
+ if (UtilityEnabled("DebugMode")) {
+ console.log("Submit clicked, isSubmitting =", isSubmitting);
+ }
if (isSubmitting) {
+ if (UtilityEnabled("DebugMode")) {
+ console.log("Already submitting, ignoring click");
+ }
return;
}
isSubmitting = true;
@@ -2762,17 +2836,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 {