From 345d10644c3248468f38d9ab95459341a8eb10bd Mon Sep 17 00:00:00 2001 From: Shawn <45581750+KOP-XIAO@users.noreply.github.com> Date: Wed, 6 Jul 2022 15:40:21 +0800 Subject: [PATCH] update --- Scripts/Cron-Switch.json | 10 ++ Scripts/switch-check-disneyplus.js | 29 ++-- Scripts/switch-check-nf.js | 32 ++-- Scripts/switch-check-ytb-url-cron.js | 230 --------------------------- Scripts/switch-check-ytb.js | 45 ++++-- 5 files changed, 79 insertions(+), 267 deletions(-) create mode 100644 Scripts/Cron-Switch.json delete mode 100644 Scripts/switch-check-ytb-url-cron.js diff --git a/Scripts/Cron-Switch.json b/Scripts/Cron-Switch.json new file mode 100644 index 0000000..7e5e92c --- /dev/null +++ b/Scripts/Cron-Switch.json @@ -0,0 +1,10 @@ +{ + "name":"流媒体定时切换合集 @Shawn", + "description":"Crontab Script Gallery by Shawn", + "task":[ + "0 8 * * * 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", + "1 8 * * * 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", + "2 8 * * * https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-disneyplus.js, tag=Disneyᐩ 定时切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Disney.png, enabled=true", + "3 8 * * * https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-google.js, tag=Google 送中定时切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Google.png, enabled=true", + ] +} \ No newline at end of file diff --git a/Scripts/switch-check-disneyplus.js b/Scripts/switch-check-disneyplus.js index 976f315..26906a3 100644 --- a/Scripts/switch-check-disneyplus.js +++ b/Scripts/switch-check-disneyplus.js @@ -7,8 +7,12 @@ For Quantumult-X 598+ ONLY!! [task_local] +// UI 查询版本 event-interaction https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-disneyplus.js, tag=Disneyᐩ 检测&切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Disney.png, enabled=true +//cron 版本 +0 8 * * * https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-disneyplus.js, tag=Disneyᐩ 检测&切换, img-url=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/Disney.png, enabled=true + ps. 简单粗暴的 UI-Interaction 版本。无数据持久化、粗暴延迟等待。完美主义建议使用 Helge大佬的boxjs版本 https://t.me/QuanXNews/193 @XIAO_KOP @@ -33,7 +37,11 @@ const STATUS_ERROR = -2 const link = { "media-url": "https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/img/southpark/7.png" } -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) + const message = { action: "get_customized_policy", content: policy @@ -55,14 +63,14 @@ $configuration.sendMessage(message).then(resolve => { $done() } if (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("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) { + console.log("节点数量:"+resolve.ret[policy]["candidates"].length) + if(resolve.ret[policy]["candidates"].length==0) { $done({"title":"Disneyᐩ 检测&切换","htmlMessage":`


😭 无有效节点`}); } } @@ -111,10 +119,10 @@ function Check() { console.log("开始排序") ReOrder(OKList) } else if (!OKList[0]){ //不支持 - content = pflag==0 ? `


😭 该节点不支持Disneyᐩ

👇

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

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

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

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

` + content = pflag==0 ? `


😭 该节点不支持Disneyᐩ

👇

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

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

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

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

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


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

👇

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


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

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content}) } }, relay) @@ -165,17 +173,18 @@ function ReOrder(cnt) { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && array[0]? `

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

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

` : `

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

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

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

` + "
⟦ "+policy+ " ⟧

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

` : `

` + "
⟦ "+policy+ " ⟧

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

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

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

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

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

` + "
⟦ "+policy+ " ⟧

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

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

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

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

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

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

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

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

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

` : content console.log(content) $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content}) } if (resolve.ret) { 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脚本记录
-----------------------------"+`

` + if (cronsign == "Y") { $notify("📺 Disneyᐩ 定时检测&切换", "🎉 已经切换至支持 Disneyᐩ 的最优延迟线路👇", array[0] +"\n 👉 "+Ping)} + content = `

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

👇

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

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

` $done({"title":"Disneyᐩ 检测&切换", "htmlMessage": content }) } }, reject => { diff --git a/Scripts/switch-check-nf.js b/Scripts/switch-check-nf.js index 7354599..52fd2c4 100644 --- a/Scripts/switch-check-nf.js +++ b/Scripts/switch-check-nf.js @@ -7,8 +7,12 @@ For Quantumult-X 598+ ONLY!! [task_local] +//UI 查询版本 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 +//cron 版本 +0 8 * * * 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 @XIAO_KOP @@ -20,7 +24,12 @@ const BASE_URL = 'https://www.netflix.com/title/' const FILM_ID = 81215567 const link = { "media-url": "https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/img/southpark/7.png" } const policy_name = "Netflix" //填入你的 netflix 策略组名 -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) + const message = { action: "get_customized_policy", content: policy @@ -42,13 +51,13 @@ $configuration.sendMessage(message).then(resolve => { $done() } if (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("Netflix 支持检测") console.log("节点or策略组:"+pflag) if (pflag==1) { - console.log("节点数量:"+resolve.ret[$environment.params]["candidates"].length) - if(resolve.ret[$environment.params]["candidates"].length==0) { + console.log("节点数量:"+resolve.ret[policy]["candidates"].length) + if(resolve.ret[policy]["candidates"].length==0) { $done({"title":"Netflix 检测&切换","htmlMessage":`


😭 无有效节点`}); } } @@ -96,11 +105,11 @@ function Check() { console.log("开始排序") ReOrder(OKList) } else if (!OKList[0]){ //不支持 - content =pflag==0 ? `


😭 该节点未完整支持 Netflix

👇

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

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

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

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

` + content =pflag==0 ? `


😭 该节点未完整支持 Netflix

👇

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

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

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

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

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


🎉 该节点完整支持 Netflix

👇

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


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

👇

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


🎉 该节点完整支持 Netflix

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` + //content = `


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

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` $done({"title":"Netflix 检测&切换", "htmlMessage": content}) } }, relay) @@ -147,15 +156,16 @@ function ReOrder(cnt) { $configuration.sendMessage(mes1).then(resolve => { if (resolve.error) { console.log(resolve.error); - content =pflag==0 && array[0]? `

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

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

` : `

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

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

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

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

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

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

` + "
⟦ "+policy+ " ⟧

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

` : `

` + "
⟦ "+policy+ " ⟧

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

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

` + "
⟦ "+policy+ " ⟧

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

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

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

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

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

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

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

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

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

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

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

👇

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

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

` + if (cronsign == "Y") { $notify("📺 Netflix 定时检测&切换", "🎉 已经切换至支持 Netflix 的最优延迟线路👇", array[0] +"\n 👉 "+Ping)} + content = `

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

👇

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

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

` $done({"title":"Netflix 检测&切换", "htmlMessage": content }) } }, reject => { diff --git a/Scripts/switch-check-ytb-url-cron.js b/Scripts/switch-check-ytb-url-cron.js deleted file mode 100644 index b20d84f..0000000 --- a/Scripts/switch-check-ytb-url-cron.js +++ /dev/null @@ -1,230 +0,0 @@ -/*** - -For Quantumult-X 598+ ONLY!! - -[task_local] - -// UI 查询版本 -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 - -// cron task 版本 -0 8 * * * https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-ytb-url-cron.js#policy=你的策略组, 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 - -@XIAO_KOP - -2022-07-04 - -**/ - -const BASE_URL = 'https://www.youtube.com/premium' - -const link = { "media-url": "https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/img/southpark/7.png" } -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 - -}; - -var output=[] -var OKList=[] -var NoList=["不支持节点 ➟ "] -var ErrorList=["检测出错节点 ➟ "] -var pflag=1 //是否是策略,或者简单节点 -var sign=0 - -$configuration.sendMessage(message).then(resolve => { - if (resolve.error) { - console.log(resolve.error); - $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"])) : [policy] - pflag = JSON.stringify(resolve.ret[message.content])? pflag:0 - console.log("YouTube Premium 检测") - console.log("节点or策略组:"+pflag) - if (pflag==1) { - console.log("节点数量:"+resolve.ret[policy]["candidates"].length) - if(resolve.ret[policy]["candidates"].length==0) { - $done({"title":"YouTube Premium 检测","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++) { - testYTB(output[i]) - } - if (output.length<=5) { - relay = 2000 - } else if (output.length<10) { - relay =4000 - } else if (output.length<15) { - relay =6000 - } else if (output.length<20) { - relay =8000 - } else { - relay =10000 - } - console.log(output.length+":"+relay) - setTimeout(() => { - 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

👇

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

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

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

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

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


🎉 该节点支持 YouTube Premium

👇

-------------------------
⟦ `+policy+` ⟧
-------------------------
` - $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", - content: dict - }; - $configuration.sendMessage(mes1).then(resolve => { - if (resolve.error) { - console.log(resolve.error); - content =pflag==0 && array[0]? `

` + "
⟦ "+policy+ " ⟧

🎉 该节点支持 YouTube Premium" + `

` : `

` + "
⟦ "+policy+ " ⟧

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

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

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

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

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

` : content - $done({"title":"YouTube 检测&切换", "htmlMessage": content}) - } - if (resolve.ret) { - console.log("已经切换至支持 Premium 的路线 ➟ "+array[0]) - if (cronsign == "Y") { $notify("📺 YouTube Premium 定时检测&切换", "🎉 已经切换至支持 Premium 的最优延迟线路👇", array[0] +"\n 👉 "+Ping)} - content = `

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

👇

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

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

` - $done({"title":"YouTube 检测&切换", "htmlMessage": content }) - } - }, reject => { - $done(); - }); - - } - //$done(); -}, reject => { - // Normally will never happen. - $done(); -}); -} - - -function testYTB(pname) { - return new Promise((resolve, reject) => { - let opts = { policy : pname } - let option = { - url: BASE_URL, - opts: opts, - headers: { - 'User-Agent': - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36', - 'Accept-Language': 'en', - }, - } - $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) - reject('Error') - return - } - - if (data.indexOf('Premium is not available in your country') !== -1) { - console.log(pname+":未支持") - NoList.push(pname) - resolve('Not Available') - return - } - - let region = '' - let re = new RegExp('"GL":"(.*?)"', 'gm') - let result = re.exec(data) - if (result != null && result.length === 2) { - region = result[1] - } else if (data.indexOf('www.google.cn') !== -1) { - region = 'CN' - } else { - region = 'US' - } - console.log(pname+":支持"+region) - OKList.push(pname) - resolve(region) - } - reject('Error') - }) - }) -} - - diff --git a/Scripts/switch-check-ytb.js b/Scripts/switch-check-ytb.js index 7a3af57..20712fe 100644 --- a/Scripts/switch-check-ytb.js +++ b/Scripts/switch-check-ytb.js @@ -1,27 +1,39 @@ /*** -Thanks to & modified from -1. https://gist.githubusercontent.com/Hyseen/b06e911a41036ebc36acf04ddebe7b9a/raw/nf_check.js -2. https://github.com/AtlantisGawrGura/Quantumult-X-Scripts/blob/main/media.js -3. https://github.com/CoiaPrant/MediaUnlock_Test/blob/main/check.sh - - For Quantumult-X 598+ ONLY!! [task_local] -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 +// UI 查询版本 +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 + +// cron task 版本 +0 8 * * * https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/switch-check-ytb.js#policy=你的策略组, 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 @XIAO_KOP +2022-07-04 + **/ const BASE_URL = 'https://www.youtube.com/premium' const link = { "media-url": "https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/img/southpark/7.png" } -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 @@ -42,13 +54,13 @@ $configuration.sendMessage(message).then(resolve => { } 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] + 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("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) { + console.log("节点数量:"+resolve.ret[policy]["candidates"].length) + if(resolve.ret[policy]["candidates"].length==0) { $done({"title":"YouTube Premium 检测","htmlMessage":`


😭 无有效节点`}); } } @@ -93,10 +105,10 @@ function Check() { console.log("开始排序") ReOrder(OKList) } else if (!OKList[0]){ //不支持 - content =pflag==0 ? `


😭 该节点不支持 YouTube Premium

👇

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

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

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

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

` + content =pflag==0 ? `


😭 该节点不支持 YouTube Premium

👇

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

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

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

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

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


🎉 该节点支持 YouTube Premium

👇

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


🎉 该节点支持 YouTube Premium

👇

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

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

🎉 该节点支持 YouTube Premium" + `

` : `

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

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

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

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

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

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

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

` + "
⟦ "+policy+ " ⟧

🎉 该节点支持 YouTube Premium" + `

` : `

` + "
⟦ "+policy+ " ⟧

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

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

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

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

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

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

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

👇

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

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

` + if (cronsign == "Y") { $notify("📺 YouTube Premium 定时检测&切换", "🎉 已经切换至支持 Premium 的最优延迟线路👇", array[0] +"\n 👉 "+Ping)} + content = `

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

👇

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

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

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