From 6e8f205f67925da1f5d7bbecbba6fef9657284ac Mon Sep 17 00:00:00 2001 From: Shawn <45581750+KOP-XIAO@users.noreply.github.com> Date: Tue, 5 Jul 2022 10:14:28 +0800 Subject: [PATCH] Update switch-check-google.js --- Scripts/switch-check-google.js | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Scripts/switch-check-google.js b/Scripts/switch-check-google.js index 804a418..09450c2 100644 --- a/Scripts/switch-check-google.js +++ b/Scripts/switch-check-google.js @@ -4,15 +4,33 @@ For Quantumult-X 598+ ONLY!! [task_local] +// UI 入口切换版本 event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-google.js, tag=Google Sifter, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Google_Search.png, enabled=true +// Cron 定时切换版本 +0 8 * * * https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-google.js, tag=Google Sifter, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Google_Search.png, enabled=true + + ps. 简单粗暴的 UI-Interaction 版本。无数据持久化、粗暴延迟等待。完美主义建议使用 Helge大佬的boxjs版本 https://t.me/QuanXNews/193 @XIAO_KOP **/ -var policy = $environment.params +//var policy = $environment.params +var cronsign = $environment.executeType == 0 || $environment.executeType == "0" || $environment.executeType == "-1"? "Y" : "N" +var policy = $environment.executeType == 0 || $environment.executeType == "0" || $environment.executeType == "-1"? GetPolicy($environment.sourcePath) : $environment.params +console.log(JSON.stringify($environment)) +console.log("策略组:"+policy) + +function GetPolicy(cnt) { + if (cnt && cnt.indexOf("#policy=") !=-1) { + return decodeURIComponent(cnt.split("#policy=")[1].trim()) + }else { + return "" + } +} + const message = { action: "get_customized_policy", content: policy @@ -33,15 +51,15 @@ $configuration.sendMessage(message).then(resolve => { } if (resolve.ret) { //console.log(JSON.stringify(resolve.ret)) - output=JSON.stringify(resolve.ret[message.content])? JSON.parse(JSON.stringify(resolve.ret[message.content]["candidates"])) : [$environment.params] + output=JSON.stringify(resolve.ret[message.content])? JSON.parse(JSON.stringify(resolve.ret[message.content]["candidates"])) : [policy] pflag = JSON.stringify(resolve.ret[message.content])? pflag:0 console.log("Google 送中检测 检测") console.log("节点or策略组:"+pflag) if (pflag==1) { - console.log("节点数量:"+resolve.ret[$environment.params]["candidates"].length) + console.log("节点数量:"+resolve.ret[policy]["candidates"].length) - if(resolve.ret[$environment.params]["candidates"].length==0) { + if(resolve.ret[policy]["candidates"].length==0) { $done({"title":"Google 送中检测","htmlMessage":`


😭 无有效节点`}); } } @@ -84,12 +102,12 @@ function Check() { if (OKList[0] && pflag==1) { //有支持节点、且为策略组才操作 ReOrder(OKList) } else if (!OKList[0]){ //不支持 - content =pflag==0 ? `


😭 该节点已被 Google 送中

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
`: `

` + "
⟦ "+$environment.params+ " ⟧ ⚠️ 切换失败

该策略组内未找到未被 Google 送中 的节点" + "

-----------------------------
检测详情请查看JS脚本记录
-----------------------------
"+`

` + content =pflag==0 ? `


😭 该节点已被 Google 送中

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
`: `

` + "
⟦ "+policy+ " ⟧ ⚠️ 切换失败

该策略组内未找到未被 Google 送中 的节点" + "

-----------------------------
检测详情请查看JS脚本记录
-----------------------------
"+`

` //为节点且检测超时/出错 - content = pflag==0 && Len(NoList)==0 ? content = `


⚠️ 该节点 Google 送中检测失败

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
`: content + content = pflag==0 && Len(NoList)==0 ? content = `


⚠️ 该节点 Google 送中检测失败

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
`: content $done({"title":"Google 送中检测&切换", "htmlMessage": content}) } else if (OKList[0]){ //支持, 但为节点 - content = `


🎉 该节点未被 Google 送中

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` + content = `


🎉 该节点未被 Google 送中

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` $done({"title":"Google 送中检测&切换", "htmlMessage": content}) } }, relay) @@ -136,13 +154,14 @@ function ReOrder(cnt) { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && array[0]? `


🎉 该节点未被 Google 送中

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` : `


😭 该节点已被 Google 送中

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` - content = pflag!=0 && !array[0]? `

` + "
⟦ "+$environment.params+ " ⟧ ⚠️ 切换失败

该策略组内未找到未被 Google 送中 的节点" + "

-----------------------------
检测详情请查看JS脚本记录
-----------------------------
"+`

` : content + content =pflag==0 && array[0]? `


🎉 该节点未被 Google 送中

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` : `


😭 该节点已被 Google 送中

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` + content = pflag!=0 && !array[0]? `

` + "
⟦ "+policy+ " ⟧ ⚠️ 切换失败

该策略组内未找到未被 Google 送中 的节点" + "

-----------------------------
检测详情请查看JS脚本记录
-----------------------------
"+`

` : content $done({"title":"Google 送中检测&切换", "htmlMessage": content}) } if (resolve.ret) { console.log("已经切换至未被 Google 送中 的路线中延迟最优节点 ➟ "+array[0]) - content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至未被Google 送中延迟最优路线

👇

⟦ "+array[0]+ " ⟧" + "

"+Ping+"
-----------------------------
检测详情请查看JS脚本记录
-----------------------------
"+`

` + if (cronsign == "Y") { $notify("🐸 Google 定时送中检测&切换", "🎉 已切换至未被送中的最优延迟线路👇", array[0] +"\n 👉 "+Ping)} + content = `

` + "
⟦ "+policy+ " ⟧ 已切换至未被Google 送中延迟最优路线

👇

⟦ "+array[0]+ " ⟧" + "

"+Ping+"
-----------------------------
检测详情请查看JS脚本记录
-----------------------------
"+`

` $done({"title":"Google 送中检测&切换", "htmlMessage": content }) } }, reject => {