docs/docs/rules/jsPrepend.md
在现有响应内容体前面插入指定内容(仅对响应类型 content-type 包含 javascript,且包含响应内容体的状态码(如 200/500 等)有才效)
⚠️ 注意:204、304 等无响应内容体的请求不受影响
pattern jsPrepend://value [filters...]
| 参数 | 描述 | 详细文档 |
|---|---|---|
| pattern | 匹配请求 URL 的表达式 | 匹配模式文档 |
| value | 文本或二进制内容,支持以下类型: | |
| • 目录/文件路径 | ||
| • 远程 URL | ||
| • 内联/内嵌/Values内容 | 操作指令文档 | |
| filters | 可选过滤器,支持匹配: | |
| • 请求URL/方法/头部/内容 | ||
| • 响应状态码/头部 | 过滤器文档 |
www.example.com/path1 jsPrepend://(Hello) file://(-test-)
www.example.com/path2 jsPrepend://(Hello) file://(-test-) resType://js
www.example.com/path3 jsPrepend://(Hello) file://(-test-) resType://css
https://www.example.com/path1/to 响应内容变成
<!DOCTYPE html>
<script>Hello</script>-test-
https://www.example.com/path2/to 响应内容变成 Hello-test-https://www.example.com/path3/to 响应内容变成 -test-``` body.txt
Hello world.
```
www.example.com/path1 jsPrepend://{body.txt} file://(-test-)
www.example.com/path2 jsPrepend://{body.txt} file://(-test-) resType://js
www.example.com/path3 jsPrepend://{body.txt}) file://(-test-) resType://css
https://www.example.com/path1/to 响应内容变成
<!DOCTYPE html>
<script>Hello world.</script>-test-
https://www.example.com/path2/to 响应内容变成 Hello world.-test-https://www.example.com/path3/to 响应内容变成 -test-www.example.com/path1 jsPrepend:///User/xxx/test.js
www.example.com/path2 jsPrepend://https://www.xxx.com/xxx/params.js
# 通过编辑临时文件
www.example.com/path3 jsPrepend://temp/blank.js
<script> 标签属性通过 jsPrepend 注入到 HTML 页面的脚本,Whistle 会自动为其包裹 <script> 标签。若需要为该标签设置额外的属性,如 nomodule、module、defer、async、crossorigin 等,可以使用 lineProps 参数进行配置。
www.example.com/path1 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://nomodule
www.example.com/path2 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://module
www.example.com/path3 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://defer
www.example.com/path4 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://async
www.example.com/path5 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://crossorigin
| 属性 | 用途说明 | 配置示例 |
|---|---|---|
nomodule | 传统浏览器中执行,不支持 ES 模块的浏览器会运行此脚本 | lineProps://nomodule |
module | 声明为 ES 模块,支持模块化导入 | lineProps://module |
defer | 异步加载,在文档解析完成后执行 | lineProps://defer |
async | 异步加载,下载完成后立即执行 | lineProps://async |
crossorigin | 启用跨域资源共享(CORS)模式 | lineProps://crossorigin |
Prepend To Body):resPrependPrepend HTML To Body,响应类型必须为 text/html):htmlPrependPrepend CSS To Body,响应类型必须为 text/html 或 text/css):cssPrependPrepend JS To Body,响应类型必须为 text/html、text/css 或 application/javascript):jsPrependReplace Body):resBodyReplace Body,响应类型必须为 text/html):htmlBodyReplace Body,响应类型必须为 text/html 或 text/css):cssBodyReplace Body,响应类型必须为 text/html、text/css 或 application/javascript):jsBodyAppend To Body):resAppendAppend HTML To Body,响应类型必须为 text/html):htmlAppendAppend CSS To Body,响应类型必须为 text/html 或 text/css):cssAppendAppend JS To Body,响应类型必须为 text/html、text/css 或 application/javascript):jsAppendModify Body Text):resReplaceModify Form/JSON):resMergeDelete Form/JSON):delete://resBody.xxx