From 44d03973254bf9db5da52031789b834b289fc302 Mon Sep 17 00:00:00 2001 From: Shawn <45581750+KOP-XIAO@users.noreply.github.com> Date: Fri, 13 May 2022 20:54:23 +0800 Subject: [PATCH] update --- Scripts/switch-check-disneyplus.js | 105 ++++++++++++++++++++++----- Scripts/switch-check-google.js | 109 +++++++++++++++++++++++------ Scripts/switch-check-nf.js | 100 +++++++++++++++++++++----- Scripts/switch-check-ytb.js | 91 ++++++++++++++++++++---- 4 files changed, 333 insertions(+), 72 deletions(-) diff --git a/Scripts/switch-check-disneyplus.js b/Scripts/switch-check-disneyplus.js index 2d26869..976f315 100644 --- a/Scripts/switch-check-disneyplus.js +++ b/Scripts/switch-check-disneyplus.js @@ -41,11 +41,13 @@ const message = { }; var output=[] -var OKList=["完整解锁节点 ➟ "] +var OKList=[] var ResList=["即将登陆节点 ➟ "] var NoList=["不支持节点 ➟ "] var timeoutList=["检测超时节点 ➟ "] var pflag=1 //是否是策略,或者简单节点 +var sign=0 //是否停止 + $configuration.sendMessage(message).then(resolve => { if (resolve.error) { @@ -53,11 +55,18 @@ $configuration.sendMessage(message).then(resolve => { $done() } if (resolve.ret) { - //$notify(JSON.stringify(resolve.ret)) output=JSON.stringify(resolve.ret[message.content])? JSON.parse(JSON.stringify(resolve.ret[message.content]["candidates"])) : [$environment.params] pflag = JSON.stringify(resolve.ret[message.content])? pflag:0 console.log("Disneyᐩ 检测&切换") console.log("节点or策略组:"+pflag) + console.log(JSON.stringify(resolve.ret)) + if (pflag==1) { + console.log("节点数量:"+resolve.ret[$environment.params]["candidates"].length) + if(resolve.ret[$environment.params]["candidates"].length==0) { + $done({"title":"Disneyᐩ 检测&切换","htmlMessage":`


😭 无有效节点`}); + } + } + //$notify(typeof(output),output) Check() //$done({"title":"策略内容","message":output}) @@ -68,6 +77,10 @@ $configuration.sendMessage(message).then(resolve => { $done(); }); +function Len(cnt) { + return cnt.length-1 +} + function Check() { var relay = 2000; for ( var i=0;i < output.length;i++) { @@ -90,9 +103,60 @@ function Check() { } console.log(output.length+":"+relay) setTimeout(() => { - const dict = { [policy] : OKList[1].split(": 支持 ")[0]}; - if(OKList[1]) { - console.log("选定支持节点:"+OKList[1]) + console.log("⛳️ 共计 "+OKList.length+" 个:支持节点 ➟ "+ OKList) + console.log("🏠 共计 "+Len(NoList)+" 个:"+NoList) + console.log("🕹 共计 "+Len(timeoutList)+" 个:"+timeoutList) + sign = 1 + if (OKList[0] && pflag==1) { //有支持节点、且为策略组才操作 + console.log("开始排序") + ReOrder(OKList) + } else if (!OKList[0]){ //不支持 + content = pflag==0 ? `


😭 该节点不支持Disneyᐩ

👇

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

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

该策略组内未找到支持 Disneyᐩ 的节点" + "

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

` + $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content}) + } else if (OKList[0]){ //支持, 但为节点 + content = `


🎉 该节点支持 Disneyᐩ ➟` + OKList[0].split(": 支持 ")[1]+`

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` + $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content}) + } + }, relay) + +} + + + +//选择最优延迟节点 +function ReOrder(cnt) { + const array = cnt//; + const messageURL = { + action: "url_latency_benchmark", + content: array.map(item=>item.split(": 支持 ")[0]) +}; + $configuration.sendMessage(messageURL).then(resolve => { + if (resolve.error) { + console.log(resolve.error); + } + if (resolve.ret) { + let output=JSON.stringify(resolve.ret); + //console.log("节点延迟:"+output); + //排序 + //console.log("排序前: "+ array) + if(array){ + try { + array.sort(function (a,b) { + //console.log(a+" VS "+b) + a=a.split(": 支持 ")[0] + b=b.split(": 支持 ")[0] + return (resolve.ret[a][1]!=-1 && resolve.ret[b][1] !=-1)? resolve.ret[a][1]-resolve.ret[b][1] : resolve.ret[b][1] + }) + } catch (err) { + console.log(err) + } + } + console.log("排序后: "+array) + let Ping =resolve.ret[array[0].split(": 支持 ")[0]] + const dict = { [policy] : array[0].split(": 支持 ")[0]}; + if(array[0]) { + console.log("选定支持 Disneyᐩ 节点:"+array[0].split(": 支持 ")[0]+"延迟数据为 👉"+Ping) + Ping = " ⚡️ 节点延迟 ➟ 「 "+Ping + " 」 " } const mes1 = { action: "set_policy_state", @@ -101,31 +165,31 @@ function Check() { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && OKList[1]? `

` + "
⟦ "+$environment.params+ " ⟧

🎉 该节点支持 Disneyᐩ ➟" + OKList[1].split(": 支持 ")[1]+ `

` : `

` + "
⟦ "+$environment.params+ " ⟧

⚠️ 该节点不支持 Disneyᐩ " + `

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

` + "
⟦ "+$environment.params+ " ⟧

🎉 该节点支持 Disneyᐩ ➟" + array[0].split(": 支持 ")[1]+ `

` : `

` + "
⟦ "+$environment.params+ " ⟧

⚠️ 该节点不支持 Disneyᐩ " + `

` content =pflag==0 && ResList[1]? `

` + "
⟦ "+$environment.params+ " ⟧

🚦 即将登陆节点所在地区 ➟" + ResList[1].split("登陆 ")[1]+`

` : content - content = pflag!=0 && !OKList[1]? `

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

该策略组内未找到支持 Disneyᐩ 的节点" + "

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

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

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

该策略组内未找到支持 Disneyᐩ 的节点" + "

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

` : content + console.log(content) $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content}) } if (resolve.ret) { - console.log("已经切换至支持Disneyᐩ"+OKList[1].split(": 支持 ")[1]+"的路线 ➟ "+OKList[1].split(": 支持 ")[0]) - content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至支持"+OKList[1].split(": 支持 ")[1]+"的路线

👇

⟦ "+OKList[1].split(": 支持 ")[0]+ " ⟧" + "

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

` + console.log("已经切换至支持 Disneyᐩ"+array[0].split(": 支持 ")[1]+"的路线 ➟ "+array[0].split(": 支持 ")[0]) + content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至支持 Disneyᐩ "+array[0].split(": 支持 ")[1]+"中延迟最优的路线

👇

⟦ "+array[0].split(": 支持 ")[0]+ " ⟧" + "

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

` $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content }) } }, reject => { $done(); - }); - - - }, relay) - + }); + } + //$done(); +}, reject => { + // Normally will never happen. + $done(); +}); } - - - async function testDisneyPlus(pname) { try { let { region, cnbl } = await Promise.race([testHomePage(pname), timeout(7000)]) @@ -141,21 +205,23 @@ async function testDisneyPlus(pname) { region = countryCode ?? region // 即将登陆 + if (sign==0) { if (inSupportedLocation === false || inSupportedLocation === 'false') { ResList.push(pname+": 即将登陆 「"+region+"」") //coming console.log(pname+": 即将登陆 「"+region+"」") return { region, status: STATUS_COMING } } else { // 支持解锁 + OKList.push(pname+": 支持 「"+region+"」") console.log(pname+": 支持 「"+region+"」") return { region, status: STATUS_AVAILABLE } } - + } // sign } catch (error) { //console.log(pname+": 检测错误"+error) //console.log("error:"+error) - + if (sign==0) { // 不支持解锁 if (error === 'Not Available') { NoList.push(pname) @@ -171,6 +237,7 @@ async function testDisneyPlus(pname) { } return { status: STATUS_ERROR } + } } } diff --git a/Scripts/switch-check-google.js b/Scripts/switch-check-google.js index 46b9af4..cfc3c05 100644 --- a/Scripts/switch-check-google.js +++ b/Scripts/switch-check-google.js @@ -20,10 +20,11 @@ const message = { }; var output=[] -var OKList=["未被送中节点 ➟ "] +var OKList=[] var NoList=["已被送中节点 ➟ "] var ErrorList=["检测出错节点 ➟ "] var pflag=1 //是否是策略,或者简单节点 +var sign=0 //是否停止 $configuration.sendMessage(message).then(resolve => { if (resolve.error) { @@ -31,26 +32,38 @@ $configuration.sendMessage(message).then(resolve => { $done() } if (resolve.ret) { - //$notify(JSON.stringify(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] 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) + + if(resolve.ret[$environment.params]["candidates"].length==0) { + $done({"title":"Google 送中检测","htmlMessage":`


😭 无有效节点`}); + } + } + //$notify(typeof(output),output) Check() //$done({"title":"策略内容","message":output}) } - //$done();| }, reject => { // Normally will never happen. $done(); }); +function Len(cnt) { + return cnt.length-1 +} + function Check() { var relay = 2000; for ( var i=0;i < output.length;i++) { testGoogle(output[i]) - } + } if (output.length<=5) { relay = 2000 } else if (output.length<10) { @@ -64,12 +77,55 @@ function Check() { } console.log(output.length+":"+relay) setTimeout(() => { - console.log(OKList) - console.log(NoList) - console.log(ErrorList) - const dict = { [policy] : OKList[1]}; - if(OKList[1]) { - console.log("选定未被送中节点:"+OKList[1]) + console.log("⛳️ 共计 "+OKList.length+" 个:未送中节点 ➟ "+ OKList) + console.log("🏠 共计 "+Len(NoList)+" 个:"+NoList) + console.log("🕹 共计 "+Len(ErrorList)+" 个:"+ErrorList) + sign=1 + if (OKList[0] && pflag==1) { //有支持节点、且为策略组才操作 + ReOrder(OKList) + } else if (!OKList[0]){ //不支持 + content =pflag==0 ? `


😭 该节点已被 Google 送中

👇

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

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

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

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

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


🎉 该节点未被 Google 送中

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` + $done({"title":"Google 送中检测&切换", "htmlMessage": content}) + } + }, relay) + +} + +//选择最优延迟节点 +function ReOrder(cnt) { + const array = cnt; + const messageURL = { + action: "url_latency_benchmark", + content: array +}; + $configuration.sendMessage(messageURL).then(resolve => { + if (resolve.error) { + console.log(resolve.error); + } + if (resolve.ret) { + let output=JSON.stringify(resolve.ret); + console.log("节点延迟:"+output); + //排序 + console.log("排序前: "+ array) + if(array){ + try { + array.sort(function (a,b) { + //console.log(a+" VS "+b) + return (resolve.ret[a][1]!=-1 && resolve.ret[b][1] !=-1)? resolve.ret[a][1]-resolve.ret[b][1] : resolve.ret[b][1] + }) + } catch (err) { + console.log(err) + } + } + console.log("排序后: "+array) + let Ping =resolve.ret[array[0]] + const dict = { [policy] : array[0]}; + if(array[0]) { + console.log("选定未被送中节点:"+array[0]+"延迟数据为 👉"+Ping) + Ping = " ⚡️ 节点延迟 ➟ 「 "+Ping + " 」 " } const mes1 = { action: "set_policy_state", @@ -78,27 +134,28 @@ function Check() { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && OKList[1]? `


🎉 该节点未被 Google 送中

👇

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


😭 该节点已被 Google 送中

👇

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

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

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

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

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


🎉 该节点未被 Google 送中

👇

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


😭 该节点已被 Google 送中

👇

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

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

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

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

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

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

👇

⟦ "+OKList[1]+ " ⟧" + "

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

` + console.log("已经切换至未被 Google 送中 的路线中延迟最优节点 ➟ "+array[0]) + content = `

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

👇

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

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

` $done({"title":"Google 送中检测&切换", "htmlMessage": content }) } }, reject => { $done(); }); - - }, relay) - + } + //$done(); +}, reject => { + // Normally will never happen. + $done(); +}); } - - function testGoogle(pname) { return new Promise((resolve, reject) => { const url = `https://www.google.com/maps/timeline`; @@ -119,28 +176,34 @@ function testGoogle(pname) { headers: headers, body: body, opts: opts, - timeout: 3000 + //timeout: 3000 }; $task.fetch(myRequest).then(response => { let sCode = response.statusCode hmessage = "该节点未被送中" //console.log(pname+sCode); + if (sign==0) { if (sCode == 400) { NoList.push(pname) - console.log(pname + ": 该节点已被送中") + console.log(pname + ": 该节点已被送中 ->" +sCode) resolve("YES") return } else { - OKList.push(pname) - console.log(pname + ": 该节点未被送中") + OKList.push(pname)//结束前推送 + console.log(pname + ": 该节点未被送中 ->" +sCode) resolve("No") return } + } else { + return + } }, reason => { + if (sign==0) { ErrorList.push(pname) console.log(pname + ": 该节点检测失败") reject("Error") + } return }); }) diff --git a/Scripts/switch-check-nf.js b/Scripts/switch-check-nf.js index 5e4617f..7354599 100644 --- a/Scripts/switch-check-nf.js +++ b/Scripts/switch-check-nf.js @@ -7,7 +7,7 @@ For Quantumult-X 598+ ONLY!! [task_local] -event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-nf.js, tag=Netflix 切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Netflix_Letter.png, enabled=true +event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/sswitch-check-nf.js, tag=Netflix 切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Netflix_Letter.png, enabled=true ps. 简单粗暴的 UI-Interaction 版本。无数据持久化、粗暴延迟等待。完美主义建议使用 Helge大佬的boxjs版本 https://t.me/QuanXNews/193 @@ -28,11 +28,13 @@ const message = { }; var output=[] -var OKList=["完整解锁节点 ➟ "] +var OKList=[] var ResList=["仅支持自制剧节点 ➟ "] var NoList=["不支持节点 ➟ "] var timeoutList=["检测超时节点 ➟ "] var pflag=1 //是否是策略,或者简单节点 +var sign = 0 // 是否结束标志 + $configuration.sendMessage(message).then(resolve => { if (resolve.error) { @@ -40,11 +42,16 @@ $configuration.sendMessage(message).then(resolve => { $done() } if (resolve.ret) { - //$notify(JSON.stringify(resolve.ret)) output=JSON.stringify(resolve.ret[message.content])? JSON.parse(JSON.stringify(resolve.ret[message.content]["candidates"])) : [$environment.params] pflag = JSON.stringify(resolve.ret[message.content])? pflag:0 console.log("Netflix 支持检测") console.log("节点or策略组:"+pflag) + if (pflag==1) { + console.log("节点数量:"+resolve.ret[$environment.params]["candidates"].length) + if(resolve.ret[$environment.params]["candidates"].length==0) { + $done({"title":"Netflix 检测&切换","htmlMessage":`


😭 无有效节点`}); + } + } //$notify(typeof(output),output) Check() //$done({"title":"策略内容","message":output}) @@ -55,6 +62,10 @@ $configuration.sendMessage(message).then(resolve => { $done(); }); +function Len(cnt) { + return cnt.length-1 +} + function Check() { var relay = 2000; for ( var i=0;i < output.length;i++) { @@ -77,9 +88,57 @@ function Check() { } console.log(output.length+":"+relay) setTimeout(() => { - const dict = { [policy] : OKList[1]}; - if(OKList[1]) { - console.log("选定支持节点:"+OKList[1]) + console.log("⛳️ 共计 "+OKList.length+" 个:完整支持节点 ➟"+ OKList) + console.log("🏠 共计 "+Len(NoList)+" 个:"+NoList) + console.log("🕹 共计 "+Len(timeoutList)+" 个:"+timeoutList) + sign=1 + if (OKList[0] && pflag==1) { + console.log("开始排序") + ReOrder(OKList) + } else if (!OKList[0]){ //不支持 + content =pflag==0 ? `


😭 该节点未完整支持 Netflix

👇

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

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

该策略组内未找到完整支持 Netflix 的节点" + "

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

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


🎉 该节点完整支持 Netflix

👇

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


🎉 该节点支持 Disneyᐩ ➟` + OKList[0].split(": 支持 ")[1]+`

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` + $done({"title":"Netflix 检测&切换", "htmlMessage": content}) + } + }, relay) + +} + +//选择最优延迟节点 +function ReOrder(cnt) { + const array = cnt; + const messageURL = { + action: "url_latency_benchmark", + content: array + }; + $configuration.sendMessage(messageURL).then(resolve => { + if (resolve.error) { + console.log(resolve.error); + } + if (resolve.ret) { + let output=JSON.stringify(resolve.ret); + console.log("节点延迟:"+output); + //排序 + console.log("排序前: "+ array) + if(array){ + try { + array.sort(function (a,b) { + //console.log(a+" VS "+b) + return (resolve.ret[a][1]!=-1 && resolve.ret[b][1] !=-1)? resolve.ret[a][1]-resolve.ret[b][1] : resolve.ret[b][1] + }) + } catch (err) { + console.log(err) + } + } + console.log("排序后: "+array) + let Ping =resolve.ret[array[0]] + const dict = { [policy] : array[0]}; + if(array[0]) { + console.log("选定完整支持节点:"+array[0]+"延迟数据为 👉"+Ping) + Ping = " ⚡️ 节点延迟 ➟ 「 "+Ping + " 」 " } const mes1 = { action: "set_policy_state", @@ -88,28 +147,30 @@ function Check() { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && OKList[1]? `

` + "
⟦ "+$environment.params+ " ⟧

🎉 该节点完整支持 Netflix" + `

` : `

` + "
⟦ "+$environment.params+ " ⟧

⚠️ 该节点不支持 Netflix" + `

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

` + "
⟦ "+$environment.params+ " ⟧

🎉 该节点完整支持 Netflix" + `

` : `

` + "
⟦ "+$environment.params+ " ⟧

⚠️ 该节点不支持 Netflix" + `

` + content =pflag==0 && ResList[1]? `

` + "
⟦ "+$environment.params+ " ⟧

🚦 该节点仅支持 Netflix 自制剧集" + `

` : content - content = pflag!=0 && !OKList[1]? `

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

该策略组内未找到完整支持 Netflix 的节点" + "

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

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

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

该策略组内未找到完整支持 Netflix 的节点" + "

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

` : content $done({"title":"Netflix 检测&切换", "htmlMessage": content}) } if (resolve.ret) { - console.log("已经切换至完整支持的路线 ➟ "+OKList[1]) - content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至完整支持的路线

👇

⟦ "+OKList[1]+ " ⟧" + "

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

` + console.log("已经切换至完整支持的路线 ➟ "+array[0]) + content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至完整支持的路线中延迟最优节点

👇

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

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

` $done({"title":"Netflix 检测&切换", "htmlMessage": content }) } }, reject => { $done(); }); - - }, relay) - + } + //$done(); +}, reject => { + // Normally will never happen. + $done(); +}); } - - function testNF(pname ) { return new Promise((resolve, reject) => { //console.log(pname) @@ -123,7 +184,7 @@ function testNF(pname ) { }, } $task.fetch(option).then (response => { - + if (sign==0) { if (response.statusCode === 404) { NoList.push(pname) console.log(pname+": "+"未支持") @@ -150,6 +211,13 @@ function testNF(pname ) { resolve(region) return } + } else { + console.log(pname+": 检测超时") + timeoutList.push(pname) + resolve("Erroe") + return + + } reject('Error') }) }) diff --git a/Scripts/switch-check-ytb.js b/Scripts/switch-check-ytb.js index 3e1f2eb..7a3af57 100644 --- a/Scripts/switch-check-ytb.js +++ b/Scripts/switch-check-ytb.js @@ -10,7 +10,7 @@ For Quantumult-X 598+ ONLY!! [task_local] -event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-ytb.js, tag=YouTube 切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/YouTube_Letter.png, enabled=true +event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/sswitch-check-ytb.js, tag=YouTube 切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/YouTube_Letter.png, enabled=true ps. 简单粗暴的 UI-Interaction 版本。无数据持久化、粗暴延迟等待。完美主义建议使用 Helge大佬的boxjs版本 https://t.me/QuanXNews/193 @@ -29,10 +29,11 @@ const message = { }; var output=[] -var OKList=["支持节点 ➟ "] +var OKList=[] var NoList=["不支持节点 ➟ "] var ErrorList=["检测出错节点 ➟ "] var pflag=1 //是否是策略,或者简单节点 +var sign=0 $configuration.sendMessage(message).then(resolve => { if (resolve.error) { @@ -45,6 +46,13 @@ $configuration.sendMessage(message).then(resolve => { pflag = JSON.stringify(resolve.ret[message.content])? pflag:0 console.log("YouTube Premium 检测") console.log("节点or策略组:"+pflag) + if (pflag==1) { + console.log("节点数量:"+resolve.ret[$environment.params]["candidates"].length) + if(resolve.ret[$environment.params]["candidates"].length==0) { + $done({"title":"YouTube Premium 检测","htmlMessage":`


😭 无有效节点`}); + } + } + //$notify(typeof(output),output) Check() //$done({"title":"策略内容","message":output}) @@ -55,6 +63,10 @@ $configuration.sendMessage(message).then(resolve => { $done(); }); +function Len(cnt) { + return cnt.length-1 +} + function Check() { var relay = 2000; for ( var i=0;i < output.length;i++) { @@ -73,9 +85,56 @@ function Check() { } console.log(output.length+":"+relay) setTimeout(() => { - const dict = { [policy] : OKList[1]}; - if(OKList[1]) { - console.log("选定支持节点:"+OKList[1]) + console.log("⛳️ 共计 "+OKList.length+" 个:支持节点 ➟ "+ OKList) + console.log("🏠 共计 "+Len(NoList)+" 个:"+NoList) + console.log("🕹 共计 "+Len(ErrorList)+" 个:"+ErrorList) + sign = 1 + if (OKList[0] && pflag==1) { //有支持节点、且为策略组才操作 + console.log("开始排序") + ReOrder(OKList) + } else if (!OKList[0]){ //不支持 + content =pflag==0 ? `


😭 该节点不支持 YouTube Premium

👇

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

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

该策略组内未找到支持 YouTube Premium 的节点" + "

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

` + $done({"title":"YouTube Premium 检测&切换", "htmlMessage": content}) + } else if (OKList[0]){ //支持, 但为节点 + content =`


🎉 该节点支持 YouTube Premium

👇

-------------------------
⟦ `+$environment.params+` ⟧
-------------------------
` + $done({"title":"YouTube Premium 检测&切换", "htmlMessage": content}) + } + }, relay) + +} + +//选择最优延迟节点 +function ReOrder(cnt) { + const array = cnt; + const messageURL = { + action: "url_latency_benchmark", + content: array +}; + $configuration.sendMessage(messageURL).then(resolve => { + if (resolve.error) { + console.log(resolve.error); + } + if (resolve.ret) { + let output=JSON.stringify(resolve.ret); + console.log("节点延迟:"+output); + //排序 + console.log("排序前: "+ array) + if(array){ + try { + array.sort(function (a,b) { + //console.log(a+" VS "+b) + return (resolve.ret[a][1]!=-1 && resolve.ret[b][1] !=-1)? resolve.ret[a][1]-resolve.ret[b][1] : resolve.ret[b][1] + }) + } catch (err) { + console.log(err) + } + } + console.log("排序后: "+array) + let Ping =resolve.ret[array[0]] + const dict = { [policy] : array[0]}; + if(array[0]) { + console.log("选定支持YouTube Premium:"+array[0]+"延迟数据为 👉"+Ping) + Ping = " ⚡️ 节点延迟 ➟ 「 "+Ping + " 」 " } const mes1 = { action: "set_policy_state", @@ -84,27 +143,28 @@ function Check() { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && OKList[1]? `

` + "
⟦ "+$environment.params+ " ⟧

🎉 该节点支持 YouTube Premium" + `

` : `

` + "
⟦ "+$environment.params+ " ⟧

⚠️ 该节点不支持 YouTube Premium" + `

` - content = pflag!=0 && !OKList[1]? `

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

该策略组内未找到支持 YouTube Premium 的节点" + "

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

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

` + "
⟦ "+$environment.params+ " ⟧

🎉 该节点支持 YouTube Premium" + `

` : `

` + "
⟦ "+$environment.params+ " ⟧

⚠️ 该节点不支持 YouTube Premium" + `

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

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

该策略组内未找到支持 YouTube Premium 的节点" + "

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

` : content $done({"title":"YouTube 检测&切换", "htmlMessage": content}) } if (resolve.ret) { - console.log("已经切换至支持 Premium 的路线 ➟ "+OKList[1]) - content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至支持Premium 的路线

👇

⟦ "+OKList[1]+ " ⟧" + "

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

` + console.log("已经切换至支持 Premium 的路线 ➟ "+array[0]) + content = `

` + "
⟦ "+$environment.params+ " ⟧ 已切换至支持Premium 的路线中延迟最优节点

👇

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

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

` $done({"title":"YouTube 检测&切换", "htmlMessage": content }) } }, reject => { $done(); }); - - }, relay) - + } + //$done(); +}, reject => { + // Normally will never happen. + $done(); +}); } - - function testYTB(pname) { return new Promise((resolve, reject) => { let opts = { policy : pname } @@ -120,6 +180,7 @@ function testYTB(pname) { $task.fetch(option).then(response=> { let data = response.body //console.log(response.statusCode) + if (sign==0) { if (response.statusCode !== 200) { console.log(pname+":检测出错") ErrorList.push(pname) @@ -147,6 +208,8 @@ function testYTB(pname) { console.log(pname+":支持"+region) OKList.push(pname) resolve(region) + } + reject('Error') }) }) }