Skip to content

Commit caf1ee0

Browse files
authored
Merge pull request #916 from XMOJ-Script-dev/fix/contestrank-dark-mode
Fix contest ranking table styling for dark mode
2 parents 9583131 + ba94e6f commit caf1ee0

3 files changed

Lines changed: 55 additions & 13 deletions

File tree

Update.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,6 +3385,17 @@
33853385
}
33863386
],
33873387
"Notes": "No release notes were provided for this release."
3388+
},
3389+
"3.2.1": {
3390+
"UpdateDate": 1771740586846,
3391+
"Prerelease": true,
3392+
"UpdateContents": [
3393+
{
3394+
"PR": 916,
3395+
"Description": "Fix contest ranking table styling for dark mode"
3396+
}
3397+
],
3398+
"Notes": "Fix contest ranking table colors in dark mode (contestrank-oi.php and contestrank-correct.php)"
33883399
}
33893400
}
33903401
}

XMOJ.user.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 3.2.0
3+
// @version 3.2.1
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -2994,11 +2994,21 @@ async function main() {
29942994
document.querySelector("#rank").innerText = "比赛暂时还没有排名";
29952995
} else {
29962996
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排名)";
2997-
document.querySelector("#rank > thead > tr > :nth-child(1)").innerText = "排名";
2998-
document.querySelector("#rank > thead > tr > :nth-child(2)").innerText = "用户";
2999-
document.querySelector("#rank > thead > tr > :nth-child(3)").innerText = "昵称";
3000-
document.querySelector("#rank > thead > tr > :nth-child(4)").innerText = "AC数";
3001-
document.querySelector("#rank > thead > tr > :nth-child(5)").innerText = "得分";
2997+
let HeaderCells = document.querySelectorAll("#rank > thead > tr > *");
2998+
HeaderCells[0].innerText = "排名";
2999+
HeaderCells[1].innerText = "用户";
3000+
HeaderCells[2].innerText = "昵称";
3001+
HeaderCells[3].innerText = "AC数";
3002+
HeaderCells[4].innerText = "得分";
3003+
for (let j = 0; j < HeaderCells.length; j++) {
3004+
HeaderCells[j].removeAttribute("bgcolor");
3005+
HeaderCells[j].style.setProperty("background-color", "black", "important");
3006+
HeaderCells[j].style.setProperty("color", "white", "important");
3007+
let Links = HeaderCells[j].querySelectorAll("a");
3008+
for (let k = 0; k < Links.length; k++) {
3009+
Links[k].style.setProperty("color", "white", "important");
3010+
}
3011+
}
30023012
let RefreshOIRank = async () => {
30033013
await fetch(location.href)
30043014
.then((Response) => {
@@ -3009,6 +3019,7 @@ async function main() {
30093019
TidyTable(ParsedDocument.getElementById("rank"));
30103020
let Temp = ParsedDocument.getElementById("rank").rows;
30113021
for (var i = 1; i < Temp.length; i++) {
3022+
Temp[i].style.backgroundColor = "";
30123023
let MetalCell = Temp[i].cells[0];
30133024
let Metal = document.createElement("span");
30143025
Metal.innerText = MetalCell.innerText;
@@ -3018,6 +3029,10 @@ async function main() {
30183029
GetUsernameHTML(Temp[i].cells[1], Temp[i].cells[1].innerText);
30193030
Temp[i].cells[2].innerHTML = Temp[i].cells[2].innerText;
30203031
Temp[i].cells[3].innerHTML = Temp[i].cells[3].innerText;
3032+
for (let j = 0; j < 5 && j < Temp[i].cells.length; j++) {
3033+
Temp[i].cells[j].style.backgroundColor = "";
3034+
Temp[i].cells[j].style.color = "";
3035+
}
30213036
for (let j = 5; j < Temp[i].cells.length; j++) {
30223037
let InnerText = Temp[i].cells[j].innerText;
30233038
let BackgroundColor = Temp[i].cells[j].style.backgroundColor;
@@ -3038,7 +3053,7 @@ async function main() {
30383053
} else if (FirstBlood) {
30393054
BackgroundColor = "rgb(127, 127, 255)";
30403055
} else if (Solved) {
3041-
BackgroundColor = "rgb(0, 255, 0, " + Math.max(1 / 10 * (10 - ErrorCount), 0.2) + ")";
3056+
BackgroundColor = "rgba(0, 255, 0, " + Math.max(1 / 10 * (10 - ErrorCount), 0.2) + ")";
30423057
if (ErrorCount != 0) {
30433058
InnerText += " (" + (ErrorCount == 5 ? "4+" : ErrorCount) + ")";
30443059
}
@@ -3080,11 +3095,21 @@ async function main() {
30803095
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) + "(订正排名)";
30813096
document.querySelector("body > div > div.mt-3 > center > a").remove();
30823097
}
3083-
document.querySelector("#rank > thead > tr > :nth-child(1)").innerText = "排名";
3084-
document.querySelector("#rank > thead > tr > :nth-child(2)").innerText = "用户";
3085-
document.querySelector("#rank > thead > tr > :nth-child(3)").innerText = "昵称";
3086-
document.querySelector("#rank > thead > tr > :nth-child(4)").innerText = "AC数";
3087-
document.querySelector("#rank > thead > tr > :nth-child(5)").innerText = "得分";
3098+
let HeaderCells = document.querySelectorAll("#rank > thead > tr > *");
3099+
HeaderCells[0].innerText = "排名";
3100+
HeaderCells[1].innerText = "用户";
3101+
HeaderCells[2].innerText = "昵称";
3102+
HeaderCells[3].innerText = "AC数";
3103+
HeaderCells[4].innerText = "得分";
3104+
for (let j = 0; j < HeaderCells.length; j++) {
3105+
HeaderCells[j].removeAttribute("bgcolor");
3106+
HeaderCells[j].style.setProperty("background-color", "black", "important");
3107+
HeaderCells[j].style.setProperty("color", "white", "important");
3108+
let Links = HeaderCells[j].querySelectorAll("a");
3109+
for (let k = 0; k < Links.length; k++) {
3110+
Links[k].style.setProperty("color", "white", "important");
3111+
}
3112+
}
30883113
let RefreshCorrectRank = async () => {
30893114
await fetch(location.href)
30903115
.then((Response) => {
@@ -3095,6 +3120,7 @@ async function main() {
30953120
TidyTable(ParsedDocument.getElementById("rank"));
30963121
let Temp = ParsedDocument.getElementById("rank").rows;
30973122
for (var i = 1; i < Temp.length; i++) {
3123+
Temp[i].style.backgroundColor = "";
30983124
let MetalCell = Temp[i].cells[0];
30993125
let Metal = document.createElement("span");
31003126
Metal.innerText = MetalCell.innerText;
@@ -3104,6 +3130,10 @@ async function main() {
31043130
GetUsernameHTML(Temp[i].cells[1], Temp[i].cells[1].innerText);
31053131
Temp[i].cells[2].innerHTML = Temp[i].cells[2].innerText;
31063132
Temp[i].cells[3].innerHTML = Temp[i].cells[3].innerText;
3133+
for (let j = 0; j < 5 && j < Temp[i].cells.length; j++) {
3134+
Temp[i].cells[j].style.backgroundColor = "";
3135+
Temp[i].cells[j].style.color = "";
3136+
}
31073137
for (let j = 5; j < Temp[i].cells.length; j++) {
31083138
let InnerText = Temp[i].cells[j].innerText;
31093139
let BackgroundColor = Temp[i].cells[j].style.backgroundColor;
@@ -3136,6 +3166,7 @@ async function main() {
31363166
}
31373167
Temp[i].cells[j].innerHTML = InnerText;
31383168
Temp[i].cells[j].style.backgroundColor = BackgroundColor;
3169+
Temp[i].cells[j].style.color = (UtilityEnabled("DarkMode") ? "white" : "black");
31393170
}
31403171
}
31413172
document.querySelector("#rank > tbody").innerHTML = ParsedDocument.querySelector("#rank > tbody").innerHTML;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xmoj-script",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "an improvement script for xmoj.tech",
55
"main": "AddonScript.js",
66
"scripts": {

0 commit comments

Comments
 (0)