Skip to content
42 changes: 42 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,48 @@
}
],
"Notes": "No release notes were provided for this release."
},
"3.5.0": {
"UpdateDate": 1778930758179,
"Prerelease": false,
"UpdateContents": [
{
"PR": 961,
"Description": "feat: Cross-device settings sync via cloud backend"
},
{
"PR": 963,
"Description": "feat: Add hourly periodic cloud settings sync"
},
{
"PR": 969,
"Description": "Migrate XMOJ-BBS client endpoints to /v1 routes"
},
{
"PR": 975,
"Description": "Revert /v1 endpoint migration"
},
{
"PR": 973,
"Description": "Fix loginpage.php Loop"
},
{
"PR": 980,
"Description": "Switch all backend endpoints to api.xmoj-script.uk"
}
],
"Notes": "No release notes were provided for this release."
},
"3.5.1": {
"UpdateDate": 1780117325597,
"Prerelease": true,
"UpdateContents": [
{
"PR": 986,
"Description": "Fix Violentmonkey SyntaxError: wrap async init block in IIFE"
}
],
"Notes": "No release notes were provided for this release."
}
}
}
31 changes: 23 additions & 8 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name XMOJ
// @version 3.4.6
// @version 3.5.1
// @description XMOJ增强脚本
// @author @XMOJ-Script-dev, @langningchen and the community
// @namespace https://github/langningchen
Expand Down Expand Up @@ -43,6 +43,11 @@
const CaptchaSiteKey = "0x4AAAAAAALBT58IhyDViNmv";
const AdminUserList = ["zhuchenrui2", "shanwenxiao", "chenlangning", "admin"];

// Pre-declared so that closures defined before the async init block can reference them
let CurrentUsername;
let initTheme;
let SearchParams;

let escapeHTML = (str) => {
return str.replace(/[&<>"']/g, function (match) {
const escape = {
Expand Down Expand Up @@ -911,6 +916,9 @@ GM_registerMenuCommand("重置数据", () => {
}
});

// Wrapped in an async IIFE so that `await` is valid in Violentmonkey,
// which executes userscripts as classic scripts (not ES modules).
(async () => {
//otherwise CurrentUsername might be undefined
let loginStatus;
await fetch("https://www.xmoj.tech/loginpage.php")
Expand All @@ -920,14 +928,19 @@ const logined = loginStatus == "<a href=logout.php>Please logout First!</a>";
if (UtilityEnabled("AutoLogin") && document.querySelector("body > a:nth-child(1)") != null && document.querySelector("body > a:nth-child(1)").innerText == "请登录后继续操作") {
localStorage.setItem("UserScript-LastPage", location.pathname + location.search);
location.href = "https://www.xmoj.tech/loginpage.php";
return;
}

let SearchParams = new URLSearchParams(location.search);
SearchParams = new URLSearchParams(location.search);
let ServerURL = (UtilityEnabled("DebugMode") ? "https://ghpages.xmoj-script.uk/" : "https://www.xmoj-script.uk")
if (document.querySelector("#profile") === null && !logined) {
location.href = "https://www.xmoj.tech/loginpage.php";
const profileElement = document.querySelector("#profile");
if (profileElement === null) {
if (!logined) {
location.href = "https://www.xmoj.tech/loginpage.php";
}
return;
}
let CurrentUsername = document.querySelector("#profile").innerText;
CurrentUsername = profileElement.innerText;
CurrentUsername = CurrentUsername.replaceAll(/[^a-zA-Z0-9]/g, "");
let IsAdmin = AdminUserList.indexOf(CurrentUsername) !== -1;

Expand All @@ -937,7 +950,7 @@ const applyTheme = (theme) => {
localStorage.setItem("UserScript-Setting-DarkMode", theme === "dark" ? "true" : "false");
};
const applySystemTheme = (e) => applyTheme(e.matches ? "dark" : "light");
let initTheme = () => {
initTheme = () => {
const saved = localStorage.getItem("UserScript-Setting-Theme") || "auto";
if (saved === "auto") {
applyTheme(prefersDark.matches ? "dark" : "light");
Expand Down Expand Up @@ -6344,6 +6357,8 @@ int main()
}
}

main().then(r => {
console.log("XMOJ-Script loaded successfully!");
await main();
console.log("XMOJ-Script loaded successfully!");
})().catch(e => {
console.error("[XMOJ-Script] Initialization error:", e);
});
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": "3.4.6",
"version": "3.5.1",
"description": "an improvement script for xmoj.tech",
"main": "AddonScript.js",
"scripts": {
Expand Down
Loading