From 8764e01d7e0972f22184b7b16845a192d451d774 Mon Sep 17 00:00:00 2001 From: xream Date: Thu, 1 Feb 2024 21:58:17 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/demo.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 scripts/demo.js diff --git a/scripts/demo.js b/scripts/demo.js new file mode 100644 index 0000000..1eefa83 --- /dev/null +++ b/scripts/demo.js @@ -0,0 +1,119 @@ +function operator(proxies = [], targetPlatform, context) { + // 支持快捷操作 不一定要写一个 function + // 可参考 https://t.me/zhetengsha/970 + // https://t.me/zhetengsha/1009 + + + // proxies 为传入的内部节点数组 + // 结构大致参考了 Clash.Meta(mihomo) 有私货 + // 可在预览界面点击节点查看 JSON 结构 或查看 `target=JSON` 的通用订阅 + // 1. `no-resolve` 为不解析域名 + // 2. 域名解析后 会多一个 `resolved` 字段 + // 3. 节点字段 `exec` 为 `ssr-local` 路径, 默认 `/usr/local/bin/ssr-local`; 端口从 10000 开始递增(暂不支持配置) + + // $arguments 为传入的脚本参数 + + // targetPlatform 为输出的目标平台 + + // lodash + + // $substore 为 OpenAPI + // 参考 https://github.com/Peng-YM/QuanX/blob/master/Tools/OpenAPI/README.md + + // scriptResourceCache 缓存 + // 可参考 https://t.me/zhetengsha/1003 + + // ProxyUtils 为节点处理工具 + // 可参考 https://t.me/zhetengsha/1066 + + // flowUtils 为机场订阅流量信息处理工具 + // 可参考 https://t.me/zhetengsha/948 + // https://github.com/sub-store-org/Sub-Store/blob/31b6dd0507a9286d6ab834ec94ad3050f6bdc86b/backend/src/utils/download.js#L104 + + // context 为传入的上下文 + // 有三种情况, 按需判断 + + // 若存在 `source._collection` 且 `source._collection.subscriptions` 中的 key 在 `source` 上也存在, 说明输出结果为组合订阅, 但是脚本设置在单条订阅上 + + // 若存在 `source._collection` 但 `source._collection.subscriptions` 中的 key 在 `source` 上不存在, 说明输出结果为组合订阅, 脚本设置在组合订阅上 + + // 若不存在 `source._collection`, 说明输出结果为单条订阅, 脚本设置在此单条订阅上 + + // 1. 输出单条订阅 sub-1 时, 该单条订阅中的脚本上下文为: + // { + // "source": { + // "sub-1": { + // "name": "sub-1", + // "displayName": "", + // "mergeSources": "", + // "ignoreFailedRemoteSub": true, + // "process": [], + // "icon": "", + // "source": "local", + // "url": "", + // "content": "", + // "ua": "", + // "display-name": "", + // "useCacheForFailedRemoteSub": false + // } + // }, + // "backend": "Node", + // "version": "2.14.198" + // } + // 2. 输出组合订阅 collection-1 时, 该组合订阅中的脚本上下文为: + // { + // "source": { + // "_collection": { + // "name": "collection-1", + // "displayName": "", + // "mergeSources": "", + // "ignoreFailedRemoteSub": false, + // "icon": "", + // "process": [], + // "subscriptions": [ + // "sub-1" + // ], + // "display-name": "" + // } + // }, + // "backend": "Node", + // "version": "2.14.198" + // } + // 3. 输出组合订阅 collection-1 时, 该组合订阅中的单条订阅 sub-1 中的某个脚本上下文为: + // { + // "source": { + // "sub-1": { + // "name": "sub-1", + // "displayName": "", + // "mergeSources": "", + // "ignoreFailedRemoteSub": true, + // "icon": "", + // "process": [], + // "source": "local", + // "url": "", + // "content": "", + // "ua": "", + // "display-name": "", + // "useCacheForFailedRemoteSub": false + // }, + // "_collection": { + // "name": "collection-1", + // "displayName": "", + // "mergeSources": "", + // "ignoreFailedRemoteSub": false, + // "icon": "", + // "process": [], + // "subscriptions": [ + // "sub-1" + // ], + // "display-name": "" + // } + // }, + // "backend": "Node", + // "version": "2.14.198" + // } + + console.log(JSON.stringify(env, null, 2)) + + return proxies +}