forked from 71n9/prophet
-
Notifications
You must be signed in to change notification settings - Fork 4
/
myRuleModule.js
47 lines (41 loc) · 1.13 KB
/
myRuleModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const astHook = require("./astHook");
const handleCode = require("./handleCode");
module.exports = {
*beforeSendResponse (requestDetail, responseDetail) {
if (typeof requestDetail.url != "string") {
return null;
}
//正常的js和html文件
return astHook.astHook(requestDetail, responseDetail);
},
*beforeSendRequest (requestDetail) {
if (typeof requestDetail.url != "string") {
return null;
}
var code = requestDetail.requestData.toString();
if (requestDetail.requestOptions.path == "/hook_jscode") {
//eval("内容")
try {
let head = "(function $$() {", tail = "})( /**/);";
code = handleCode.jsCode(head + code + tail, true).replace(head, "").replace(tail, "")
} catch (err) {
console.log("请求解析失败", err, code);
}
} else if (requestDetail.requestOptions.path == "/hook_config") {
//配置
astHook.config(code)
} else {
return null
}
return {
response: {
statusCode: 200,
header: {
"content-type": "text/plain; charset=utf-8",
"access-control-allow-origin": "*",
},
body: code,
},
};
},
};