Are you an LLM? You can read better optimized documentation at /zh-TW\document\script.md for this page in Markdown format
腳本型別
http-request
在獲得一個http請求時觸發,可配置的引數:
requires-body = true代表是否獲取http請求的bodybinary-body-mode = true代表獲取http請求的body型別為Uint8Arrayargument = "name=loon&version=2.1.0"腳本中可以透過變數$argument獲取,為了能夠準確解析到引數,請將引數用雙引號包裹
配置語法
http-request ^https?:\/\/(www.)?(example)\.com script-path=localscript.js,tag = requestScript,requires-body = true,timeout = 10,binary-body-mode = false,argument = "1234",enable=true腳本預設執行超時時間10s,此類腳本中可以使用如下變數,
- 所有Script API
$request: 一個http請求資訊$request.url: String型別,請求URL$request.method: String型別,請求方法$request.headers: js物件,請求頭$request.body: String或者Uint8Array型別,當requires-body = true時才有值,請求的body
$response: undefined$done()方法引數說明:$done(): 不傳任何引數,表示放棄該請求,請求連線會直接斷開$done({}): 空js物件,請求繼續,任何請求引數不會有任何變化$done({url:"https://new.example.com/",headers:{},node:"HK"}): url引數替換原來的url,headers替換原來的request headers,node參數列示該請求後續用指定的策略組(也可以是節點名稱)進行請求(build 534版本開始適用)$done({response:{ status:200, headers:{}, body:"" }}): 直接向該請求返回一個假的響應,body型別可以是String或者Uint8Array,如果body的長度大於0,會自動計算headers中的content-length,content-encoding也會根據body型別自動生成注意 當$done()引數的物件中的request不包含headers或者body時,表示使用原請求的headers和body,如果要清除原請求的body時,引數的body=""即可,清除原headers的話headers={}
http-response
在獲得一個http響應時觸發,引數requires-body = true代表是否獲取http響應的body
requires-body = true代表是否獲取http請求的bodybinary-body-mode = true代表獲取http請求的body型別為Uint8Arrayargument = "name=loon&version=2.1.0"腳本中可以透過變數$argument獲取,為了能夠準確解析到引數,請將引數用雙引號包裹
配置語法
http-response ^https?:\/\/(www.)?(example)\.com script-path=https://example.com/loon.js,timeout=10,requires-body = true,tag = responseScript,enable=true,timeout = 10,binary-body-mode = false,argument = "1234",enable=true腳本預設執行超時時間10s,此類腳本中可以使用如下變數:
- 所有Script API
$request: http請求資訊$request.url: String型別,請求URL$request.method: String型別,請求方法$request.headers: js物件,請求頭$request.body: String或者Uint8Array型別,如果請求帶有body,此引數才有值
$response: http響應資訊$response.status: 響應狀態$response.headers: 響應頭$response.body: String或者Uint8Array型別,如果響應帶有body,並且requires-body = true時此引數才有值
$done()方法引數說明:$done(): 不傳任何引數,表示放棄該請求,請求連線會直接斷開$done({}): 空js物件,請求繼續,任何請求引數不會有任何變化$done({ status:200, headers:{}, body:"" }): 直接向該請求返回一個假的響應,body型別可以是String或者Uint8Array,如果body的長度大於0,會自動計算headers中的content-length,content-encoding也會根據body型別自動生成注意 當$done()引數的物件中的response不包含headers或者body時,表示使用原響應的headers和body,如果要清除原請求的body時,引數的body=""即可,清除原headers的話headers={}
cron
- 根據設定的cron表示式定時觸發腳本
- "** ** *" : 分 時 日 月 周
- "** ** **" :秒 分 時 日 月 周
配置語法
cron "0 8 * * *" script-path=cron.js,tag = cronScript,enable=true,timeout = 300,argument = "1234",enable=true腳本預設執行超時時間200s,此類腳本中可以使用如下變數:
network-changed
當網路環境發生變化時會呼叫此型別腳本,如果有多個這種型別的腳本,只會呼叫配置檔案中的第一個
配置語法
network-changed script-path=https://raw.githubusercontent.com/Loon0x00/LoonExampleConfig/master/Script/netChanged.js,tag=changeModel,timeout = 300,argument = "1234",enable=true腳本預設執行超時時間200s,此類腳本中可以使用如下變數:
generic
以節點、策略組、規則等配置為引數的腳本,需要在app內部頁面手動進行觸發,不會主動觸發
配置語法
generic script-path=https://raw.githubusercontent.com/Loon0x00/LoonExampleConfig/master/Script/generic_example.js,tag=GeoLocation,timeout=10,img-url=location.fill.viewfinder.system,timeout = 300,argument = "1234",enable=true此類腳本中可以使用如下變數
