题目编号
@@ -3453,7 +4049,7 @@ async function main() {
if (UtilityEnabled("ImproveACRate")) {
let ImproveACRateButton = document.createElement("button");
- document.querySelector("body > div.container > div > div.input-append").appendChild(ImproveACRateButton);
+ if (document.querySelector("body > div.container > div > div.input-append") != null) document.querySelector("body > div.container > div > div.input-append").appendChild(ImproveACRateButton);
ImproveACRateButton.className = "btn btn-outline-secondary";
ImproveACRateButton.innerText = "提高正确率";
ImproveACRateButton.disabled = true;
@@ -3463,12 +4059,15 @@ async function main() {
return Response.text();
}).then((Response) => {
let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
- ImproveACRateButton.innerText += "(" + (parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(4) > td:nth-child(2)").innerText) / parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(3) > td:nth-child(2)").innerText) * 100).toFixed(2) + "%)";
- let Temp = ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script").innerText.split("\n")[5].split(";");
+ if (ParsedDocument.querySelector("#statics > tbody > tr:nth-child(4) > td:nth-child(2)") != null && ParsedDocument.querySelector("#statics > tbody > tr:nth-child(3) > td:nth-child(2)") != null) ImproveACRateButton.innerText += "(" + (parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(4) > td:nth-child(2)").innerText) / parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(3) > td:nth-child(2)").innerText) * 100).toFixed(2) + "%)";
+ let Temp = (ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script") != null) ? ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script").innerText.split("\n")[5].split(";") : [];
for (let i = 0; i < Temp.length; i++) {
ACProblems.push(Number(Temp[i].substring(2, Temp[i].indexOf(","))));
}
- ImproveACRateButton.disabled = false;
+ //没有解析到已通过的题目时保持禁用,避免用无效的题号提交
+ if (ACProblems.length > 0) {
+ ImproveACRateButton.disabled = false;
+ }
});
ImproveACRateButton.addEventListener("click", async () => {
ImproveACRateButton.disabled = true;
@@ -3488,8 +4087,13 @@ async function main() {
return Result.text();
}).then((Result) => {
let ParsedDocument = new DOMParser().parseFromString(Result, "text/html");
- SID = ParsedDocument.querySelector("#result-tab > tbody > tr:nth-child(1) > td:nth-child(2)").innerText;
+ if (ParsedDocument.querySelector("#result-tab > tbody > tr:nth-child(1) > td:nth-child(2)") != null) SID = ParsedDocument.querySelector("#result-tab > tbody > tr:nth-child(1) > td:nth-child(2)").innerText;
});
+ //没有找到提交记录时跳过本次,避免提交错误的代码
+ if (SID == 0) {
+ Count++;
+ return;
+ }
let Code = "";
await fetch("https://www.xmoj.tech/getsource.php?id=" + SID)
.then((Response) => {
@@ -3513,7 +4117,7 @@ async function main() {
}
if (UtilityEnabled("CompareSource")) {
let CompareButton = document.createElement("button");
- document.querySelector("body > div.container > div > div.input-append").appendChild(CompareButton);
+ if (document.querySelector("body > div.container > div > div.input-append") != null) document.querySelector("body > div.container > div > div.input-append").appendChild(CompareButton);
CompareButton.className = "btn btn-outline-secondary";
CompareButton.innerText = "比较提交记录";
CompareButton.addEventListener("click", () => {
@@ -3522,11 +4126,11 @@ async function main() {
CompareButton.style.marginBottom = "7px";
}
if (UtilityEnabled("ResetType")) {
- document.querySelector("#result-tab > thead > tr > th:nth-child(1)").remove();
- document.querySelector("#result-tab > thead > tr > th:nth-child(2)").remove();
- document.querySelector("#result-tab > thead > tr > th:nth-child(10)").innerHTML = "开启O2";
+ if (document.querySelector("#result-tab > thead > tr > th:nth-child(1)") != null) document.querySelector("#result-tab > thead > tr > th:nth-child(1)").remove();
+ if (document.querySelector("#result-tab > thead > tr > th:nth-child(2)") != null) document.querySelector("#result-tab > thead > tr > th:nth-child(2)").remove();
+ if (document.querySelector("#result-tab > thead > tr > th:nth-child(10)") != null) document.querySelector("#result-tab > thead > tr > th:nth-child(10)").innerHTML = "开启O2";
}
- let Temp = document.querySelector("#result-tab > tbody").childNodes;
+ let Temp = (document.querySelector("#result-tab > tbody") != null) ? document.querySelector("#result-tab > tbody").childNodes : [];
let SolutionIDs = [];
for (let i = 1; i < Temp.length; i += 2) {
let SID = Number(Temp[i].childNodes[1].innerText);
@@ -3580,7 +4184,7 @@ async function main() {
Rows[i].cells[2].className = "td_result";
let SolutionID = SolutionIDs[i - 1];
if (Rows[i].cells[2].children.length == 2) {
- Points[SolutionID] = Rows[i].cells[2].children[1].innerText;
+ Points[SolutionID] = Rows[i].cells[2].children[1].textContent.trim();
Rows[i].cells[2].children[1].remove();
}
Rows[i].cells[2].innerHTML += UtilityEnabled("MonochromeUI") ? "
" : "
";
@@ -3654,269 +4258,17 @@ async function main() {
};
}
}
- } else if (location.pathname == "/contest.php") {
- if (UtilityEnabled("AutoCountdown")) {
- clock = () => {
- }
- }
- if (location.href.indexOf("?cid=") == -1) {
- if (UtilityEnabled("ResetType")) {
- document.querySelector("body > div > div.mt-3 > center").innerHTML = String(document.querySelector("body > div > div.mt-3 > center").innerHTML).replaceAll("ServerTime:", "服务器时间:");
- document.querySelector("body > div > div.mt-3 > center > table").style.marginTop = "10px";
-
- document.querySelector("body > div > div.mt-3 > center > form").outerHTML = `
`;
- }
- if (UtilityEnabled("Translate")) {
- document.querySelector("body > div > div.mt-3 > center > table > thead > tr").childNodes[0].innerText = "编号";
- document.querySelector("body > div > div.mt-3 > center > table > thead > tr").childNodes[1].innerText = "标题";
- document.querySelector("body > div > div.mt-3 > center > table > thead > tr").childNodes[2].innerText = "状态";
- document.querySelector("body > div > div.mt-3 > center > table > thead > tr").childNodes[3].remove();
- document.querySelector("body > div > div.mt-3 > center > table > thead > tr").childNodes[3].innerText = "创建者";
- }
- let Temp = document.querySelector("body > div > div.mt-3 > center > table > tbody").childNodes;
- for (let i = 1; i < Temp.length; i++) {
- let CurrentElement = Temp[i].childNodes[2].childNodes;
- if (CurrentElement[1].childNodes[0].data.indexOf("运行中") != -1) {
- let Time = String(CurrentElement[1].childNodes[1].innerText).substring(4);
- let Day = parseInt(Time.substring(0, Time.indexOf("天"))) || 0;
- let Hour = parseInt(Time.substring((Time.indexOf("天") == -1 ? 0 : Time.indexOf("天") + 1), Time.indexOf("小时"))) || 0;
- let Minute = parseInt(Time.substring((Time.indexOf("小时") == -1 ? 0 : Time.indexOf("小时") + 2), Time.indexOf("分"))) || 0;
- let Second = parseInt(Time.substring((Time.indexOf("分") == -1 ? 0 : Time.indexOf("分") + 1), Time.indexOf("秒"))) || 0;
- let TimeStamp = new Date().getTime() + diff + ((((isNaN(Day) ? 0 : Day) * 24 + Hour) * 60 + Minute) * 60 + Second) * 1000;
- CurrentElement[1].childNodes[1].setAttribute("EndTime", TimeStamp);
- CurrentElement[1].childNodes[1].classList.add("UpdateByJS");
- } else if (CurrentElement[1].childNodes[0].data.indexOf("开始于") != -1) {
- let TimeStamp = Date.parse(String(CurrentElement[1].childNodes[0].data).substring(4)) + diff;
- CurrentElement[1].setAttribute("EndTime", TimeStamp);
- CurrentElement[1].classList.add("UpdateByJS");
- } else if (CurrentElement[1].childNodes[0].data.indexOf("已结束") != -1) {
- let TimeStamp = String(CurrentElement[1].childNodes[0].data).substring(4);
- CurrentElement[1].childNodes[0].data = " 已结束 ";
- CurrentElement[1].className = "red";
- let Temp = document.createElement("span");
- CurrentElement[1].appendChild(Temp);
- Temp.className = "green";
- Temp.innerHTML = TimeStamp;
- }
- Temp[i].childNodes[3].style.display = "none";
- Temp[i].childNodes[4].innerHTML = "
" + Temp[i].childNodes[4].innerHTML + " ";
- localStorage.setItem("UserScript-Contest-" + Temp[i].childNodes[0].innerText + "-Name", Temp[i].childNodes[1].innerText);
- }
- } else {
- document.getElementsByTagName("h3")[0].innerHTML = "比赛" + document.getElementsByTagName("h3")[0].innerHTML.substring(7);
- if (document.querySelector("#time_left") != null) {
- let EndTime = document.querySelector("body > div > div.mt-3 > center").childNodes[3].data;
- EndTime = EndTime.substring(EndTime.indexOf("结束时间是:") + 6, EndTime.lastIndexOf("。"));
- EndTime = new Date(EndTime).getTime();
- if (new Date().getTime() < EndTime) {
- document.querySelector("#time_left").classList.add("UpdateByJS");
- document.querySelector("#time_left").setAttribute("EndTime", EndTime);
- }
- }
- let HTMLData = document.querySelector("body > div > div.mt-3 > center > div").innerHTML;
- HTMLData = HTMLData.replaceAll(" \n ", " ")
- HTMLData = HTMLData.replaceAll("
开始于: ", "开始时间:")
- HTMLData = HTMLData.replaceAll("\n结束于: ", "
结束时间:")
- HTMLData = HTMLData.replaceAll("\n订正截止日期: ", "
订正截止日期:")
- HTMLData = HTMLData.replaceAll("\n现在时间: ", "当前时间:")
- HTMLData = HTMLData.replaceAll("\n状态:", "
状态:")
- document.querySelector("body > div > div.mt-3 > center > div").innerHTML = HTMLData;
- if (UtilityEnabled("RemoveAlerts") && document.querySelector("body > div > div.mt-3 > center").innerHTML.indexOf("尚未开始比赛") != -1) {
- document.querySelector("body > div > div.mt-3 > center > a").setAttribute("href", "start_contest.php?cid=" + SearchParams.get("cid"));
- } else if (UtilityEnabled("AutoRefresh")) {
- addEventListener("focus", async () => {
- await fetch(location.href)
- .then((Response) => {
- return Response.text();
- })
- .then((Response) => {
- let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
- let Temp = ParsedDocument.querySelector("#problemset > tbody").children;
- if (UtilityEnabled("ReplaceYN")) {
- for (let i = 0; i < Temp.length; i++) {
- let Status = Temp[i].children[0].innerText;
- if (Status.indexOf("Y") != -1) {
- document.querySelector("#problemset > tbody").children[i].children[0].children[0].className = "status status_y";
- document.querySelector("#problemset > tbody").children[i].children[0].children[0].innerText = "✓";
- } else if (Status.indexOf("N") != -1) {
- document.querySelector("#problemset > tbody").children[i].children[0].children[0].className = "status status_n";
- document.querySelector("#problemset > tbody").children[i].children[0].children[0].innerText = "✗";
- }
- }
- }
- });
- });
- document.querySelector("body > div > div.mt-3 > center > br:nth-child(2)").remove();
- document.querySelector("body > div > div.mt-3 > center > br:nth-child(2)").remove();
- document.querySelector("body > div > div.mt-3 > center > div > .red").innerHTML = String(document.querySelector("body > div > div.mt-3 > center > div > .red").innerHTML).replaceAll("
", "
");
-
- document.querySelector("#problemset > tbody").innerHTML = String(document.querySelector("#problemset > tbody").innerHTML).replaceAll(/\t ([0-9]*) 问题 ([^<]*)/g, "$2. $1");
-
- document.querySelector("#problemset > tbody").innerHTML = String(document.querySelector("#problemset > tbody").innerHTML).replaceAll(/\t\*([0-9]*) 问题 ([^<]*)/g, "拓展$2. $1");
-
- if (UtilityEnabled("MoreSTD") && document.querySelector("#problemset > thead > tr").innerHTML.indexOf("标程") != -1) {
- let Temp = document.querySelector("#problemset > thead > tr").children;
- for (let i = 0; i < Temp.length; i++) {
- if (Temp[i].innerText == "标程") {
- Temp[i].remove();
- let Temp2 = document.querySelector("#problemset > tbody").children;
- for (let j = 0; j < Temp2.length; j++) {
- if (Temp2[j].children[i] != undefined) {
- Temp2[j].children[i].remove();
- }
- }
- }
- }
- document.querySelector("#problemset > thead > tr").innerHTML += "
标程 ";
- Temp = document.querySelector("#problemset > tbody").children;
- for (let i = 0; i < Temp.length; i++) {
- Temp[i].innerHTML += "
打开 ";
- }
- }
-
- Temp = document.querySelector("#problemset > tbody").rows;
- for (let i = 0; i < Temp.length; i++) {
- if (Temp[i].childNodes[0].children.length == 0) {
- Temp[i].childNodes[0].innerHTML = "
";
- }
- let PID = Temp[i].childNodes[1].innerHTML;
- if (PID.substring(0, 2) == "拓展") {
- PID = PID.substring(2);
- }
- Temp[i].children[2].children[0].target = "_blank";
- localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + i + "-PID", PID.substring(3));
- localStorage.setItem("UserScript-Problem-" + PID.substring(3) + "-Name", Temp[i].childNodes[2].innerText);
- }
- let CheatDiv = document.createElement("div");
- CheatDiv.style.marginTop = "20px";
- CheatDiv.style.textAlign = "left";
- document.querySelector("body > div > div.mt-3 > center").insertBefore(CheatDiv, document.querySelector("#problemset"));
- if (UtilityEnabled("AutoCheat")) {
- let AutoCheatButton = document.createElement("button");
- CheatDiv.appendChild(AutoCheatButton);
- AutoCheatButton.className = "btn btn-outline-secondary";
- AutoCheatButton.innerText = "自动提交当年代码";
- AutoCheatButton.style.marginRight = "5px";
- AutoCheatButton.disabled = true;
- let ACProblems = [], ContestProblems = [];
- const UrlParams = new URLSearchParams(window.location.search);
- const CID = UrlParams.get("cid");
- await fetch("https://www.xmoj.tech/userinfo.php?user=" + CurrentUsername)
- .then((Response) => {
- return Response.text();
- }).then((Response) => {
- let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
- let Temp = ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script").innerText.split("\n")[5].split(";");
- for (let i = 0; i < Temp.length; i++) {
- ACProblems.push(Number(Temp[i].substring(2, Temp[i].indexOf(","))));
- }
- AutoCheatButton.disabled = false;
- });
- let Rows = document.querySelector("#problemset > tbody").rows;
- for (let i = 0; i < Rows.length; i++) {
- ContestProblems.push(Rows[i].children[1].innerText.substring(Rows[i].children[1].innerText.indexOf('.') + 2)).toFixed;
- }
- AutoCheatButton.addEventListener("click", async () => {
- AutoCheatButton.disabled = true;
- let Submitted = false;
- for (let i = 0; i < ContestProblems.length; i++) {
- let PID = ContestProblems[i];
- if (ACProblems.indexOf(Number(PID)) == -1) {
- console.log("Ignoring problem " + PID + " as it has not been solved yet.");
- continue;
- }
- if (Rows[i].children[0].children[0].classList.contains("status_y")) {
- console.log("Ignoring problem " + PID + " as it has already been solved in this contest.");
- continue;
- }
- console.log("Submitting problem " + PID);
- Submitted = true;
- AutoCheatButton.innerHTML = "正在提交 " + PID;
- let SID = 0;
- await fetch("https://www.xmoj.tech/status.php?problem_id=" + PID + "&jresult=4")
- .then((Result) => {
- return Result.text();
- }).then((Result) => {
- let ParsedDocument = new DOMParser().parseFromString(Result, "text/html");
- SID = ParsedDocument.querySelector("#result-tab > tbody > tr:nth-child(1) > td:nth-child(2)").innerText;
- });
- await new Promise(r => setTimeout(r, 500));
- let Code = "";
- await fetch("https://www.xmoj.tech/getsource.php?id=" + SID)
- .then((Response) => {
- return Response.text();
- }).then((Response) => {
- Code = Response.substring(0, Response.indexOf("/**************************************************************")).trim();
- });
- await new Promise(r => setTimeout(r, 500));
- await fetch("https://www.xmoj.tech/submit.php", {
- "headers": {
- "content-type": "application/x-www-form-urlencoded"
- },
- "referrer": "https://www.xmoj.tech/submitpage.php?id=" + PID,
- "method": "POST",
- "body": "cid=" + CID + "&pid=" + i + "&" + "language=1&" + "source=" + encodeURIComponent(Code) + "&" + "enable_O2=on"
- });
- await new Promise(r => setTimeout(r, 500));
- }
- if (!Submitted) {
- AutoCheatButton.innerHTML = "没有可以提交的题目!";
- await new Promise(r => setTimeout(r, 1000));
- }
- AutoCheatButton.disabled = false;
- if (Submitted) location.reload(); else AutoCheatButton.innerHTML = "自动提交当年代码";
- });
- document.addEventListener("keydown", (Event) => {
- if (Event.code === 'Enter' && (Event.metaKey || Event.ctrlKey)) {
- AutoCheatButton.click();
- }
- });
- }
- if (UtilityEnabled("OpenAllProblem")) {
- let OpenAllButton = document.createElement("button");
- OpenAllButton.className = "btn btn-outline-secondary";
- OpenAllButton.innerText = "打开全部题目";
- OpenAllButton.style.marginRight = "5px";
- CheatDiv.appendChild(OpenAllButton);
- OpenAllButton.addEventListener("click", () => {
- let Rows = document.querySelector("#problemset > tbody").rows;
- for (let i = 0; i < Rows.length; i++) {
- open(Rows[i].children[2].children[0].href, "_blank");
- }
- });
- let OpenUnsolvedButton = document.createElement("button");
- OpenUnsolvedButton.className = "btn btn-outline-secondary";
- OpenUnsolvedButton.innerText = "打开未解决题目";
- CheatDiv.appendChild(OpenUnsolvedButton);
- OpenUnsolvedButton.addEventListener("click", () => {
- let Rows = document.querySelector("#problemset > tbody").rows;
- for (let i = 0; i < Rows.length; i++) {
- if (!Rows[i].children[0].children[0].classList.contains("status_y")) {
- open(Rows[i].children[2].children[0].href, "_blank");
- }
- }
- });
- }
- localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemCount", document.querySelector("#problemset > tbody").rows.length);
- }
- }
+ } else if (location.pathname == "/contestrank-oi.php" && document.querySelector("#rank") == null && document.querySelector("body > div > div.mt-3") == null) {
+ //页面结构异常(如403/404页面),跳过处理
} else if (location.pathname == "/contestrank-oi.php") {
if (document.querySelector("#rank") == null) {
- document.querySelector("body > div > div.mt-3").innerHTML = "
比赛排名 ";
+ if (document.querySelector("body > div > div.mt-3") != null) document.querySelector("body > div > div.mt-3").innerHTML = "比赛排名 ";
}
if (SearchParams.get("ByUserScript") == null) {
- if (document.querySelector("body > div > div.mt-3 > center > h3").innerText == "比赛排名") {
- document.querySelector("#rank").innerText = "比赛暂时还没有排名";
+ if (document.querySelector("body > div > div.mt-3 > center > h3") != null && document.querySelector("body > div > div.mt-3 > center > h3").innerText == "比赛排名") {
+ if (document.querySelector("#rank") != null) document.querySelector("#rank").innerText = "比赛暂时还没有排名";
} else {
- document.querySelector("body > div > div.mt-3 > center > h3").innerText = document.querySelector("body > div > div.mt-3 > center > h3").innerText.substring(document.querySelector("body > div > div.mt-3 > center > h3").innerText.indexOf(" -- ") + 4) + "(OI排名)";
+ if (document.querySelector("body > div > div.mt-3 > center > h3") != null) document.querySelector("body > div > div.mt-3 > center > h3").innerText = document.querySelector("body > div > div.mt-3 > center > h3").innerText.substring(document.querySelector("body > div > div.mt-3 > center > h3").innerText.indexOf(" -- ") + 4) + "(OI排名)";
let HeaderCells = document.querySelectorAll("#rank > thead > tr > *");
HeaderCells[0].innerText = "排名";
HeaderCells[1].innerText = "用户";
@@ -3997,11 +4349,11 @@ async function main() {
Temp[i].cells[j].style.color = (UtilityEnabled("DarkMode") ? "white" : "black");
}
}
- document.querySelector("#rank > tbody").innerHTML = ParsedDocument.querySelector("#rank > tbody").innerHTML;
+ if (document.querySelector("#rank > tbody") != null && ParsedDocument.querySelector("#rank > tbody") != null) document.querySelector("#rank > tbody").innerHTML = ParsedDocument.querySelector("#rank > tbody").innerHTML;
});
};
RefreshOIRank();
- document.title = document.querySelector("body > div.container > div > center > h3").innerText;
+ if (document.querySelector("body > div.container > div > center > h3") != null) document.title = document.querySelector("body > div.container > div > center > h3").innerText;
if (UtilityEnabled("AutoRefresh")) {
addEventListener("focus", RefreshOIRank);
}
@@ -4010,109 +4362,11 @@ async function main() {
Style.innerHTML += "td {";
Style.innerHTML += " white-space: nowrap;";
Style.innerHTML += "}";
- document.querySelector("body > div.container > div > center").style.paddingBottom = "10px";
- document.querySelector("body > div.container > div > center > a").style.display = "none";
- document.title = document.querySelector("body > div.container > div > center > h3").innerText;
- } else if (location.pathname == "/contestrank-correct.php") {
- if (document.querySelector("#rank") == null) {
- document.querySelector("body > div > div.mt-3").innerHTML = "比赛排名 ";
- }
- if (document.querySelector("body > div > div.mt-3 > center > h3").innerText == "比赛排名") {
- document.querySelector("#rank").innerText = "比赛暂时还没有排名";
- } else {
- if (UtilityEnabled("ResetType")) {
- document.querySelector("body > div > div.mt-3 > center > h3").innerText = document.querySelector("body > div > div.mt-3 > center > h3").innerText.substring(document.querySelector("body > div > div.mt-3 > center > h3").innerText.indexOf(" -- ") + 4) + "(订正排名)";
- document.querySelector("body > div > div.mt-3 > center > a").remove();
- }
- let HeaderCells = document.querySelectorAll("#rank > thead > tr > *");
- HeaderCells[0].innerText = "排名";
- HeaderCells[1].innerText = "用户";
- HeaderCells[2].innerText = "昵称";
- HeaderCells[3].innerText = "AC数";
- HeaderCells[4].innerText = "得分";
- if (UtilityEnabled("MonochromeUI")) {
- for (let j = 0; j < HeaderCells.length; j++) {
- HeaderCells[j].removeAttribute("bgcolor");
- HeaderCells[j].style.setProperty("background-color", "black", "important");
- HeaderCells[j].style.setProperty("color", "white", "important");
- let Links = HeaderCells[j].querySelectorAll("a");
- for (let k = 0; k < Links.length; k++) {
- Links[k].style.setProperty("color", "white", "important");
- }
- }
- }
- let RefreshCorrectRank = async () => {
- await fetch(location.href)
- .then((Response) => {
- return Response.text()
- })
- .then(async (Response) => {
- let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
- TidyTable(ParsedDocument.getElementById("rank"));
- let Temp = ParsedDocument.getElementById("rank").rows;
- for (var i = 1; i < Temp.length; i++) {
- if (UtilityEnabled("MonochromeUI")) {
- Temp[i].style.backgroundColor = "";
- }
- let MetalCell = Temp[i].cells[0];
- let Metal = document.createElement("span");
- Metal.innerText = MetalCell.innerText;
- Metal.className = "badge text-bg-primary";
- MetalCell.innerText = "";
- MetalCell.appendChild(Metal);
- GetUsernameHTML(Temp[i].cells[1], Temp[i].cells[1].innerText);
- Temp[i].cells[2].innerHTML = Temp[i].cells[2].innerText;
- Temp[i].cells[3].innerHTML = Temp[i].cells[3].innerText;
- if (UtilityEnabled("MonochromeUI")) {
- for (let j = 0; j < 5 && j < Temp[i].cells.length; j++) {
- Temp[i].cells[j].style.backgroundColor = "";
- Temp[i].cells[j].style.color = "";
- }
- }
- for (let j = 5; j < Temp[i].cells.length; j++) {
- let InnerText = Temp[i].cells[j].innerText;
- let BackgroundColor = Temp[i].cells[j].style.backgroundColor;
- let Red = BackgroundColor.substring(4, BackgroundColor.indexOf(","));
- let Green = BackgroundColor.substring(BackgroundColor.indexOf(",") + 2, BackgroundColor.lastIndexOf(","));
- let Blue = BackgroundColor.substring(BackgroundColor.lastIndexOf(",") + 2, BackgroundColor.lastIndexOf(")"));
- let NoData = (Red == 238 && Green == 238 && Blue == 238);
- let FirstBlood = (Red == 170 && Green == 170 && Blue == 255);
- let Solved = (Green == 255);
- let ErrorCount = "";
- if (Solved) {
- ErrorCount = (Blue == 170 ? "4+" : (Blue - 51) / 32);
- } else {
- ErrorCount = (Blue == 22 ? "14+" : (170 - Blue) / 10);
- }
- if (NoData) {
- BackgroundColor = "";
- } else if (FirstBlood) {
- BackgroundColor = "rgba(127, 127, 255, 0.5)";
- } else if (Solved) {
- BackgroundColor = "rgba(0, 255, 0, 0.5)";
- if (ErrorCount != 0) {
- InnerText += " (" + ErrorCount + ")";
- }
- } else {
- BackgroundColor = "rgba(255, 0, 0, 0.5)";
- if (ErrorCount != 0) {
- InnerText += " (" + ErrorCount + ")";
- }
- }
- Temp[i].cells[j].innerHTML = InnerText;
- Temp[i].cells[j].style.backgroundColor = BackgroundColor;
- Temp[i].cells[j].style.color = (UtilityEnabled("DarkMode") ? "white" : "black");
- }
- }
- document.querySelector("#rank > tbody").innerHTML = ParsedDocument.querySelector("#rank > tbody").innerHTML;
- });
- };
- RefreshCorrectRank();
- document.title = document.querySelector("body > div.container > div > center > h3").innerText;
- if (UtilityEnabled("AutoRefresh")) {
- addEventListener("focus", RefreshCorrectRank);
- }
- }
+ if (document.querySelector("body > div.container > div > center") != null) document.querySelector("body > div.container > div > center").style.paddingBottom = "10px";
+ if (document.querySelector("body > div.container > div > center > a") != null) document.querySelector("body > div.container > div > center > a").style.display = "none";
+ if (document.querySelector("body > div.container > div > center > h3") != null) document.title = document.querySelector("body > div.container > div > center > h3").innerText;
+ } else if (location.pathname == "/submitpage.php" && document.querySelector("body > div > div.mt-3") == null) {
+ //页面结构异常(如403/404页面),跳过处理
} else if (location.pathname == "/submitpage.php") {
document.title = "提交代码: " + (SearchParams.get("id") != null ? "题目" + Number(SearchParams.get("id")) : "比赛" + Number(SearchParams.get("cid")));
// submitpage.php only renders the vcode field while the judge queue is busy, and the
@@ -4122,7 +4376,7 @@ async function main() {
const NativeCaptchaShown = document.querySelector("input[name='vcode']") != null ||
document.querySelector("img#vcode") != null ||
localStorage.getItem("UserScript-ForceCaptcha") === "true";
- document.querySelector("body > div > div.mt-3").innerHTML = `
+ if (document.querySelector("body > div > div.mt-3") != null) document.querySelector("body > div > div.mt-3").innerHTML = `
@@ -4167,7 +4421,7 @@ async function main() {
}
})();
if (UtilityEnabled("AutoO2")) {
- document.querySelector("#enable_O2").checked = true;
+ if (document.querySelector("#enable_O2") != null) document.querySelector("#enable_O2").checked = true;
}
const getSubmitStorageKey = () => (SearchParams.get("id") != null ? ('XMOJ-Submit-id-' + SearchParams.get("id")) : ('XMOJ-Submit-cid-' + SearchParams.get("cid") + '-pid-' + SearchParams.get("pid")));
let CodeMirrorElement;
@@ -4261,7 +4515,7 @@ async function main() {
let CaptchaObjectURL = null;
let CaptchaRequestID = 0;
const SetCaptchaStatus = (Message) => {
- document.querySelector("#CaptchaStatus").innerText = Message;
+ if (document.querySelector("#CaptchaStatus") != null) document.querySelector("#CaptchaStatus").innerText = Message;
};
// Byte 6-7 of a GIF header is the little endian width. vcode.php sizes the image as
// 15px per character, so 60px means the easy 4 digit challenge while a wider image is
@@ -4394,7 +4648,8 @@ async function main() {
const RefreshCaptcha = async (StatusMessage) => {
const RequestID = ++CaptchaRequestID;
const CaptchaInput = document.querySelector("#vcode");
- document.querySelector("#CaptchaElement").style.display = "block";
+ if (CaptchaInput == null) return;
+ if (document.querySelector("#CaptchaElement") != null) document.querySelector("#CaptchaElement").style.display = "block";
CaptchaInput.value = "";
SetCaptchaStatus(StatusMessage || "");
// Only a submitted answer counts against the session, so fetching another image is
@@ -4427,7 +4682,7 @@ async function main() {
if (RequestID !== CaptchaRequestID) return;
if (CaptchaObjectURL !== null) URL.revokeObjectURL(CaptchaObjectURL);
CaptchaObjectURL = URL.createObjectURL(ImageBlob);
- document.querySelector("#CaptchaImage").src = CaptchaObjectURL;
+ if (document.querySelector("#CaptchaImage") != null) document.querySelector("#CaptchaImage").src = CaptchaObjectURL;
CaptchaInput.value = "";
CaptchaInput.readOnly = false;
if (!UtilityEnabled("AutoCaptcha")) return;
@@ -4453,10 +4708,10 @@ async function main() {
}
SetCaptchaStatus("连续几张都看不太准,请手动输入,或点击图片换一张");
};
- document.querySelector("#CaptchaImage").addEventListener("click", () => {
+ if (document.querySelector("#CaptchaImage") != null) document.querySelector("#CaptchaImage").addEventListener("click", () => {
RefreshCaptcha("");
});
- document.querySelector("#vcode").addEventListener("keydown", (KeyEvent) => {
+ if (document.querySelector("#vcode") != null) document.querySelector("#vcode").addEventListener("keydown", (KeyEvent) => {
if (KeyEvent.key === "Enter") {
KeyEvent.preventDefault();
Submit.click();
@@ -4466,7 +4721,7 @@ async function main() {
// one costs nothing and covers the case where the queue grew past the enforcement
// threshold after this page was rendered.
const GetCaptchaParameter = () => {
- const CaptchaValue = document.querySelector("#vcode").value.trim();
+ const CaptchaValue = (document.querySelector("#vcode") != null) ? document.querySelector("#vcode").value.trim() : "";
return CaptchaValue === "" ? "" : "&vcode=" + encodeURIComponent(CaptchaValue);
};
// Submitting a blank answer makes the server mark the session as having failed the
@@ -4475,8 +4730,8 @@ async function main() {
// 提交 is pressed: a warning leaves 强制提交 on screen, and the captcha can be cleared
// in between by refreshing the image or emptying the box by hand.
const CaptchaIsMissing = () => {
- if (document.querySelector("#CaptchaElement").style.display === "none") return false;
- if (document.querySelector("#vcode").value.trim() !== "") return false;
+ if (document.querySelector("#CaptchaElement") != null && document.querySelector("#CaptchaElement").style.display === "none") return false;
+ if (document.querySelector("#vcode") != null && document.querySelector("#vcode").value.trim() !== "") return false;
PassCheck.style.display = "none";
ErrorElement.style.display = "block";
ErrorMessage.style.color = "red";
@@ -4489,7 +4744,7 @@ async function main() {
ErrorMessage.innerText = "当前评测队列繁忙,请先填写上方的验证码。";
Submit.disabled = false;
Submit.value = "提交";
- document.querySelector("#vcode").focus();
+ if (document.querySelector("#vcode") != null) document.querySelector("#vcode").focus();
return true;
};
if (NativeCaptchaShown) {
@@ -4517,44 +4772,13 @@ async function main() {
async function SubmitToEndedContestProblem(Source, O2Switch, ReportStatus) {
const ContestID = new URL(location.href).searchParams.get("cid");
const ProblemNumber = new URL(location.href).searchParams.get("pid");
- // A rejected fetch here would unwind all the way out of the click handler, which
- // has no catch, leaving 提交 stuck on 正在提交... with the error box still hidden.
- let ContestResponse = undefined;
- let ContestPage = "";
- try {
- ContestResponse = await fetch("https://www.xmoj.tech/contest.php?cid=" + ContestID);
- ContestPage = await ContestResponse.text();
- } catch (e) {
- console.error(e);
- return {Success: false, Message: "无法读取比赛页面,未能找到原题题号!"};
- }
- if (ContestResponse.status !== 200 || ContestPage.indexOf("比赛尚未开始或私有,不能查看题目。") !== -1) {
- console.error("Failed to get contest page!");
- return {Success: false, Message: "无法读取比赛页面,未能找到原题题号!"};
- }
- let RealPID = undefined;
+ let RealPID;
try {
- const ContestDocument = new DOMParser().parseFromString(ContestPage, "text/html");
- const ProblemTable = ContestDocument.querySelector("#problemset > tbody");
- if (ProblemTable === null) {
- console.error("Failed to find the problem list of the contest!");
- return {Success: false, Message: "无法解析比赛题目列表,未能找到原题题号!"};
- }
- const ContestProblems = [];
- for (let i = 0; i < ProblemTable.rows.length; i++) {
- // The 题号 cell is padded with newlines and tabs; a fixed substring(2, 6)
- // truncates any problem number that is not exactly four digits.
- const ProblemNumberMatch = ProblemTable.rows[i].children[1].textContent.match(/\d+/);
- ContestProblems.push(ProblemNumberMatch === null ? "" : ProblemNumberMatch[0]);
- }
- RealPID = ContestProblems[ProblemNumber];
- if (UtilityEnabled("DebugMode")) {
- console.log("Contest Problems:", ContestProblems);
- console.log("Real PID:", RealPID);
- }
+ const problem = await GetContestProblemData(ContestID, ProblemNumber);
+ RealPID = String(problem.problemId);
} catch (e) {
console.error(e);
- return {Success: false, Message: "无法解析比赛题目列表,未能找到原题题号!"};
+ return {Success: false, Message: "无法读取比赛题目,未能找到原题题号!"};
}
if (RealPID === undefined || RealPID === "") {
return {Success: false, Message: "无法确定原题题号,请手动前往原题提交!"};
@@ -4562,7 +4786,7 @@ async function main() {
// XMOJ rejects anything submitted within a few seconds of the previous submission
// with 请勿重复提交, so wait the cooldown out instead of silently dropping the code.
for (let Attempt = 0; Attempt < 5; Attempt++) {
- // The captcha field stays editable while we fetch contest.php and while we wait
+ // The captcha field stays editable while we fetch the contest API and while we wait
// out a cooldown, so re-check it before every POST rather than trusting the
// check the 提交 handler did. Sending a blank answer would burn the session.
// CaptchaIsMissing() already shows its own message and restores the button.
@@ -4593,7 +4817,7 @@ async function main() {
// Retrying cannot help here: the answer that was sent has already been spent.
if (SubmitPage.indexOf("验证码错误") !== -1) {
await RefreshCaptcha("");
- document.querySelector("#vcode").focus();
+ if (document.querySelector("#vcode") != null) document.querySelector("#vcode").focus();
return {Success: false, Message: "验证码错误!请填写上方的验证码后重新提交。"};
}
if (SubmitPage.indexOf("请勿重复提交") === -1) {
@@ -4617,10 +4841,10 @@ async function main() {
// here as well as in the 提交 handler above.
if (CaptchaIsMissing()) return;
ErrorElement.style.display = "none";
- document.querySelector("#Submit").disabled = true;
- document.querySelector("#Submit").value = "正在提交...";
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").disabled = true;
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").value = "正在提交...";
let o2Switch = "&enable_O2=on";
- if (!document.querySelector("#enable_O2").checked) o2Switch = "";
+ if (document.querySelector("#enable_O2") != null && !document.querySelector("#enable_O2").checked) o2Switch = "";
await fetch("https://www.xmoj.tech/submit.php", {
"headers": {
"content-type": "application/x-www-form-urlencoded"
@@ -4651,7 +4875,7 @@ async function main() {
ErrorMessage.innerText = "验证码错误!请填写上方的验证码后重新提交。";
Submit.disabled = false;
Submit.value = "提交";
- document.querySelector("#vcode").focus();
+ if (document.querySelector("#vcode") != null) document.querySelector("#vcode").focus();
return;
}
if (UtilityEnabled("DebugMode")) {
@@ -4675,8 +4899,8 @@ async function main() {
Submit.addEventListener("click", async () => {
PassCheck.style.display = "none";
ErrorElement.style.display = "none";
- document.querySelector("#Submit").disabled = true;
- document.querySelector("#Submit").value = "正在检查...";
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").disabled = true;
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").value = "正在检查...";
if (CaptchaIsMissing()) return;
let Source = CodeMirrorElement.getValue();
let PID = 0;
@@ -4754,8 +4978,8 @@ async function main() {
pre.textContent = 'freopen("' + IOFilename + '.in", "r", stdin);\nfreopen("' + IOFilename + '.out", "w", stdout);';
codeHost.appendChild(pre);
}
- document.querySelector("#Submit").disabled = false;
- document.querySelector("#Submit").value = "提交";
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").disabled = false;
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").value = "提交";
return false;
} else if (RegExp("//.*freopen").test(Source)) {
PassCheck.style.display = "";
@@ -4768,8 +4992,8 @@ async function main() {
}
}
ErrorMessage.innerText = "请不要注释freopen语句";
- document.querySelector("#Submit").disabled = false;
- document.querySelector("#Submit").value = "提交";
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").disabled = false;
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").value = "提交";
return false;
}
}
@@ -4784,8 +5008,8 @@ async function main() {
}
}
ErrorMessage.innerText = "源代码为空";
- document.querySelector("#Submit").disabled = false;
- document.querySelector("#Submit").value = "提交";
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").disabled = false;
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").value = "提交";
return false;
}
if (UtilityEnabled("CompileError")) {
@@ -4812,8 +5036,8 @@ async function main() {
}
}
ErrorMessage.innerText = "编译错误:\n" + Response.stderr.trim();
- document.querySelector("#Submit").disabled = false;
- document.querySelector("#Submit").value = "提交";
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").disabled = false;
+ if (document.querySelector("#Submit") != null) document.querySelector("#Submit").value = "提交";
return false;
} else {
PassCheck.click();
@@ -4822,10 +5046,12 @@ async function main() {
PassCheck.click();
}
});
+ } else if (location.pathname == "/modifypage.php" && document.querySelector("body > div > div") == null) {
+ //页面结构异常(如403/404页面),跳过处理
} else if (location.pathname == "/modifypage.php") {
if (SearchParams.get("ByUserScript") != null) {
document.title = "XMOJ-Script 更新日志";
- document.querySelector("body > div > div.mt-3").innerHTML = "";
+ if (document.querySelector("body > div > div.mt-3") != null) document.querySelector("body > div > div.mt-3").innerHTML = "";
await fetch(ServerURL + "/Update.json", {cache: "no-cache"})
.then((Response) => {
return Response.json();
@@ -4835,7 +5061,7 @@ async function main() {
let Version = Object.keys(Response.UpdateHistory)[i];
let Data = Response.UpdateHistory[Version];
let UpdateDataCard = document.createElement("div");
- document.querySelector("body > div > div.mt-3").appendChild(UpdateDataCard);
+ if (document.querySelector("body > div > div.mt-3") != null) document.querySelector("body > div > div.mt-3").appendChild(UpdateDataCard);
UpdateDataCard.className = "card mb-3";
if (Data.Prerelease) UpdateDataCard.classList.add("text-secondary");
let UpdateDataCardBody = document.createElement("div");
@@ -4885,7 +5111,7 @@ async function main() {
let AtcoderAccount = document.getElementsByName("acc_atc")[0].value;
let USACOAccount = document.getElementsByName("acc_usaco")[0].value;
let LuoguAccount = document.getElementsByName("acc_luogu")[0].value;
- document.querySelector("body > div > div").innerHTML = `
+ if (document.querySelector("body > div > div") != null) document.querySelector("body > div > div").innerHTML = `
@@ -4988,9 +5214,17 @@ async function main() {
});
ModifyInfo.addEventListener("click", async () => {
ModifyInfo.disabled = true;
- ModifyInfo.querySelector("span").style.display = "";
+ if (ModifyInfo.querySelector("span") != null) ModifyInfo.querySelector("span").style.display = "";
ErrorElement.style.display = "none";
SuccessElement.style.display = "none";
+ //表单元素缺失时不提交,避免用空值覆盖用户信息
+ if (document.querySelector("#BadgeContent") == null || document.querySelector("#BadgeBackgroundColor") == null || document.querySelector("#BadgeColor") == null || document.querySelector("#Nickname") == null || document.querySelector("#OldPassword") == null || document.querySelector("#NewPassword") == null || document.querySelector("#NewPasswordAgain") == null || document.querySelector("#School") == null || document.querySelector("#EmailAddress") == null || document.querySelector("#CodeforcesAccount") == null || document.querySelector("#AtcoderAccount") == null || document.querySelector("#USACOAccount") == null || document.querySelector("#LuoguAccount") == null) {
+ ModifyInfo.disabled = false;
+ if (ModifyInfo.querySelector("span") != null) ModifyInfo.querySelector("span").style.display = "none";
+ ErrorElement.style.display = "block";
+ ErrorElement.innerText = "页面加载异常,请刷新后重试";
+ return;
+ }
let BadgeContent = document.querySelector("#BadgeContent").value;
let BadgeBackgroundColor = document.querySelector("#BadgeBackgroundColor").value;
let BadgeColor = document.querySelector("#BadgeColor").value;
@@ -5005,7 +5239,7 @@ async function main() {
Resolve();
} else {
ModifyInfo.disabled = false;
- ModifyInfo.querySelector("span").style.display = "none";
+ if (ModifyInfo.querySelector("span") != null) ModifyInfo.querySelector("span").style.display = "none";
ErrorElement.style.display = "block";
ErrorElement.innerText = Response.Message;
}
@@ -5030,12 +5264,12 @@ async function main() {
"body": "nick=" + encodeURIComponent(Nickname) + "&" + "opassword=" + encodeURIComponent(OldPassword) + "&" + "npassword=" + encodeURIComponent(NewPassword) + "&" + "rptpassword=" + encodeURIComponent(NewPasswordAgain) + "&" + "school=" + encodeURIComponent(School) + "&" + "email=" + encodeURIComponent(EmailAddress) + "&" + "acc_cf=" + encodeURIComponent(CodeforcesAccount) + "&" + "acc_atc=" + encodeURIComponent(AtcoderAccount) + "&" + "acc_usaco=" + encodeURIComponent(USACOAccount) + "&" + "acc_luogu=" + encodeURIComponent(LuoguAccount)
});
ModifyInfo.disabled = false;
- ModifyInfo.querySelector("span").style.display = "none";
+ if (ModifyInfo.querySelector("span") != null) ModifyInfo.querySelector("span").style.display = "none";
SuccessElement.style.display = "block";
});
if (UtilityEnabled("ExportACCode")) {
let ExportACCode = document.createElement("button");
- document.querySelector("body > div.container > div").appendChild(ExportACCode);
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").appendChild(ExportACCode);
ExportACCode.innerText = "导出AC代码";
ExportACCode.className = "btn btn-outline-secondary";
ExportACCode.addEventListener("click", () => {
@@ -5095,6 +5329,8 @@ async function main() {
});
}
}
+ } else if (location.pathname == "/userinfo.php" && document.querySelector("body > div > div") == null) {
+ //页面结构异常(如403/404页面),跳过处理
} else if (location.pathname == "/userinfo.php") {
if (SearchParams.get("ByUserScript") === null) {
if (UtilityEnabled("RemoveUseless")) {
@@ -5103,10 +5339,10 @@ async function main() {
Temp[i].remove();
}
}
- eval(document.querySelector("body > script:nth-child(5)").innerHTML);
- document.querySelector("#statics > tbody > tr:nth-child(1)").remove();
+ if (document.querySelector("body > script:nth-child(5)") != null) eval(document.querySelector("body > script:nth-child(5)").innerHTML);
+ if (document.querySelector("#statics > tbody > tr:nth-child(1)") != null) document.querySelector("#statics > tbody > tr:nth-child(1)").remove();
- let Temp = document.querySelector("#statics > tbody").children;
+ let Temp = (document.querySelector("#statics > tbody") != null) ? document.querySelector("#statics > tbody").children : [];
for (let i = 0; i < Temp.length; i++) {
if (Temp[i].children[0] != undefined) {
if (Temp[i].children[0].innerText == "Statistics") {
@@ -5118,18 +5354,18 @@ async function main() {
}
}
- Temp = document.querySelector("#statics > tbody > tr:nth-child(1) > td:nth-child(3)").childNodes;
+ Temp = (document.querySelector("#statics > tbody > tr:nth-child(1) > td:nth-child(3)") != null) ? document.querySelector("#statics > tbody > tr:nth-child(1) > td:nth-child(3)").childNodes : [];
let ACProblems = [];
for (let i = 0; i < Temp.length; i++) {
if (Temp[i].tagName == "A" && Temp[i].href.indexOf("problem.php?id=") != -1) {
ACProblems.push(Number(Temp[i].innerText.trim()));
}
}
- document.querySelector("#statics > tbody > tr:nth-child(1) > td:nth-child(3)").remove();
+ if (document.querySelector("#statics > tbody > tr:nth-child(1) > td:nth-child(3)") != null) document.querySelector("#statics > tbody > tr:nth-child(1) > td:nth-child(3)").remove();
let UserID, UserNick;
- [UserID, UserNick] = document.querySelector("#statics > caption").childNodes[0].data.trim().split("--");
- document.querySelector("#statics > caption").remove();
+ if (document.querySelector("#statics > caption") != null) [UserID, UserNick] = document.querySelector("#statics > caption").childNodes[0].data.trim().split("--");
+ if (document.querySelector("#statics > caption") != null) document.querySelector("#statics > caption").remove();
document.title = "用户 " + UserID + " 的个人中心";
let Row = document.createElement("div");
Row.className = "row";
@@ -5245,11 +5481,11 @@ async function main() {
for (let i = 0; i < ACProblems.length; i++) {
RightDiv.innerHTML += "
" + ACProblems[i] + " ";
}
- document.querySelector("body > div > div").innerHTML = "";
- document.querySelector("body > div > div").appendChild(Row);
+ if (document.querySelector("body > div > div") != null) document.querySelector("body > div > div").innerHTML = "";
+ if (document.querySelector("body > div > div") != null) document.querySelector("body > div > div").appendChild(Row);
} else {
document.title = "上传标程";
- document.querySelector("body > div > div.mt-3").innerHTML = `
上传标程
+ if (document.querySelector("body > div > div.mt-3") != null) document.querySelector("body > div > div.mt-3").innerHTML = `
上传标程
0%
@@ -5275,7 +5511,7 @@ async function main() {
return Response.text();
}).then((Response) => {
let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
- let ScriptData = ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script").innerText;
+ let ScriptData = (ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script") != null) ? ParsedDocument.querySelector("#statics > tbody > tr:nth-child(2) > td:nth-child(3) > script").innerText : "";
ScriptData = ScriptData.substr(ScriptData.indexOf("}") + 1).trim();
ScriptData = ScriptData.split(";");
for (let i = 0; i < ScriptData.length; i++) {
@@ -5317,35 +5553,37 @@ async function main() {
});
});
}
+ } else if (location.pathname == "/comparesource.php" && document.querySelector("body > div.container > div") == null) {
+ //页面结构异常(如403/404页面),跳过处理
} else if (location.pathname == "/comparesource.php") {
if (UtilityEnabled("CompareSource")) {
if (location.search == "") {
- document.querySelector("body > div.container > div").innerHTML = "";
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").innerHTML = "";
let LeftCodeText = document.createElement("span");
- document.querySelector("body > div.container > div").appendChild(LeftCodeText);
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").appendChild(LeftCodeText);
LeftCodeText.innerText = "左侧代码的运行编号:";
let LeftCode = document.createElement("input");
- document.querySelector("body > div.container > div").appendChild(LeftCode);
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").appendChild(LeftCode);
LeftCode.classList.add("form-control");
LeftCode.style.width = "40%";
LeftCode.style.marginBottom = "5px";
let RightCodeText = document.createElement("span");
- document.querySelector("body > div.container > div").appendChild(RightCodeText);
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").appendChild(RightCodeText);
RightCodeText.innerText = "右侧代码的运行编号:";
let RightCode = document.createElement("input");
- document.querySelector("body > div.container > div").appendChild(RightCode);
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").appendChild(RightCode);
RightCode.classList.add("form-control");
RightCode.style.width = "40%";
RightCode.style.marginBottom = "5px";
let CompareButton = document.createElement("button");
- document.querySelector("body > div.container > div").appendChild(CompareButton);
+ if (document.querySelector("body > div.container > div") != null) document.querySelector("body > div.container > div").appendChild(CompareButton);
CompareButton.innerText = "比较";
CompareButton.className = "btn btn-primary";
CompareButton.addEventListener("click", () => {
location.href = "https://www.xmoj.tech/comparesource.php?left=" + Number(LeftCode.value) + "&right=" + Number(RightCode.value);
});
} else {
- document.querySelector("body > div > div.mt-3").innerHTML = `
+ if (document.querySelector("body > div > div.mt-3") != null) document.querySelector("body > div > div.mt-3").innerHTML = `