shawenguan hai 1 ano
pai
achega
f8005aa2ab
Modificáronse 1 ficheiros con 45 adicións e 3 borrados
  1. 45 3
      Scripts/wubian/wubianScoreRank.js

+ 45 - 3
Scripts/wubian/wubianScoreRank.js

@@ -144,16 +144,58 @@ async function tryCheckScoreRank() {
     doCheckShowRankText(rankData);
 }
 
+function padStringStart(inputString, totalLength, paddingChar = ' ') {
+    const chineseRegex = /[\u4E00-\u9FA5]/g; // 匹配中文字符的正则表达式
+    let chineseLength = 0;
+    const matches = inputString.match(chineseRegex);
+    if (matches) {
+        chineseLength = matches.length;
+    }
+
+    const stringLength = inputString.length + chineseLength;
+    if (stringLength >= totalLength) {
+        return inputString;
+    } else {
+        const remainingLength = totalLength - stringLength;
+        let paddedString = inputString;
+        for (let i = 0; i < remainingLength; i++) {
+            paddedString = paddingChar + paddedString;
+        }
+        return paddedString;
+    }
+}
+
+function padStringEnd(inputString, totalLength, paddingChar = ' ') {
+    const chineseRegex = /[\u4E00-\u9FA5]/g; // 匹配中文字符的正则表达式
+    let chineseLength = 0;
+    const matches = inputString.match(chineseRegex);
+    if (matches) {
+        chineseLength = matches.length;
+    }
+
+    const stringLength = inputString.length + chineseLength;
+    if (stringLength >= totalLength) {
+        return inputString;
+    } else {
+        const remainingLength = totalLength - stringLength;
+        let paddedString = inputString;
+        for (let i = 0; i < remainingLength; i++) {
+            paddedString = paddedString + paddingChar;
+        }
+        return paddedString;
+    }
+}
+
 function doCheckShowRankText(rankData) {
     let text = '';
     let rankList = rankData.rankList;
     for (let i = 0; i < rankList.length; i++) {
         let rankInfo = rankList[i];
-        text += `${(i + 1).toString().padStart(2, '*', 'utf8')}、${rankInfo.nickName}  消费¥${rankInfo.score},买入详情:\n`;
+        text += `${padStringStart((i + 1).toString(), 2)}、${rankInfo.nickName}  消费¥${rankInfo.score},买入详情:\n`;
         let buyArtList = rankInfo.buyArtList || [];
         for (let j = 0; j < buyArtList.length; j++) {
             let artInfo = buyArtList[j];
-            text += `    ${artInfo.artName.padEnd(10, '*', 'utf8')}  均价:¥${artInfo.unitPrice.toFixed(2).padStart(6, '*', 'utf8')}  数量:${artInfo.num.toString().padStart(4, '*', 'utf8')}\n`;
+            text += `    ${padStringEnd(artInfo.artName, 10)}  均价:¥${padStringStart(artInfo.unitPrice.toFixed(2), 6)}  数量:${padStringStart(artInfo.num.toString(), 4)}\n`;
         }
         text += `\n`;
     }
@@ -163,7 +205,7 @@ function doCheckShowRankText(rankData) {
     let selfBuyArtList = selfData.buyArtList || [];
     for (let j = 0; j < selfBuyArtList.length; j++) {
         let artInfo = selfBuyArtList[j];
-        text += `    ${artInfo.artName.padEnd(10, '*', 'utf8')}  均价:¥${artInfo.unitPrice.toFixed(2).padStart(6, '*', 'utf8')}  数量:${artInfo.num.toString().padStart(4, '*', 'utf8')}\n`;
+        text += `    ${padStringEnd(artInfo.artName, 10)}  均价:¥${padStringStart(artInfo.unitPrice.toFixed(2), 6)}  数量:${padStringStart(artInfo.num.toString(), 4)}\n`;
     }
     text += `\n`;
     magicJS.notification.appendNotifyInfo(text);