MCPcopy Index your code
hub / github.com/NobyDa/Script / nobyda

Function nobyda

Shortcuts/PolicySwitch.js:38–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36})()
37
38function nobyda() {
39 const isLoon = typeof($loon) !== "undefined";
40 const isQuanX = typeof($configuration) !== 'undefined';
41 const isSurge = typeof($httpAPI) !== 'undefined';
42 const m = `不支持您的APP版本, 请等待APP更新 ⚠️`;
43 this.getGroup = () => {
44 if (isSurge) {
45 return new Promise((resolve) => {
46 $httpAPI("GET", "v1/policies", {}, (b) => resolve(b['policy-groups']))
47 })
48 }
49 if (isLoon) {
50 const getName = JSON.parse($config.getConfig());
51 return getName['all_policy_groups'];
52 }
53 if (isQuanX) {
54 return new Promise((resolve) => {
55 $configuration.sendMessage({
56 action: "get_customized_policy"
57 }).then(b => {
58 if (b.ret) {
59 resolve(Object.keys(b.ret).filter(s => b.ret[s].type == "static"));
60 } else resolve();
61 }, () => resolve());
62 })
63 }
64 return m;
65 }
66 this.getPolicy = (groupName) => {
67 if (isSurge) {
68 return new Promise((resolve) => {
69 $httpAPI("GET", "v1/policy_groups", {}, (b) => {
70 resolve(b[groupName].map(g => g.name))
71 })
72 })
73 }
74 if (isLoon) {
75 return new Promise((resolve) => {
76 $config.getSubPolicys(groupName, (b) => {
77 const get = JSON.parse(b || '[]').map(n => n.name);
78 resolve(get)
79 })
80 })
81 }
82 if (isQuanX) {
83 return new Promise((resolve) => {
84 $configuration.sendMessage({
85 action: "get_customized_policy",
86 content: groupName
87 }).then(b => {
88 if (b.ret && b.ret[groupName]) {
89 resolve(b.ret[groupName].candidates);
90 } else resolve();
91 }, () => resolve());
92 })
93 }
94 return m;
95 }

Callers

nothing calls this directly

Calls 1

stringifyMethod · 0.45

Tested by

no test coverage detected