Skip to main content
This page shows JavaScript overrides as needed. Each example contains expected results or failing behavior.

Modify scalar fields

修改端口.js
修改端口 diff.js

Modify according to conditions

条件修改.js
When mode is rule:
When the conditions are not met, the script returns the original object and no diff is generated.

Add object field

添加 DNS 字段.js
添加 DNS 字段 diff.yaml

Use deepMerge to add rules

添加规则.js
添加规则 diff.yaml
JavaScript does not automatically move MATCH like YAML does. If the original list didn’t put MATCH at the end, the script won’t fix it for you.

Replace object or array

替换 DNS.js
替换 DNS diff.yaml

Filter proxy

过滤代理.js
过滤代理 diff.yaml
If profile.proxies is not an array, the script uses an empty array and ends up with proxies: [].

Modify naming policy group

修改策略组.js
修改策略组 diff.yaml
If PROXY is not found, the script will not create a new policy group and will not report an error.

Read remote YAML

远程 YAML.js
Remote return:
Expected diff:
远程 YAML 结果 diff.yaml
Network failure, HTTPS only support, corrupted YAML content, or incomplete Promise will cause the script to fail.

Read remote JSON

远程 JSON.js
If payload.port is not a number, the script retains the original mixed-port.

Request header and request body

POST 请求.js
The object request body is converted to a JSON string before being sent.

Logs and Exceptions

记录并抛错.js
On failure:
  • The current override writes [exception] 脚本执行失败.
  • Subsequent overwrites will not proceed.
  • Normal configuration will return script errors and file paths.
  • Encrypted configuration does not expose configuration content and paths in errors or logs.

Return error value

返回数组.js
Expected results:
缺少 main.js
Expected results:

Multiple JavaScript overrides

Files are executed in binding order, with subsequent scripts receiving the return value of the previous script:
第一个脚本.js
第二个脚本.js
JavaScript 覆写链结果 diff.yaml
When the second script lacks main, the function of the first script will not be reused, but will fail directly.
Last modified on August 13, 2026