shawenguan 2 年之前
父節點
當前提交
7e79cdc0ca
共有 4 個文件被更改,包括 348 次插入239 次删除
  1. 117 110
      BoxJsSub/JoJo_BoxJs.json
  2. 147 102
      Scripts/gandart/gandartHelper.js
  3. 84 27
      Scripts/util/ToolKit.js
  4. 0 0
      Scripts/util/ToolKit.min.js

+ 117 - 110
BoxJsSub/JoJo_BoxJs.json

@@ -1,114 +1,121 @@
 {
-    "id": "JoJo.app.sub",
-    "name": "JoJo应用订阅",
-    "description": "JoJo私人QX应用订阅",
-    "author": "@JoJo",
-    "icon": "https://avatars.githubusercontent.com/u/16010188",
-    "repo": "http://git.jojo21.cf/shawenguan/Quantumult-X",
-    "apps": [
+  "id": "JoJo.app.sub",
+  "name": "JoJo应用订阅",
+  "description": "JoJo私人QX应用订阅",
+  "author": "@JoJo",
+  "icon": "https://avatars.githubusercontent.com/u/16010188",
+  "repo": "http://git.jojo21.cf/shawenguan/Quantumult-X",
+  "apps": [
+    {
+      "id": "lkGandartHelper",
+      "name": "光予助手",
+      "author": "@jojo",
+      "repo": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js",
+      "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js",
+      "icons": [
+        "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Images/gandart.png",
+        "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Images/gandart.png"
+      ],
+      "scripts": [
         {
-            "id": "lkGandartHelper",
-            "name": "光予助手",
-            "author": "@jojo",
-            "repo": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js",
-            "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js",
-            "icons": [
-                "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Images/gandart.png",
-                "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Images/gandart.png"
-            ],
-            "scripts": [
-                {
-                    "name": "极速购买",
-                    "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js"
-                },
-                {
-                    "name": "极速合成",
-                    "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js"
-                },
-                {
-                    "name": "极速置换",
-                    "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js"
-                }
-            ],
-            "keys": [
-                "lkGandartToken",
-                "lkGandartCastingId",
-                "lkGandartTransactionRecordId",
-                "lkGandartLimitPrice",
-                "lkGandartCollectionName"
-            ],
-            "settings": [
-                {
-                  "id": "lkIsEnableLogGandartHelperCheckIn",
-                  "name": "开启/关闭日志",
-                  "val": true,
-                  "type": "boolean",
-                  "desc": "默认开启"
-                },
-                {
-                  "id": "lkNotifyOnlyFailGandartHelperCheckIn",
-                  "name": "只当执行失败才通知",
-                  "val": false,
-                  "type": "boolean",
-                  "desc": "默认关闭"
-                },
-                {
-                  "id": "lkIsEnableTgNotifyGandartHelperCheckIn",
-                  "name": "开启/关闭Telegram通知",
-                  "val": false,
-                  "type": "boolean",
-                  "desc": "默认关闭"
-                },
-                {
-                  "id": "lkTgNotifyUrlGandartHelperCheckIn",
-                  "name": "Telegram通知地址",
-                  "val": "",
-                  "type": "text",
-                  "desc": "Tg的通知地址,如:https://api.telegram.org/bot-token/sendMessage?chat_id=-100140&parse_mode=Markdown&text="
-                },
-                {
-                  "id": "lkGandartToken",
-                  "name": "token",
-                  "val": "",
-                  "type": "text",
-                  "desc": "授权token"
-                },
-                {
-                  "id": "lkGandartCastingId",
-                  "name": "产品铸造品类ID",
-                  "val": "",
-                  "type": "text",
-                  "desc": "产品铸造品类ID"
-                },
-                {
-                  "id": "lkGandartTransactionRecordId",
-                  "name": "产品记录ID",
-                  "val": "",
-                  "type": "text",
-                  "desc": "产品记录ID(非编号)"
-                },
-                {
-                  "id": "lkGandartLimitPrice",
-                  "name": "价格上限",
-                  "val": 0,
-                  "type": "number",
-                  "desc": "价格上限"
-                },
-                {
-                  "id": "lkGandartCollectionName",
-                  "name": "产品名称",
-                  "val": "",
-                  "type": "text",
-                  "desc": "产品名称"
-                },
-                {
-                  "id": "lkGandartCollectionCateLst",
-                  "name": "产品列表",
-                  "val": "[]",
-                  "type": "textarea",
-                  "desc": "产品列表"
-                }
-            ]
+          "name": "极速购买",
+          "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js"
+        },
+        {
+          "name": "极速合成",
+          "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js"
+        },
+        {
+          "name": "极速置换",
+          "script": "https://git.jojo21.cf/shawenguan/Quantumult-X/raw/master/Scripts/gandartHelper.js"
+        }
+      ],
+      "keys": [
+        "lkGandartToken",
+        "lkGandartCastingId",
+        "lkGandartTransactionRecordId",
+        "lkGandartLimitPrice",
+        "lkGandartCollectionName"
+      ],
+      "settings": [
+        {
+          "id": "lkIsEnableLogGandartHelperCheckIn",
+          "name": "开启/关闭日志",
+          "val": true,
+          "type": "boolean",
+          "desc": "默认开启"
+        },
+        {
+          "id": "lkNotifyOnlyFailGandartHelperCheckIn",
+          "name": "只当执行失败才通知",
+          "val": false,
+          "type": "boolean",
+          "desc": "默认关闭"
+        },
+        {
+          "id": "lkIsEnableTgNotifyGandartHelperCheckIn",
+          "name": "开启/关闭通知",
+          "val": false,
+          "type": "boolean",
+          "desc": "默认关闭"
+        },
+        {
+          "id": "lkTgNotifyUrlGandartHelperCheckIn",
+          "name": "通知地址",
+          "val": "",
+          "type": "text",
+          "desc": "Tg的通知地址,如:https://api.telegram.org/bot-token/sendMessage?chat_id=-100140&parse_mode=Markdown&text="
+        },
+        {
+          "id": "lkGandartToken",
+          "name": "token",
+          "val": "",
+          "type": "text",
+          "desc": "授权token"
+        },
+        {
+          "id": "lkGandartCastingId",
+          "name": "产品铸造品类ID",
+          "val": "",
+          "type": "text",
+          "desc": "产品铸造品类ID"
+        },
+        {
+          "id": "lkGandartTransactionRecordId",
+          "name": "产品记录ID",
+          "val": "",
+          "type": "text",
+          "desc": "产品记录ID(非编号)"
+        },
+        {
+          "id": "lkGandartLimitPrice",
+          "name": "捡漏最大价格",
+          "val": 0,
+          "type": "number",
+          "desc": "捡漏最大价格"
+        },
+        {
+          "id": "lkGandartFloatPriceIntaval",
+          "name": "价格浮动限制",
+          "val": 10,
+          "type": "number",
+          "desc": "价格浮动限制"
+        },
+        {
+          "id": "lkGandartCollectionName",
+          "name": "产品名称",
+          "val": "",
+          "type": "text",
+          "desc": "产品名称"
+        },
+        {
+          "id": "lkGandartCollectionCateLst",
+          "name": "产品列表",
+          "val": "[]",
+          "type": "textarea",
+          "desc": "产品列表"
         }
-    ]
+      ]
+    }
+  ]
 }

File diff suppressed because it is too large
+ 147 - 102
Scripts/gandart/gandartHelper.js


+ 84 - 27
Scripts/util/ToolKit.js

@@ -75,9 +75,53 @@ function ToolKit(scriptName, scriptId, options) {
             this.notifyInfo = []
             this.log(`${this.name}, 开始执行!`)
             this.initCache()
+            this.checkRecordRequestBody()
             this.execComm()
         }
 
+        checkRecordRequestBody() {
+            if (!this.isRequest()) {
+                return;
+            }
+            const reqBody = $request.body;
+            if (!reqBody) {
+                return;
+            }
+            const path = $request.path;
+            const cacheKey = this.id + "#" + path.replace("/", "_");
+            if (this.isQuanX()) $prefs.setValueForKey(reqBody, cacheKey);
+            if (this.isLoon() || this.isSurge()) $persistentStore.write(reqBody, cacheKey);
+            if (this.isNode()) {
+                this.node.fs.writeFileSync(
+                    `${cacheKey}.json`,
+                    reqBody,
+                    {
+                        flag: "w"
+                    },
+                    (err) => console.log(err)
+                );
+            }
+        }
+
+        getRequestBody() {
+            const path = $request.path;
+            const cacheKey = this.id + "#" + path.replace("/", "_");
+            if (this.isSurge() || this.isLoon()) {
+                return $persistentStore.read(cacheKey);
+            }
+            if (this.isQuanX()) {
+                return $prefs.valueForKey(cacheKey);
+            }
+            if (this.isNode()) {
+                const fpath = `${cacheKey}.json`;
+                if (!this.node.fs.existsSync(fpath)) {
+                    return JSON.parse(
+                        this.node.fs.readFileSync(fpath)
+                    );
+                }
+            }
+        }
+
         // persistence
         // initialize cache
         initCache() {
@@ -92,9 +136,10 @@ function ToolKit(scriptName, scriptId, options) {
                 if (!this.node.fs.existsSync(fpath)) {
                     this.node.fs.writeFileSync(
                         fpath,
-                        JSON.stringify({}), {
-                        flag: "wx"
-                    },
+                        JSON.stringify({}),
+                        {
+                            flag: "wx"
+                        },
                         (err) => console.log(err)
                     );
                 }
@@ -105,9 +150,10 @@ function ToolKit(scriptName, scriptId, options) {
                 if (!this.node.fs.existsSync(fpath)) {
                     this.node.fs.writeFileSync(
                         fpath,
-                        JSON.stringify({}), {
-                        flag: "wx"
-                    },
+                        JSON.stringify({}),
+                        {
+                            flag: "wx"
+                        },
                         (err) => console.log(err)
                     );
                     this.cache = {};
@@ -120,7 +166,7 @@ function ToolKit(scriptName, scriptId, options) {
         }
 
         getPersistKey() {
-            return `private_${this.id}`;
+            return `${this.id}#privateCache`;
         }
 
         // store cache
@@ -132,16 +178,18 @@ function ToolKit(scriptName, scriptId, options) {
             if (this.isNode()) {
                 this.node.fs.writeFileSync(
                     `${pKey}.json`,
-                    data, {
-                    flag: "w"
-                },
+                    data,
+                    {
+                        flag: "w"
+                    },
                     (err) => console.log(err)
                 );
                 this.node.fs.writeFileSync(
                     "root.json",
-                    JSON.stringify(this.root, null, 2), {
-                    flag: "w"
-                },
+                    JSON.stringify(this.root, null, 2),
+                    {
+                        flag: "w"
+                    },
                     (err) => console.log(err)
                 );
             }
@@ -810,7 +858,9 @@ function ToolKit(scriptName, scriptId, options) {
         }
 
         getResponseBody() {
-            return $response.body
+            if ($response) {
+                return $response.body
+            }
         }
 
         isGetCookie(reg) {
@@ -944,25 +994,32 @@ function ToolKit(scriptName, scriptId, options) {
             return format
         }
 
-        /**
-         *
-         * @param {Object} options
-         * @returns {String} 将 Object 对象 转换成 queryStr: key=val&name=senku
-         */
-        queryStr(options) {
-            let queryString = ''
-
-            for (const key in options) {
-                let value = options[key]
+        objToQueryStr(obj, encode) {
+            let str = ''
+            for (const key in obj) {
+                let value = obj[key]
                 if (value != null && value !== '') {
                     if (typeof value === 'object') {
                         value = JSON.stringify(value)
+                    } else if (encode) {
+                        value = encodeURIComponent(value)
                     }
-                    queryString += `${key}=${value}&`
+                    str += `${key}=${value}&`
                 }
             }
-            queryString = queryString.substring(0, queryString.length - 1)
-            return queryString
+            str = str.substring(0, str.length - 1)
+            return str
+        }
+
+        parseQueryStr(str) {
+            let obj = {};
+            let str1 = str.split("?");
+            let str2 = str1[1].split("&");  //["a=1", "b=2", "c=3"]
+            for (let i = 0; i < str2.length; i++) {
+                let str3 = str2[i].split("=");
+                obj[str3[0]] = str3[1]
+            }
+            return obj
         }
     })(scriptName, scriptId, options)
 }

File diff suppressed because it is too large
+ 0 - 0
Scripts/util/ToolKit.min.js


Some files were not shown because too many files changed in this diff