xmoj-script 1.1.58 → 1.1.59

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
@@ -1469,6 +1469,17 @@
1469
1469
  }
1470
1470
  ],
1471
1471
  "Notes": "No release notes were provided for this release."
1472
+ },
1473
+ "1.1.59": {
1474
+ "UpdateDate": 1713676517652,
1475
+ "Prerelease": true,
1476
+ "UpdateContents": [
1477
+ {
1478
+ "PR": 515,
1479
+ "Description": "允许管理在用户页管理badge并在修改badge后清除缓存"
1480
+ }
1481
+ ],
1482
+ "Notes": "No release notes were provided for this release."
1472
1483
  }
1473
1484
  }
1474
1485
  }
package/XMOJ.user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // ==UserScript==
2
2
  // @name XMOJ
3
- // @version 1.1.58
3
+ // @version 1.1.59
4
4
  // @description XMOJ增强脚本
5
5
  // @author @XMOJ-Script-dev, @langningchen and the community
6
6
  // @namespace https://github/langningchen
@@ -2681,7 +2681,15 @@ async function main() {
2681
2681
  BadgeContent.value = Response.Data.Content;
2682
2682
  BadgeBackgroundColor.value = Response.Data.BackgroundColor;
2683
2683
  BadgeColor.value = Response.Data.Color;
2684
- SuccessElement.innerText += ",用户标签会在一天内生效";
2684
+ let Temp = [];
2685
+ for (let i = 0; i < localStorage.length; i++) {
2686
+ if (localStorage.key(i).startsWith("UserScript-User-" + CurrentUsername + "-Badge-")) {
2687
+ Temp.push(localStorage.key(i));
2688
+ }
2689
+ }
2690
+ for (let i = 0; i < Temp.length; i++) {
2691
+ localStorage.removeItem(Temp[i]);
2692
+ }
2685
2693
  }
2686
2694
  });
2687
2695
  ModifyInfo.addEventListener("click", async () => {
@@ -2855,7 +2863,63 @@ async function main() {
2855
2863
  let lastOnlineElement = document.createElement('div');
2856
2864
  lastOnlineElement.innerHTML = "最后在线:加载中...<br>";
2857
2865
  UserInfoElement.appendChild(lastOnlineElement);
2858
-
2866
+ let BadgeInfo = await GetUserBadge(UserID);
2867
+ if (IsAdmin) {
2868
+ if (BadgeInfo.Content !== "") {
2869
+ let DeleteBadgeButton = document.createElement("button");
2870
+ DeleteBadgeButton.className = "btn btn-outline-danger btn-sm";
2871
+ DeleteBadgeButton.innerText = "删除标签";
2872
+ DeleteBadgeButton.addEventListener("click", async () => {
2873
+ if (confirm("您确定要删除此标签吗?")) {
2874
+ RequestAPI("DeleteBadge", {
2875
+ "UserID": UserID
2876
+ }, (Response) => {
2877
+ if (UtilityEnabled("DebugMode")) console.log(Response);
2878
+ if (Response.Success) {
2879
+ let Temp = [];
2880
+ for (let i = 0; i < localStorage.length; i++) {
2881
+ if (localStorage.key(i).startsWith("UserScript-User-" + UserID + "-Badge-")) {
2882
+ Temp.push(localStorage.key(i));
2883
+ }
2884
+ }
2885
+ for (let i = 0; i < Temp.length; i++) {
2886
+ localStorage.removeItem(Temp[i]);
2887
+ }
2888
+ window.location.reload();
2889
+ } else {
2890
+ alert(Response.Message);
2891
+ }
2892
+ });
2893
+ }
2894
+ });
2895
+ UserInfoElement.appendChild(DeleteBadgeButton);
2896
+ } else {
2897
+ let AddBadgeButton = document.createElement("button");
2898
+ AddBadgeButton.className = "btn btn-outline-primary btn-sm";
2899
+ AddBadgeButton.innerText = "添加标签";
2900
+ AddBadgeButton.addEventListener("click", async () => {
2901
+ RequestAPI("NewBadge", {
2902
+ "UserID": UserID
2903
+ }, (Response) => {
2904
+ if (Response.Success) {
2905
+ let Temp = [];
2906
+ for (let i = 0; i < localStorage.length; i++) {
2907
+ if (localStorage.key(i).startsWith("UserScript-User-" + UserID + "-Badge-")) {
2908
+ Temp.push(localStorage.key(i));
2909
+ }
2910
+ }
2911
+ for (let i = 0; i < Temp.length; i++) {
2912
+ localStorage.removeItem(Temp[i]);
2913
+ }
2914
+ window.location.reload();
2915
+ } else {
2916
+ alert(Response.Message);
2917
+ }
2918
+ });
2919
+ });
2920
+ UserInfoElement.appendChild(AddBadgeButton);
2921
+ }
2922
+ }
2859
2923
  RequestAPI("LastOnline", {"Username": UserID}, (result) => {
2860
2924
  if (result.Success) {
2861
2925
  if (UtilityEnabled("DebugMode")) {
@@ -3883,7 +3947,7 @@ int main()
3883
3947
  }, async (ResponseData) => {
3884
3948
  if (ResponseData.Success == true) {
3885
3949
  ErrorElement.style.display = "none";
3886
- if(!Silent) {
3950
+ if (!Silent) {
3887
3951
  DiscussPagination.children[0].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=1";
3888
3952
  DiscussPagination.children[1].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=" + (Page - 1);
3889
3953
  DiscussPagination.children[2].children[0].href = "https://www.xmoj.tech/discuss3/discuss.php?" + (isNaN(ProblemID) ? "" : "pid=" + ProblemID + "&") + "page=" + Page;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmoj-script",
3
- "version": "1.1.58",
3
+ "version": "1.1.59",
4
4
  "description": "an improvement script for xmoj.tech",
5
5
  "main": "AddonScript.js",
6
6
  "scripts": {