Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 94 additions & 12 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = `<center class="mb-3">` + `<h3>提交代码</h3>` + (SearchParams.get("id") != null ? `题目<span class="blue">${Number(SearchParams.get("id"))}</span>` : `比赛<span class="blue">${Number(SearchParams.get("cid")) + `</span>&emsp;题目<span class="blue">` + String.fromCharCode(65 + parseInt(SearchParams.get("pid")))}</span>`) + `</center>
<textarea id="CodeInput"></textarea>
Expand Down Expand Up @@ -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 = "正在提交...";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down