[Script] 脚本
本节定义 HTTP 请求、HTTP 响应、定时和网络事件脚本。
语法
ini
[Script]
名称 = type=类型, script-path=来源, 选项=值只接受键值参数。名称必须非空且唯一,不得为 .、..,也不得包含 /、反斜杠或 NUL。未知参数被忽略。
公共字段
| 字段 | 取值与单位 | 默认值 | 行为与约束 |
|---|---|---|---|
type | http-request、http-response、cron、event | 无,必填 | 决定触发类型 |
script-path | 本地路径或 HTTP/HTTPS URL | 无,必填 | 脚本来源 |
script-update-interval | 无符号整数,秒 | 未设置 | 仅 HTTP 来源接受;未设置时不启用定时刷新 |
debug | true/yes/1、false/no/0 | false | 布尔值不区分大小写 |
timeout | 1–86400,秒 | 5 | 执行超时;0 和超出一天均解析失败 |
argument | 字符串 | 未设置 | 传入脚本的参数 |
engine | auto、quickjs、webview | auto | 不区分大小写;未知值按 auto;auto 对 HTTP 脚本使用 WebView,对 cron/event 使用 QuickJS |
触发字段
| 字段 | 适用类型 | 取值与单位 | 默认值与约束 |
|---|---|---|---|
pattern | http-request、http-response | URL 正则表达式 | 必填 |
requires-body | http-request、http-response | 同 debug 的布尔取值 | false;是否读取并提供 HTTP body |
max-size | http-request、http-response | 整数,字节 | 131072;任何负数表示不限,0 非法,正溢出饱和到 usize::MAX |
binary-body-mode | http-request、http-response | 同 debug 的布尔取值 | false;以二进制形式提供 body |
cronexp | cron | 五段或六段表达式 | 必填;解析器检查段数,接受成对单引号或双引号 |
event-name | event | network-changed | 必填;其他值解析失败 |
HTTP 脚本能否处理 HTTPS 取决于流量是否进入解密后的 HTTP 管道,相关配置见 MITM。
示例
ini
[Script]
Request = type=http-request, pattern=^http://example\.com/, script-path=./request.js
Timer = type=cron, cronexp="0 * * * *", script-path=./timer.js
Network = type=event, event-name=network-changed, script-path=./network.js