Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,17 @@
}
],
"Notes": "No release notes were provided for this release."
},
"2.0.0": {
"UpdateDate": 1754724044036,
"Prerelease": true,
"UpdateContents": [
{
"PR": 826,
"Description": "修复更新"
}
],
"Notes": "No release notes were provided for this release."
}
}
}
27 changes: 21 additions & 6 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name XMOJ
// @version 1.10.0
// @version 2.0.0
// @description XMOJ增强脚本
// @author @XMOJ-Script-dev, @langningchen and the community
// @namespace https://github/langningchen
Expand Down Expand Up @@ -39,7 +39,7 @@
*/

const CaptchaSiteKey = "0x4AAAAAAALBT58IhyDViNmv";
const AdminUserList = ["zhuchenrui2", "shanwenxiao", "admin"];
const AdminUserList = ["zhuchenrui2", "shanwenxiao", "chenlangning", "admin"];

let escapeHTML = (str) => {
return str.replace(/[&<>"']/g, function (match) {
Expand Down Expand Up @@ -107,6 +107,24 @@ let GetRelativeTime = (Input) => {
}
}
};

Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compareVersions function lacks documentation. Consider adding a JSDoc comment explaining the parameters, return value, and behavior when comparing semantic versions.

Suggested change
/**
* Compares two semantic version strings to determine if an update is needed.
*
* @param {string} currVer - The current version string (e.g., "1.2.3").
* @param {string} remoteVer - The remote version string to compare against (e.g., "1.2.4").
* @returns {boolean} Returns true if the remote version is greater than the current version (update needed), false otherwise.
*
* The function compares each segment of the version strings numerically from left to right.
* If the remote version segment is greater than the current, it returns true.
* If the current version segment is greater, it returns false.
* If all segments are equal, it returns false.
* Missing segments are treated as 0.
*/

Copilot uses AI. Check for mistakes.
function compareVersions(currVer, remoteVer) {
const currParts = currVer.split('.').map(Number);
const remoteParts = remoteVer.split('.').map(Number);

const maxLen = Math.max(currParts.length, remoteParts.length);
for (let i = 0; i < maxLen; i++) {
const curr = currParts[i] !== undefined ? currParts[i] : 0;
const remote = remoteParts[i] !== undefined ? remoteParts[i] : 0;
if (remote > curr) {
return true; // update needed
} else if (remote < curr) {
return false; // no update needed
}
}
return false; // versions are equal
}

let RenderMathJax = async () => {
try {
if (document.getElementById("MathJax-script") === null) {
Expand Down Expand Up @@ -270,9 +288,6 @@ let GetUsernameHTML = async (Element, Username, Simple = false, Href = "https://
if (AdminUserList.includes(Username)) {
HTMLData += `<span class="badge text-bg-danger ms-2">脚本管理员</span>`;
}
if (Username == "chenlangning") {
HTMLData += `<span class="badge ms-2" style="background-color: #6633cc; color: #ffffff">吉祥物</span>`;
}
let BadgeInfo = await GetUserBadge(Username);
if (BadgeInfo.Content != "") {
HTMLData += `<span class="badge ms-2" style="background-color: ${BadgeInfo.BackgroundColor}; color: ${BadgeInfo.Color}">${BadgeInfo.Content}</span>`;
Expand Down Expand Up @@ -1031,7 +1046,7 @@ async function main() {
break;
}
}
if (CurrentVersion < LatestVersion) {
if (compareVersions(CurrentVersion, LatestVersion)) {
let UpdateDiv = document.createElement("div");
UpdateDiv.innerHTML = `
<div class="alert alert-warning alert-dismissible fade show mt-2" role="alert">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmoj-script",
"version": "1.10.0",
"version": "2.0.0",
"description": "an improvement script for xmoj.tech",
"main": "AddonScript.js",
"scripts": {
Expand Down