From fe4177be472c740088d5231c2cb9ffe24af505d0 Mon Sep 17 00:00:00 2001
From: Shawn <45581750+KOP-XIAO@users.noreply.github.com>
Date: Mon, 18 Oct 2021 20:21:43 +0800
Subject: [PATCH] =?UTF-8?q?=E7=B2=97=E6=9A=B4=E5=88=87=E6=8D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Scripts/switch-check-nf.js | 145 ++++++++++++++++++++++++++++++++++++
Scripts/switch-check-ytb.js | 143 +++++++++++++++++++++++++++++++++++
2 files changed, 288 insertions(+)
create mode 100644 Scripts/switch-check-nf.js
create mode 100644 Scripts/switch-check-ytb.js
diff --git a/Scripts/switch-check-nf.js b/Scripts/switch-check-nf.js
new file mode 100644
index 0000000..480f054
--- /dev/null
+++ b/Scripts/switch-check-nf.js
@@ -0,0 +1,145 @@
+/***
+
+Thanks to & modified from
+1. https://gist.githubusercontent.com/Hyseen/b06e911a41036ebc36acf04ddebe7b9a/raw/nf_check.js
+
+For Quantumult-X 598+ ONLY!!
+
+[task_local]
+
+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
+
+@XIAO_KOP
+
+**/
+
+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
+const message = {
+ action: "get_customized_policy",
+ content: policy
+
+};
+
+var output=[]
+var OKList=["完整解锁节点 ➟ "]
+var ResList=["仅支持自制剧节点 ➟ "]
+var NoList=["不支持节点 ➟ "]
+var timeoutList=["检测超时节点 ➟ "]
+
+$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.stringify(resolve.ret[message.content]["candidates"]).replace(/\"|\[|\]/g,"").replace(/\,/g," ➟ ").split(" ➟ ") : $environment.params
+ //$notify(typeof(output),output)
+ Check()
+ //$done({"title":"策略内容","message":output})
+ }
+ //$done();|
+}, reject => {
+ // Normally will never happen.
+ $done();
+});
+
+function Check() {
+ var relay = 2000;
+ for ( var i=0;i < output.length;i++) {
+ testNF(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(() => {
+ const dict = { [policy] : OKList[2]};
+ const mes1 = {
+ action: "set_policy_state",
+ content: dict
+ };
+ $configuration.sendMessage(mes1).then(resolve => {
+ if (resolve.error) {
+ console.log(resolve.error);
+ content = `
` + "
❌ ⟦"+$environment.params+ "⟧ 切换失败,未找到完整支持节点" + `
`
+ $done({"title":"Netflix 切换", "htmlMessage": content})
+ }
+ if (resolve.ret) {
+ console.log("已经切换至完整支持的路线 ➟ "+OKList[2])
+ content = `` + "
⟦"+$environment.params+ "⟧ 已切换至完整支持的路线
👇
⟦"+OKList[2]+ "⟧" + "
-------------------
Shawn 大善人自用
-------------------"+`
`
+ $done({"title":"Netflix 切换", "htmlMessage": content })
+ }
+ }, reject => {
+ $done();
+ });
+
+
+ }, relay)
+
+}
+
+
+
+
+function testNF(pname ) {
+ return new Promise((resolve, reject) => {
+ //console.log(pname)
+ let opts = { policy : pname }
+ let option = {
+ url: BASE_URL + FILM_ID,
+ 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',
+ },
+ }
+ $task.fetch(option).then (response => {
+
+ if (response.statusCode === 404) {
+ NoList.push(pname)
+ console.log(pname+": "+"未支持")
+ resolve('Not Found')
+ return
+ }
+
+ if (response.statusCode === 403) {
+ ResList.push(pname)
+ console.log(pname+": "+"仅支持自制剧集")
+ resolve('Not Available')
+ return
+ }
+
+ if (response.statusCode === 200) {
+ console.log(pname+": "+"完整支持")
+ let url = response.headers['X-Originating-URL']
+ let region = url.split('/')[3]
+ region = region.split('-')[0]
+ if (region == 'title') {
+ region = 'us'
+ }
+ OKList.push(pname)
+ resolve(region)
+ return
+ }
+ reject('Error')
+ })
+ })
+}
+
+
diff --git a/Scripts/switch-check-ytb.js b/Scripts/switch-check-ytb.js
new file mode 100644
index 0000000..a4f52d6
--- /dev/null
+++ b/Scripts/switch-check-ytb.js
@@ -0,0 +1,143 @@
+/***
+
+Thanks to & modified from
+1. https://gist.githubusercontent.com/Hyseen/b06e911a41036ebc36acf04ddebe7b9a/raw/nf_check.js
+
+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
+
+ps. 简单粗暴的 UI-Interaction 版本。无数据持久化、粗暴延迟等待。完美主义建议使用 Helge大佬的boxjs版本 https://t.me/QuanXNews/193
+
+@XIAO_KOP
+
+**/
+
+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
+const message = {
+ action: "get_customized_policy",
+ content: policy
+
+};
+
+var output=[]
+var OKList=["支持节点 ➟ "]
+var NoList=["不支持节点 ➟ "]
+var ErrorList=["检测出错节点 ➟ "]
+
+$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.stringify(resolve.ret[message.content]["candidates"]).replace(/\"|\[|\]/g,"").replace(/\,/g," ➟ ").split(" ➟ ") : $environment.params
+ //$notify(typeof(output),output)
+ Check()
+ //$done({"title":"策略内容","message":output})
+ }
+ //$done();|
+}, reject => {
+ // Normally will never happen.
+ $done();
+});
+
+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(() => {
+ const dict = { [policy] : OKList[2]};
+ const mes1 = {
+ action: "set_policy_state",
+ content: dict
+ };
+ $configuration.sendMessage(mes1).then(resolve => {
+ if (resolve.error) {
+ console.log(resolve.error);
+ content = `` + "
❌ ⟦"+$environment.params+ "⟧ 切换失败,未找到支持 YouTube Premium 的节点" + `
`
+ $done({"title":"Netflix 切换", "htmlMessage": content})
+ }
+ if (resolve.ret) {
+ console.log("已经切换至支持 Premium 的路线 ➟ "+OKList[2])
+ content = `` + "
⟦"+$environment.params+ "⟧ 已切换至支持Premium 的路线
👇
⟦"+OKList[2]+ "⟧" + "
-------------------
Shawn 大善人自用
-------------------"+`
`
+ $done({"title":"YouTube 切换", "htmlMessage": content })
+ }
+ }, reject => {
+ $done();
+ });
+
+
+ }, relay)
+
+}
+
+
+
+
+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 (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)
+ })
+ })
+}
+
+