forked from VirgilClyne/GetSomeFries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpapi.js
79 lines (74 loc) · 2.18 KB
/
httpapi.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
async function checkHTTPAPI() {
if (isSurge) {
if (typeof ($httpAPI) === 'undefined') $.log();$.done();
} else if (isLoon) {
if (typeof ($config) === 'undefined') $.log();$.done();
} else if (isQuanX) {
if (typeof ($configuration) === 'undefined') $.log();$.done();
} else $.log()
}
async function getPolicy(groupName) {
if (isSurge) {
$httpAPI("GET", "v1/policy_groups/select", { group_name: encodeURIComponent(groupName) }, (result));
return result.policy
}
if (isLoon) {
return $config.getPolicy(groupName);
}
if (isQuanX) {
result = $configuration.sendMessage({ action: "get_policy_state" })
if (result.ret && result.ret[groupName]) return (result.ret[groupName][1]);
}
}
// https://github.com/NobyDa/Script
const getPolicy = (groupName) => {
if (isSurge) {
if (typeof($httpAPI) === 'undefined') return 3;
return new Promise((resolve) => {
$httpAPI("GET", "v1/policy_groups/select", {
group_name: encodeURIComponent(groupName)
}, (b) => resolve(b.policy || 2))
})
}
if (isLoon) {
if (typeof($config.getPolicy) === 'undefined') return 3;
const getName = $config.getPolicy(groupName);
return getName || 2;
}
if (isQuanX) {
if (typeof($configuration) === 'undefined') return 3;
return new Promise((resolve) => {
$configuration.sendMessage({
action: "get_policy_state"
}).then(b => {
if (b.ret && b.ret[groupName]) {
resolve(b.ret[groupName][1]);
} else resolve(2);
}, () => resolve());
})
}
}
const setPolicy = (group, policy) => {
if (isSurge && typeof($httpAPI) !== 'undefined') {
return new Promise((resolve) => {
$httpAPI("POST", "v1/policy_groups/select", {
group_name: group,
policy: policy
}, (b) => resolve(!b.error || 0))
})
}
if (isLoon && typeof($config.getPolicy) !== 'undefined') {
const set = $config.setSelectPolicy(group, policy);
return set || 0;
}
if (isQuanX && typeof($configuration) !== 'undefined') {
return new Promise((resolve) => {
$configuration.sendMessage({
action: "set_policy_state",
content: {
[group]: policy
}
}).then((b) => resolve(!b.error || 0), () => resolve());
})
}
}