feat: ⚠️ BREAKING CHANGE 脚本中的 第三个参数 context 改为脚本共享的上下文, 可自由操作. 原本的 env 信息, 现在为 context.env

This commit is contained in:
xream committed 2025-12-27 17:09:42 +08:00
1 parent 311a929ebe
commit 6c553e430c
4 files changed
+32 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.20.58",
"version": "2.20.59",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
+2
View File
@@ -99,6 +99,7 @@ async function processFn(
source,
$options,
) {
let context = {};
for (const item of operators) {
if (item.disabled) {
$.log(
@@ -222,6 +223,7 @@ async function processFn(
$arguments,
source,
$options,
context,
);
} else {
processor = PROXY_PROCESSORS[item.type](item.args || {});
@@ -371,7 +371,16 @@ function RegexDeleteOperator(regex) {
1. This function name should be `operator`!
2. Always declare variables before using them!
*/
function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
function ScriptOperator(
script,
targetPlatform,
$arguments,
source,
$options,
context,
) {
context.source = source;
context.env = env;
return {
name: 'Script Operator',
func: async (proxies) => {
@@ -423,7 +432,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
$arguments,
$options,
);
output = operator(proxies, targetPlatform, { source, ...env });
output = operator(proxies, targetPlatform, context);
})();
return output;
},
@@ -432,7 +441,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
await (async function () {
const operator = createDynamicFunction(
'operator',
`async function operator(input = []) {
`async function operator(input = [], targetPlatform, context) {
if (input && (input.$files || input.$content)) {
let { $content, $files, $options, $file } = input
if($file.type === 'mihomoProfile') {
@@ -475,7 +484,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
$arguments,
$options,
);
output = operator(proxies, targetPlatform, { source, ...env });
output = operator(proxies, targetPlatform, context);
})();
return output;
},
@@ -949,7 +958,16 @@ function TypeFilter(input) {
1. This function name should be `filter`!
2. Always declare variables before using them!
*/
function ScriptFilter(script, targetPlatform, $arguments, source, $options) {
function ScriptFilter(
script,
targetPlatform,
$arguments,
source,
$options,
context,
) {
context.source = source;
context.env = env;
return {
name: 'Script Filter',
func: async (proxies) => {
@@ -961,7 +979,7 @@ function ScriptFilter(script, targetPlatform, $arguments, source, $options) {
$arguments,
$options,
);
output = filter(proxies, targetPlatform, { source, ...env });
output = filter(proxies, targetPlatform, context);
})();
return output;
},
@@ -970,7 +988,7 @@ function ScriptFilter(script, targetPlatform, $arguments, source, $options) {
await (async function () {
const filter = createDynamicFunction(
'filter',
`async function filter(input = []) {
`async function filter(input = [], targetPlatform, context) {
let proxies = input
let list = []
const fn = async ($server) => {
@@ -984,7 +1002,7 @@ function ScriptFilter(script, targetPlatform, $arguments, source, $options) {
$arguments,
$options,
);
output = filter(proxies, targetPlatform, { source, ...env });
output = filter(proxies, targetPlatform, context);
})();
return output;
},
+3 -1
View File
@@ -257,7 +257,9 @@ function operator(proxies = [], targetPlatform, context) {
// 可参考:
// 1. https://t.me/zhetengsha/948
// context 为传入的上下文
// context 为传入的上下文, 可在多个脚本中共享使用
// 其中 env 为 环境信息, 包含运行版本和其他后端信息
// 其中 source 为 订阅和组合订阅的数据, 有三种情况, 按需判断 (若只需要取订阅/组合订阅名称 直接用 `_subName` `_subDisplayName` `_collectionName` `_collectionDisplayName` 即可)
// 若存在 `source._collection` 且 `source._collection.subscriptions` 中的 key 在 `source` 上也存在, 说明输出结果为组合订阅, 但是脚本设置在单条订阅上