forked from crossutility/Quantumult-X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-configuration-api.js
93 lines (83 loc) · 2.49 KB
/
sample-configuration-api.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @fileoverview Example to deal with current configuration through API $configuration.sendMessage.
*
*
* Action: url_latency_benchmark
* Do the URL Latency Benchmark for the input servers (actually server tags),
* So you can customize (combined with task) your static policy to a url-latency-benchmark like policy.
* For more features maybe added in the future, you may have more control over the policy.
* Returns a JSON like {"ret" : {"Node-001" : [31, 126], "Node-002" : [23, -1]}}
*
*
* Action: get_customized_policy
* Returns a JSON
*
*
* Action: get_policy_state
* Returns a JSON like {"ret" : {"policy1" : ["policy1", "thePolicyThatPolicy1Selected", ... , "theLeaf1"],
* "policy2" : ["policy2", "thePolicyThatPolicy2Selected", ... ,"theLeaf2"]}}
*
*
* Action: set_policy_state
* This only works for the static type policy and the built-in policy named "proxy".
* Related active connections will be closed if the "Moderated Policy Mechanism" is turned off,
* the returned JSON from set_policy_state will resolve (promise) only when all the related connections
* are closed.
* If this API is called in a response type script, even all the related active connections
* (including the connection that called this API) will be closed, but actually the reponse of this connection
* has already been completely received.
* Returns an updated policy state in JSON like {"ret" : {"policy1" : ["policy1", "thePolicyThatPolicy1Selected", ... ,
* "theLeaf1"], "policy2" : ["policy2", "thePolicyThatPolicy2Selected", ... , "theLeaf2"]}}
*
*
* @supported Quantumult X (v1.0.22-build545) iOS 13.0 +
*/
/*
const dict = {"proxy": "Node-002", "cPolicy": "Node-007"};
const message = {
action: "set_policy_state",
content: dict
};
*/
/*
const array = ["Node-001","Node-002","Node-003","Node-004"];
const message = {
action: "url_latency_benchmark",
content: array
};
*/
/*
const message = {
action: "get_customized_policy"
};
*/
/*
const data = "PolicyName";
const message = {
action: "get_customized_policy",
content: data
};
*/
/*
const data = ["PolicyName1","PolicyName2"];
const message = {
action: "get_customized_policy",
content: data
};
*/
const message = {
action: "get_policy_state"
};
$configuration.sendMessage(message).then(resolve => {
if (resolve.error) {
console.log(resolve.error);
}
if (resolve.ret) {
let output=JSON.stringify(resolve.ret);
console.log(output);
}
$done();
}, reject => {
// Normally will never happen.
$done();
});