Browse Source

小细节升级

zxlie 11 months ago
parent
commit
5c79ed29f9

+ 4 - 4
apps/background/tools.js

@@ -71,11 +71,11 @@ let toolMap = {
         }]
     },
     'chatgpt': {
-        name: 'ChatGPT工具',
-        tips: '由OpenAI强力支撑的超智能对话工具,可以让它帮你写代码、查资料、做分析、甚至帮你画一幅画',
+        name: 'AI(智能助手)',
+        tips: '由AI强力支撑的超智能对话工具,可以让它帮你写代码、改代码、做方案设计、查资料、做分析等',
         menuConfig: [{
-            icon: '',
-            text: 'ChatGPT工具'
+            icon: '֍',
+            text: 'AI(智能助手)'
         }]
     },
     'timestamp': {

+ 61 - 1
apps/en-decode/endecode-lib.js

@@ -434,6 +434,65 @@ let EncodeUtils = (() => {
         return hex;
     };
 
+    // 来自网友的贡献,做jwt解码
+    let jwtDecode = (() => {
+        class InvalidTokenError extends Error {
+        }
+        InvalidTokenError.prototype.name = "InvalidTokenError";
+        function b64DecodeUnicode(str) {
+            return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
+                let code = p.charCodeAt(0).toString(16).toUpperCase();
+                if (code.length < 2) {
+                    code = "0" + code;
+                }
+                return "%" + code;
+            }));
+        }
+        function base64UrlDecode(str) {
+            let output = str.replace(/-/g, "+").replace(/_/g, "/");
+            switch (output.length % 4) {
+                case 0:
+                    break;
+                case 2:
+                    output += "==";
+                    break;
+                case 3:
+                    output += "=";
+                    break;
+                default:
+                    throw new Error("base64 string is not of the correct length");
+            }
+            try {
+                return b64DecodeUnicode(output);
+            }
+            catch (err) {
+                return atob(output);
+            }
+        }
+        return function(token) {
+            if (typeof token !== "string") {
+                throw new InvalidTokenError("Invalid token specified: must be a string");
+            }
+            const parts = token.split(".");
+           
+            if (parts.length !== 3) {
+                throw new InvalidTokenError("Invalid token specified: must be three parts");
+            }
+            
+            for(let part of parts){
+                if (typeof part !== "string") {
+                    throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
+                }        
+            }
+        
+            return {
+                header: base64UrlDecode(parts[0]),
+                payload: base64UrlDecode(parts[1]),
+                sign: parts[2]
+            }
+        }
+    })();
+
     return {
         uniEncode: _uniEncode,
         uniDecode: _uniDecode,
@@ -448,7 +507,8 @@ let EncodeUtils = (() => {
         hexDecode: hexTools.hexDecode,
         html2js: _html2js,
         urlParamsDecode: _urlParamsDecode,
-        sha1Encode: _sha1Encode
+        sha1Encode: _sha1Encode,
+        jwtDecode
     };
 })();
 

+ 3 - 0
apps/en-decode/index.html

@@ -90,6 +90,9 @@
                             <div class="radio ui-d-ib ui-mr-20">
                                 <label><input type="radio" name="codeType" value="urlParamsDecode" v-model="selectedType" @click="convert()">URL参数解析</label>
                             </div>
+                            <div class="radio ui-d-ib ui-mr-20">
+                                <label><input type="radio" name="codeType" value="jwtDecode" v-model="selectedType" @click="convert()">JWT解码</label>
+                            </div>
                         </td>
                     </tr>
                 </table>

+ 4 - 0
apps/en-decode/index.js

@@ -101,6 +101,10 @@ new Vue({
                     } else {
                         this.urlResult = res;
                     }
+                } else if(this.selectedType === 'jwtDecode') {
+
+                    let {header,payload,sign} = EncodeUtils.jwtDecode(this.sourceContent);
+                    this.resultContent = `Header: ${header}\n\nPayload: ${payload}\n\nSign: ${sign}`;
                 }
                 this.$forceUpdate();
             });

+ 1 - 1
apps/manifest.json

@@ -1,7 +1,7 @@
 {
   "name": "FeHelper(前端助手)-Dev",
   "short_name": "FeHelper",
-  "version": "2023.03.2912",
+  "version": "2024.12.1412",
   "manifest_version": 3,
   "description": "JSON自动格式化、手动格式化,支持排序、解码、下载等,更多功能可在配置页按需安装!",
   "icons": {