`;
GetUsernameHTML(ToUser, SearchParams.get("to_user"));
let RefreshMessage = (Silent = true) => {
if (!Silent) {
MessageTable.children[1].innerHTML = "";
for (let i = 0; i < 10; i++) {
let Row = document.createElement("tr");
MessageTable.children[1].appendChild(Row);
for (let j = 0; j < 4; j++) {
let Cell = document.createElement("td");
Row.appendChild(Cell);
Cell.innerHTML = `
`;
}
}
}
RequestAPI("GetMail", {
"OtherUser": String(SearchParams.get("to_user"))
}, async (ResponseData) => {
if (ResponseData.Success) {
ErrorElement.style.display = "none";
let Data = ResponseData.Data.Mail;
MessageTable.children[1].innerHTML = "";
for (let i = 0; i < Data.length; i++) {
let Row = document.createElement("tr");
MessageTable.children[1].appendChild(Row);
if (!Data[i].IsRead && Data[i].FromUser != CurrentUsername) {
Row.className = "table-info";
}
let UsernameCell = document.createElement("td");
Row.appendChild(UsernameCell);
GetUsernameHTML(UsernameCell, Data[i].FromUser);
let ContentCell = document.createElement("td");
let ContentDiv = document.createElement("div");
ContentDiv.style.display = "flex";
ContentDiv.style.maxWidth = window.innerWidth - 300 + "px";
ContentDiv.style.maxHeight = "500px";
ContentDiv.style.overflowX = "auto";
ContentDiv.style.overflowY = "auto";
ContentDiv.innerHTML = PurifyHTML(marked.parse(Data[i].Content));
let mediaElements = ContentDiv.querySelectorAll('img, video');
for (let media of mediaElements) {
media.style.objectFit = 'contain';
media.style.maxWidth = '100%';
media.style.maxHeight = '100%';
}
ContentCell.appendChild(ContentDiv);
Row.appendChild(ContentCell);
let SendTimeCell = document.createElement("td");
Row.appendChild(SendTimeCell);
SendTimeCell.innerHTML = GetRelativeTime(Data[i].SendTime);
let IsReadCell = document.createElement("td");
Row.appendChild(IsReadCell);
IsReadCell.innerHTML = (Data[i].IsRead ? "已读" : "未读");
}
} else {
ErrorElement.innerText = ResponseData.Message;
ErrorElement.style.display = "";
}
});
};
Content.addEventListener("input", () => {
Content.classList.remove("is-invalid");
});
Content.addEventListener("keydown", (Event) => {
if (Event.keyCode == 13) {
Send.click();
}
});
Send.addEventListener("click", () => {
if (Content.value == "") {
Content.classList.add("is-invalid");
return;
}
Send.disabled = true;
Send.children[0].style.display = "";
let ContentData = Content.value;
RequestAPI("SendMail", {
"ToUser": String(SearchParams.get("to_user")), "Content": String(ContentData)
}, (ResponseData) => {
Send.disabled = false;
Send.children[0].style.display = "none";
if (ResponseData.Success) {
ErrorElement.style.display = "none";
Content.value = "";
RefreshMessage();
} else {
ErrorElement.innerText = ResponseData.Message;
ErrorElement.style.display = "";
}
});
});
RefreshMessage(false);
addEventListener("focus", RefreshMessage);
}
} else if (location.pathname.indexOf("/discuss3") != -1) {
if (UtilityEnabled("Discussion")) {
Discussion.classList.add("active");
if (location.pathname == "/discuss3/discuss.php") {
let ProblemID = parseInt(SearchParams.get("pid"));
let Page = Number(SearchParams.get("page")) || 1;
document.querySelector("body > div > div").innerHTML = `
讨论列表${(isNaN(ProblemID) ? "" : ` - 题目` + ProblemID)}
编号 |
标题 |
作者 |
题目编号 |
发布时间 |
回复数 |
最后回复 |
`;
NewPost.addEventListener("click", () => {
if (!isNaN(ProblemID)) {
location.href = "https://www.xmoj.tech/discuss3/newpost.php?pid=" + ProblemID;
} else if (SearchParams.get("bid") != null) {
location.href = "https://www.xmoj.tech/discuss3/newpost.php?bid=" + SearchParams.get("bid");
} else {
location.href = "https://www.xmoj.tech/discuss3/newpost.php";
}
});
const RefreshPostList = (Silent = true) => {
if (!Silent) {
PostList.children[1].innerHTML = "";
for (let i = 0; i < 10; i++) {
let Row = document.createElement("tr");
PostList.children[1].appendChild(Row);
for (let j = 0; j < 7; j++) {
let Cell = document.createElement("td");
Row.appendChild(Cell);
Cell.innerHTML = `
`;
}
}
}
RequestAPI("GetPosts", {
"ProblemID": Number(ProblemID || 0),
"Page": Number(Page),
"BoardID": Number(SearchParams.get("bid") || -1)
}, async (ResponseData) => {
if (ResponseData.Success == true) {
ErrorElement.style.display = "none";
if (!Silent) {
DiscussPagination.children[0].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=1";
DiscussPagination.children[1].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=" + (Page - 1);
DiscussPagination.children[2].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=" + Page;
DiscussPagination.children[3].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=" + (Page + 1);
DiscussPagination.children[4].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=" + ResponseData.Data.PageCount;
if (Page <= 1) {
DiscussPagination.children[0].classList.add("disabled");
DiscussPagination.children[1].remove();
}
if (Page >= ResponseData.Data.PageCount) {
DiscussPagination.children[DiscussPagination.children.length - 1].classList.add("disabled");
DiscussPagination.children[DiscussPagination.children.length - 2].remove();
}
}
let Posts = ResponseData.Data.Posts;
PostList.children[1].innerHTML = "";
if (Posts.length == 0) {
PostList.children[1].innerHTML = `
暂无数据 |
`;
}
for (let i = 0; i < Posts.length; i++) {
let Row = document.createElement("tr");
PostList.children[1].appendChild(Row);
let IDCell = document.createElement("td");
Row.appendChild(IDCell);
IDCell.innerText = Posts[i].PostID + " " + Posts[i].BoardName;
let TitleCell = document.createElement("td");
Row.appendChild(TitleCell);
let TitleLink = document.createElement("a");
TitleCell.appendChild(TitleLink);
TitleLink.href = "https://www.xmoj.tech/discuss3/thread.php?tid=" + Posts[i].PostID;
if (Posts[i].Lock.Locked) {
TitleLink.classList.add("link-secondary");
TitleLink.innerHTML = "🔒 ";
}
TitleLink.innerHTML += Posts[i].Title;
let AuthorCell = document.createElement("td");
Row.appendChild(AuthorCell);
GetUsernameHTML(AuthorCell, Posts[i].UserID);
let ProblemIDCell = document.createElement("td");
Row.appendChild(ProblemIDCell);
if (Posts[i].ProblemID != 0) {
let ProblemIDLink = document.createElement("a");
ProblemIDCell.appendChild(ProblemIDLink);
ProblemIDLink.href = "https://www.xmoj.tech/problem.php?id=" + Posts[i].ProblemID;
ProblemIDLink.innerText = Posts[i].ProblemID;
}
let PostTimeCell = document.createElement("td");
Row.appendChild(PostTimeCell);
PostTimeCell.innerHTML = GetRelativeTime(Posts[i].PostTime);
let ReplyCountCell = document.createElement("td");
Row.appendChild(ReplyCountCell);
ReplyCountCell.innerText = Posts[i].ReplyCount;
let LastReplyTimeCell = document.createElement("td");
Row.appendChild(LastReplyTimeCell);
LastReplyTimeCell.innerHTML = GetRelativeTime(Posts[i].LastReplyTime);
}
} else {
ErrorElement.innerText = ResponseData.Message;
ErrorElement.style.display = "block";
}
});
};
RefreshPostList(false);
addEventListener("focus", RefreshPostList);
RequestAPI("GetBoards", {}, (ResponseData) => {
if (ResponseData.Success === true) {
let LinkElement = document.createElement("a");
LinkElement.href = "https://www.xmoj.tech/discuss3/discuss.php";
LinkElement.classList.add("me-2");
LinkElement.innerText = "全部";
GotoBoard.appendChild(LinkElement);
for (let i = 0; i < ResponseData.Data.Boards.length; i++) {
let LinkElement = document.createElement("a");
LinkElement.href = "https://www.xmoj.tech/discuss3/discuss.php?bid=" + ResponseData.Data.Boards[i].BoardID;
LinkElement.classList.add("me-2");
LinkElement.innerText = ResponseData.Data.Boards[i].BoardName;
GotoBoard.appendChild(LinkElement);
}
}
});
} else if (location.pathname == "/discuss3/newpost.php") {
let ProblemID = parseInt(SearchParams.get("pid"));
document.querySelector("body > div > div").innerHTML = `
发布新讨论` + (!isNaN(ProblemID) ? ` - 题目` + ProblemID : ``) + `