diff --git a/Update.json b/Update.json index 35811b63..41b3a816 100644 --- a/Update.json +++ b/Update.json @@ -2937,7 +2937,7 @@ ], "Notes": "No release notes were provided for this release." }, - "1.10.0": { + "1.999990.0": { "UpdateDate": 1753443146018, "Prerelease": false, "UpdateContents": [ @@ -3718,4 +3718,4 @@ "Notes": "优化“获取数据”功能:页面缺少数据申请区域时会自动创建控件;默认使用 gzip + Base93 精确保留任意输入;新增约 310 MB/s 的 NSC3 高速数值模式,同时压缩 long long 数值与行结构并对混合内容原样回退;新增“保留换行”选项,默认精确保留,使用 cin >> 等空白不敏感读取时可关闭,从而避免大量随机行长占用输出;生成程序现在先向 stderr 输出并刷新数据,再通过 abort() 可靠触发 RE,同时兼容读取旧版异常包装的结果。" } } -} \ No newline at end of file +} diff --git a/XMOJ.user.js b/XMOJ.user.js index 3cb45de7..b73c7b41 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -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) { + // 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; + } + } 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"; diff --git a/ads.txt b/ads.txt new file mode 100644 index 00000000..8118328f --- /dev/null +++ b/ads.txt @@ -0,0 +1 @@ +google.com, pub-6214673028530012, DIRECT, f08c47fec0942fa0 diff --git a/index.html b/index.html index fda3f205..d45dbd70 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,6 @@ -