From e43afc2c096369d9cc304f290b5c79558aac426e Mon Sep 17 00:00:00 2001 From: Chen LangNing Date: Sat, 23 Sep 2023 19:42:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[Feature=20Request]=20=E5=B0=86=20@=20?= =?UTF-8?q?=E6=94=BE=E5=9C=A8=E5=89=8D=E7=AB=AF=E6=B8=B2=E6=9F=93=20Fixes?= =?UTF-8?q?=20#436?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XMOJ.user.js | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index 91038fd1..ff46fc12 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -72,6 +72,9 @@ let GetUserInfo = async (Username) => { return await fetch("http://www.xmoj.tech/userinfo.php?user=" + Username).then((Response) => { return Response.text(); }).then((Response) => { + if (Response.indexOf("No such User!") !== -1) { + return null; + } const ParsedDocument = new DOMParser().parseFromString(Response, "text/html"); let Rating = (parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(4) > td:nth-child(2)").innerText.trim()) / parseInt(ParsedDocument.querySelector("#statics > tbody > tr:nth-child(3) > td:nth-child(2)").innerText.trim())).toFixed(3) * 1000; @@ -126,19 +129,26 @@ let GetUserBadge = async (Username) => { } } }; -let GetUsernameHTML = async (Element, Username, Href = "http://www.xmoj.tech/userinfo.php?user=") => { +let GetUsernameHTML = async (Element, Username, Simple = false, Href = "http://www.xmoj.tech/userinfo.php?user=") => { let ID = "Username-" + Username + "-" + Math.random(); Element.id = ID; Element.innerHTML = `
${Username}`; let UserInfo = await GetUserInfo(Username); - let HTMLData = ``; } - HTMLData += `" class="rounded me-2" style="width: 20px; height: 20px; ">`; HTMLData += `${Username}`; - if (AdminUserList.includes(Username)) { - HTMLData += `管理员`; - } - let BadgeInfo = await GetUserBadge(Username); - if (BadgeInfo.Content != "") { - HTMLData += `${BadgeInfo.Content}`; + if (!Simple) { + if (AdminUserList.includes(Username)) { + HTMLData += `管理员`; + } + let BadgeInfo = await GetUserBadge(Username); + if (BadgeInfo.Content != "") { + HTMLData += `${BadgeInfo.Content}`; + } } document.getElementById(ID).innerHTML = HTMLData; }; @@ -247,7 +259,6 @@ let UtilityEnabled = (Name) => { return localStorage.getItem("UserScript-Setting-" + Name) == "true"; }; let FixReply = (Data) => { - Data = Data.replaceAll(/ ?@\1<\/a> ?/g, "@$1"); Data = Data.replaceAll(/
已于 [0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}, [0-9]{1,2}:[0-9]{2}:[0-9]{2} (A|P)M 编辑<\/span>/g, ""); return Data; } @@ -3375,7 +3386,7 @@ else { let Row = document.createElement("tr"); ReceiveTable.children[1].appendChild(Row); let UsernameCell = document.createElement("td"); Row.appendChild(UsernameCell); let UsernameSpan = document.createElement("span"); UsernameCell.appendChild(UsernameSpan); - GetUsernameHTML(UsernameSpan, Data[i].OtherUser, "http://www.xmoj.tech/mail.php?other="); + GetUsernameHTML(UsernameSpan, Data[i].OtherUser, false, "http://www.xmoj.tech/mail.php?other="); if (Data[i].UnreadCount != 0) { let UnreadCountSpan = document.createElement("span"); UsernameCell.appendChild(UnreadCountSpan); UnreadCountSpan.className = "ms-1 badge text-bg-danger"; @@ -3974,7 +3985,7 @@ else { let CardBodyHRElement = document.createElement("hr"); CardBodyElement.appendChild(CardBodyHRElement); let ReplyContentElement = document.createElement("div"); CardBodyElement.appendChild(ReplyContentElement); - ReplyContentElement.innerHTML = DOMPurify.sanitize(marked.parse(Replies[i].Content)); + ReplyContentElement.innerHTML = DOMPurify.sanitize(marked.parse(Replies[i].Content.replaceAll(/@([a-zA-Z0-9]+)/g, `@$1`))); let ContentEditElement = document.createElement("div"); CardBodyElement.appendChild(ContentEditElement); ContentEditElement.classList.add("input-group"); ContentEditElement.style.display = "none"; @@ -3999,6 +4010,12 @@ else { RenderMathJax(); }); } + + let UsernameElements = document.getElementsByClassName("Usernames"); + for (let i = 0; i < UsernameElements.length; i++) { + GetUsernameHTML(UsernameElements[i], UsernameElements[i].innerText, true); + } + let CodeElements = document.querySelectorAll("#PostReplies > div > div > div:nth-child(3) > pre > code"); for (let i = 0; i < CodeElements.length; i++) { let ModeName = "text/plain"; From 3cc79305dc11f8cbd5c712a1d947ac2d01b9add9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 23 Sep 2023 11:43:56 +0000 Subject: [PATCH 2/3] Update version info to 0.3.170 --- Update.json | 10 ++++++++++ XMOJ.user.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Update.json b/Update.json index e041fe40..a5da4355 100644 --- a/Update.json +++ b/Update.json @@ -441,6 +441,16 @@ "Description": "忽略提醒后立刻不显示该提醒" } ] + }, + "0.3.170": { + "UpdateDate": 1695469435825, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 494, + "Description": "[Feature Request] 将 @ 放在前端渲染" + } + ] } } } \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index ff46fc12..eaf621df 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 0.3.169 +// @version 0.3.170 // @description XMOJ增强脚本 // @author @langningchen // @namespace https://github/langningchen From 8df18ee17bb704fb970b24125d583682b513c08f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 23 Sep 2023 11:44:05 +0000 Subject: [PATCH 3/3] Update time and description of 0.3.170 --- Update.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Update.json b/Update.json index a5da4355..4fbf1ab1 100644 --- a/Update.json +++ b/Update.json @@ -443,12 +443,12 @@ ] }, "0.3.170": { - "UpdateDate": 1695469435825, + "UpdateDate": 1695469445405, "Prerelease": true, "UpdateContents": [ { "PR": 494, - "Description": "[Feature Request] 将 @ 放在前端渲染" + "Description": "将讨论中的 @ 放在前端渲染" } ] }