Add bilibili auto region switch scripts.

This commit is contained in:
NobyDa 2020-10-10 00:35:17 +08:00
parent ae538582d8
commit ea58878bc7
2 changed files with 97 additions and 3 deletions

View File

@ -107,7 +107,7 @@
}, {
"key": "JDShoes",
"label": "京东鞋靴"
},{
}, {
"key": "JDEsports",
"label": "京东电竞"
}, {
@ -228,7 +228,7 @@
"script": "https://raw.githubusercontent.com/NobyDa/Script/master/Bilibili-DailyBonus/Manga.js",
"author": "@NobyDa",
"repo": "https://github.com/NobyDa/Script/blob/master/Bilibili-DailyBonus/Manga.js",
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/bilibili.png", "https://raw.githubusercontent.com/Orz-3/task/master/bilibili.png"]
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/manga.png", "https://raw.githubusercontent.com/Orz-3/task/master/manga.png"]
}, {
"id": "BaiduTB",
"name": "百度贴吧",
@ -292,6 +292,50 @@
"script": "https://raw.githubusercontent.com/NobyDa/Script/master/KuaiKan-DailyBonus/KKMH.js",
"author": "@NobyDa",
"repo": "https://github.com/NobyDa/Script/blob/master/KuaiKan-DailyBonus/KKMH.js",
"icons": ["https://ftp.bmp.ovh/imgs/2020/09/5eb8495e3582aca9.png", "https://ftp.bmp.ovh/imgs/2020/09/a3345da5e9094363.png"]
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/KuaiKan.png", "https://raw.githubusercontent.com/Orz-3/task/master/KuaiKan.png"]
}, {
"id": "BiliRegion",
"name": "哔哩番剧自动地区",
"descs_html": [
"<h4 align=\"center\">脚本配置请查看<a href=\"https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js\">脚本注释</a></h4>"
],
"settings": [{
"id": "BiliAreaNotify",
"name": "静默运行",
"val": false,
"type": "boolean",
"desc": "不再发出切换策略通知"
}, {
"id": "BiliArea_Policy",
"name": "策略组名",
"val": "",
"type": "text",
"placeholder": "(点击以展开说明)",
"desc": "哔哩哔哩分流的策略组名"
}, {
"id": "BiliArea_CN",
"name": "中国大陆-子策略名",
"val": "DIRECT",
"type": "text",
"placeholder": "(点击以展开说明)",
"desc": "哔哩哔哩分流策略组里的中国大陆子策略名"
}, {
"id": "BiliArea_HK",
"name": "中国香港-子策略名",
"val": "",
"type": "text",
"placeholder": "(点击以展开说明)",
"desc": "哔哩哔哩分流策略组里的香港子策略名"
}, {
"id": "BiliArea_TW",
"name": "中国台湾-子策略名",
"val": "",
"type": "text",
"placeholder": "(点击以展开说明)",
"desc": "哔哩哔哩分流策略组里的台湾子策略名"
}],
"author": "@NobyDa",
"repo": "https://github.com/NobyDa/Script/blob/master/Surge/JS/Bili_Auto_Regions.js",
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/bilibili.png", "https://raw.githubusercontent.com/Orz-3/task/master/bilibili.png"]
}]
}

View File

@ -0,0 +1,50 @@
/*
Bilibli番剧自动切换地区
此脚本仅适用于Surge4.0+
此脚本仅适用于Surge4.0+
此脚本仅适用于Surge4.0+
您需要配置相关规则集https://raw.githubusercontent.com/DivineEngine/Profiles/master/Surge/Ruleset/StreamingMedia/StreamingSE.list绑定相关select策略组并且需要具有相关的区域代理服务器纳入您的子策略中。
最后您可以通过BoxJs设置策略名和子策略名或者手动填入脚本
Author: @NobyDa
****************************
Surge 4.2+ 远程脚本配置 :
****************************
[Script]
Bili Region = type=http-response,pattern=https:\/\/api\.bilibili\.com\/pgc\/view\/app\/season\?access_key,requires-body=1,max-size=0,control-api=1,script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
[MITM]
hostname = api.bilibili.com
****************************
*/
const Group = $persistentStore.read('BiliArea_Policy') || '📺 DomesticMedia'; //Your blibli policy group name.
const CN = $persistentStore.read('BiliArea_CN') || 'DIRECT'; //Your China sub-policy name.
const TW = $persistentStore.read('BiliArea_TW') || '🇹🇼 sub-policy'; //Your Taiwan sub-policy name.
const HK = $persistentStore.read('BiliArea_HK') || '🇭🇰 sub-policy'; //Your HongKong sub-policy name.
const obj = JSON.parse($response.body).result.title;
const current = $surge.selectGroupDetails().decisions[Group] || 'Policy error ⚠️'
const str = (() => {
if (obj.match(/\u50c5[\u4e00-\u9fa5]+\u6e2f/)) {
if (current != HK) return HK;
} else if (obj.match(/\u50c5[\u4e00-\u9fa5]+\u53f0/)) {
if (current != TW) return TW;
} else if (current != CN) return CN;
})()
if (str) {
const change = $surge.setSelectGroupPolicy(Group, str);
const notify = $persistentStore.read('BiliAreaNotify') === 'true';
if (!notify) $notification.post(obj, ``, `${current} => ${str} => ${change?`🟢`:`🔴`}`);
if (change) {
$done(); //Kill the connection. Due to the characteristics of Surge, it will auto reconnect with the new policy.
} else {
$done({});
}
} else {
$done({});
}