Selaa lähdekoodia

什么值得买

shawenguan 1 vuosi sitten
vanhempi
commit
0cf50cb6b8
2 muutettua tiedostoa jossa 661 lisäystä ja 3 poistoa
  1. 602 0
      Scripts/smzdm/smzdmHelper.js
  2. 59 3
      Scripts/util/MagicJS3.js

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 602 - 0
Scripts/smzdm/smzdmHelper.js


+ 59 - 3
Scripts/util/MagicJS3.js

@@ -155,6 +155,7 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
                 }
             }
             this.logger.info(`${scriptName}, 开始执行!`);
+            // this.checkRecordRequestBody();
         }
         get isRequest() {
             return typeof $request !== "undefined" && typeof $response === "undefined";
@@ -178,6 +179,61 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
             }
         }
 
+        checkRecordRequestBody() {
+            if (!this.isRequest) {
+                return;
+            }
+            const reqBody = $request.body;
+            if (!reqBody) {
+                return;
+            }
+            const env = this.env;
+            const path = $request.path;
+            let cacheKey = this.scriptName + "#" + path.replace("/", "_");
+            cacheKey = cacheKey.replace("?", "#");
+            if (env.isQuanX) $prefs.setValueForKey(reqBody, cacheKey);
+            if (env.isLoon || env.isSurge) $persistentStore.write(reqBody, cacheKey);
+            if (env.isNode) {
+                const node_fs = require("fs");
+                node_fs.writeFileSync(
+                    `${cacheKey}.json`,
+                    reqBody,
+                    {
+                        flag: "w"
+                    },
+                    (err) => console.log(err)
+                );
+            }
+        }
+
+        getRequestBody() {
+            const env = this.env;
+            const path = $request.path;
+            let cacheKey = this.scriptName + "#" + path.replace("/", "_");
+            cacheKey = cacheKey.replace("?", "#");
+            if (env.isSurge || env.isLoon) {
+                return $persistentStore.read(cacheKey);
+            }
+            if (env.isQuanX) {
+                return $prefs.valueForKey(cacheKey);
+            }
+            if (env.isNode) {
+                const fpath = `${cacheKey}.json`;
+                const node_fs = require("fs");
+                if (!node_fs.existsSync(fpath)) {
+                    return JSON.parse(
+                        node_fs.readFileSync(fpath)
+                    );
+                }
+            }
+        }
+
+        getResponseBody() {
+            if ($response) {
+                return $response.body;
+            }
+        }
+
         costTime() {
             let info = `${this.scriptName}执行完毕!`
             // if (this.isNode && this.isExecComm) {
@@ -837,15 +893,15 @@ function MagicNotification(scriptName, env, logger, http) {
                 let newOpts = {};
                 if (typeof _opts === "string") {
                     if(_opts.length > 0){
-                        if (this.isLoon){
+                        if (env.isLoon){
                             newOpts = {
                                 openUrl: _opts
                             };
-                        }else if (this.isQuanX){
+                        }else if (env.isQuanX){
                             newOpts = {
                                 "open-url": _opts
                             };
-                        }else if (this.isSurge){
+                        }else if (env.isSurge){
                             newOpts = {
                                 url: _opts
                             };

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä