xmoj-script 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Update.json CHANGED
@@ -2991,6 +2991,17 @@
2991
2991
  }
2992
2992
  ],
2993
2993
  "Notes": "No release notes were provided for this release."
2994
+ },
2995
+ "2.1.3": {
2996
+ "UpdateDate": 1755596470421,
2997
+ "Prerelease": true,
2998
+ "UpdateContents": [
2999
+ {
3000
+ "PR": 835,
3001
+ "Description": "feat: add user-selectable theme"
3002
+ }
3003
+ ],
3004
+ "Notes": "No release notes were provided for this release."
2994
3005
  }
2995
3006
  }
2996
3007
  }
package/XMOJ.user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // ==UserScript==
2
2
  // @name XMOJ
3
- // @version 2.1.2
3
+ // @version 2.1.3
4
4
  // @description XMOJ增强脚本
5
5
  // @author @XMOJ-Script-dev, @langningchen and the community
6
6
  // @namespace https://github/langningchen
@@ -552,6 +552,24 @@ let CurrentUsername = document.querySelector("#profile").innerText;
552
552
  CurrentUsername = CurrentUsername.replaceAll(/[^a-zA-Z0-9]/g, "");
553
553
  let IsAdmin = AdminUserList.indexOf(CurrentUsername) !== -1;
554
554
 
555
+ const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
556
+ const applyTheme = (theme) => {
557
+ document.querySelector("html").setAttribute("data-bs-theme", theme);
558
+ localStorage.setItem("UserScript-Setting-DarkMode", theme === "dark" ? "true" : "false");
559
+ };
560
+ const applySystemTheme = (e) => applyTheme(e.matches ? "dark" : "light");
561
+ let initTheme = () => {
562
+ const saved = localStorage.getItem("UserScript-Setting-Theme") || "auto";
563
+ if (saved === "auto") {
564
+ applyTheme(prefersDark.matches ? "dark" : "light");
565
+ prefersDark.addEventListener("change", applySystemTheme);
566
+ } else {
567
+ applyTheme(saved);
568
+ prefersDark.removeEventListener("change", applySystemTheme);
569
+ }
570
+ };
571
+ initTheme();
572
+
555
573
 
556
574
  class NavbarStyler {
557
575
  constructor() {
@@ -1359,7 +1377,32 @@ async function main() {
1359
1377
  } else if (Data[i].Type == "D") {
1360
1378
  Row.classList.add("list-group-item-danger");
1361
1379
  }
1362
- if (Data[i].Children == undefined) {
1380
+ if (Data[i].ID == "Theme") {
1381
+ let Label = document.createElement("label");
1382
+ Label.classList.add("me-2");
1383
+ Label.htmlFor = "UserScript-Setting-Theme";
1384
+ Label.innerText = Data[i].Name;
1385
+ Row.appendChild(Label);
1386
+ let Select = document.createElement("select");
1387
+ Select.classList.add("form-select", "form-select-sm", "w-auto", "d-inline");
1388
+ Select.id = "UserScript-Setting-Theme";
1389
+ [
1390
+ ["light", "亮色"],
1391
+ ["dark", "暗色"],
1392
+ ["auto", "跟随系统"]
1393
+ ].forEach(opt => {
1394
+ let option = document.createElement("option");
1395
+ option.value = opt[0];
1396
+ option.innerText = opt[1];
1397
+ Select.appendChild(option);
1398
+ });
1399
+ Select.value = localStorage.getItem("UserScript-Setting-Theme") || "auto";
1400
+ Select.addEventListener("change", () => {
1401
+ localStorage.setItem("UserScript-Setting-Theme", Select.value);
1402
+ initTheme();
1403
+ });
1404
+ Row.appendChild(Select);
1405
+ } else if (Data[i].Children == undefined) {
1363
1406
  let CheckBox = document.createElement("input");
1364
1407
  CheckBox.classList.add("form-check-input");
1365
1408
  CheckBox.classList.add("me-1");
@@ -1417,7 +1460,7 @@ async function main() {
1417
1460
  }, {"ID": "ResetType", "Type": "F", "Name": "重新排版*"}, {
1418
1461
  "ID": "AddColorText", "Type": "A", "Name": "增加彩色文字"
1419
1462
  }, {"ID": "AddUnits", "Type": "A", "Name": "状态界面内存与耗时添加单位"}, {
1420
- "ID": "DarkMode", "Type": "A", "Name": "使用暗色模式"
1463
+ "ID": "Theme", "Type": "A", "Name": "界面主题"
1421
1464
  }, {"ID": "AddAnimation", "Type": "A", "Name": "增加动画"}, {
1422
1465
  "ID": "ReplaceYN", "Type": "F", "Name": "题目前状态提示替换为好看的图标"
1423
1466
  }, {"ID": "RemoveAlerts", "Type": "D", "Name": "去除多余反复的提示"}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmoj-script",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "an improvement script for xmoj.tech",
5
5
  "main": "AddonScript.js",
6
6
  "scripts": {