Skip to content

Commit ea58878

Browse files
committed
Add bilibili auto region switch scripts.
1 parent ae53858 commit ea58878

2 files changed

Lines changed: 97 additions & 3 deletions

File tree

‎NobyDa_BoxJs.json‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
}, {
108108
"key": "JDShoes",
109109
"label": "京东鞋靴"
110-
},{
110+
}, {
111111
"key": "JDEsports",
112112
"label": "京东电竞"
113113
}, {
@@ -228,7 +228,7 @@
228228
"script": "https://raw.githubusercontent.com/NobyDa/Script/master/Bilibili-DailyBonus/Manga.js",
229229
"author": "@NobyDa",
230230
"repo": "https://github.com/NobyDa/Script/blob/master/Bilibili-DailyBonus/Manga.js",
231-
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/bilibili.png", "https://raw.githubusercontent.com/Orz-3/task/master/bilibili.png"]
231+
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/manga.png", "https://raw.githubusercontent.com/Orz-3/task/master/manga.png"]
232232
}, {
233233
"id": "BaiduTB",
234234
"name": "百度贴吧",
@@ -292,6 +292,50 @@
292292
"script": "https://raw.githubusercontent.com/NobyDa/Script/master/KuaiKan-DailyBonus/KKMH.js",
293293
"author": "@NobyDa",
294294
"repo": "https://github.com/NobyDa/Script/blob/master/KuaiKan-DailyBonus/KKMH.js",
295-
"icons": ["https://ftp.bmp.ovh/imgs/2020/09/5eb8495e3582aca9.png", "https://ftp.bmp.ovh/imgs/2020/09/a3345da5e9094363.png"]
295+
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/KuaiKan.png", "https://raw.githubusercontent.com/Orz-3/task/master/KuaiKan.png"]
296+
}, {
297+
"id": "BiliRegion",
298+
"name": "哔哩番剧自动地区",
299+
"descs_html": [
300+
"<h4 align=\"center\">脚本配置请查看<a href=\"https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js\">脚本注释</a></h4>"
301+
],
302+
"settings": [{
303+
"id": "BiliAreaNotify",
304+
"name": "静默运行",
305+
"val": false,
306+
"type": "boolean",
307+
"desc": "不再发出切换策略通知"
308+
}, {
309+
"id": "BiliArea_Policy",
310+
"name": "策略组名",
311+
"val": "",
312+
"type": "text",
313+
"placeholder": "(点击以展开说明)",
314+
"desc": "哔哩哔哩分流的策略组名"
315+
}, {
316+
"id": "BiliArea_CN",
317+
"name": "中国大陆-子策略名",
318+
"val": "DIRECT",
319+
"type": "text",
320+
"placeholder": "(点击以展开说明)",
321+
"desc": "哔哩哔哩分流策略组里的中国大陆子策略名"
322+
}, {
323+
"id": "BiliArea_HK",
324+
"name": "中国香港-子策略名",
325+
"val": "",
326+
"type": "text",
327+
"placeholder": "(点击以展开说明)",
328+
"desc": "哔哩哔哩分流策略组里的香港子策略名"
329+
}, {
330+
"id": "BiliArea_TW",
331+
"name": "中国台湾-子策略名",
332+
"val": "",
333+
"type": "text",
334+
"placeholder": "(点击以展开说明)",
335+
"desc": "哔哩哔哩分流策略组里的台湾子策略名"
336+
}],
337+
"author": "@NobyDa",
338+
"repo": "https://github.com/NobyDa/Script/blob/master/Surge/JS/Bili_Auto_Regions.js",
339+
"icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/bilibili.png", "https://raw.githubusercontent.com/Orz-3/task/master/bilibili.png"]
296340
}]
297341
}

‎Surge/JS/Bili_Auto_Regions.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Bilibli番剧,自动切换地区
3+
4+
此脚本仅适用于Surge4.0+
5+
此脚本仅适用于Surge4.0+
6+
此脚本仅适用于Surge4.0+
7+
8+
您需要配置相关规则集(https://raw.githubusercontent.com/DivineEngine/Profiles/master/Surge/Ruleset/StreamingMedia/StreamingSE.list)绑定相关select策略组,并且需要具有相关的区域代理服务器纳入您的子策略中。
9+
最后,您可以通过BoxJs设置策略名和子策略名,或者手动填入脚本。
10+
11+
Author: @NobyDa
12+
13+
****************************
14+
Surge 4.2+ 远程脚本配置 :
15+
****************************
16+
[Script]
17+
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
18+
19+
[MITM]
20+
hostname = api.bilibili.com
21+
****************************
22+
*/
23+
24+
const Group = $persistentStore.read('BiliArea_Policy') || '📺 DomesticMedia'; //Your blibli policy group name.
25+
const CN = $persistentStore.read('BiliArea_CN') || 'DIRECT'; //Your China sub-policy name.
26+
const TW = $persistentStore.read('BiliArea_TW') || '🇹🇼 sub-policy'; //Your Taiwan sub-policy name.
27+
const HK = $persistentStore.read('BiliArea_HK') || '🇭🇰 sub-policy'; //Your HongKong sub-policy name.
28+
29+
const obj = JSON.parse($response.body).result.title;
30+
const current = $surge.selectGroupDetails().decisions[Group] || 'Policy error ⚠️'
31+
const str = (() => {
32+
if (obj.match(/\u50c5[\u4e00-\u9fa5]+\u6e2f/)) {
33+
if (current != HK) return HK;
34+
} else if (obj.match(/\u50c5[\u4e00-\u9fa5]+\u53f0/)) {
35+
if (current != TW) return TW;
36+
} else if (current != CN) return CN;
37+
})()
38+
39+
if (str) {
40+
const change = $surge.setSelectGroupPolicy(Group, str);
41+
const notify = $persistentStore.read('BiliAreaNotify') === 'true';
42+
if (!notify) $notification.post(obj, ``, `${current} => ${str} => ${change?`🟢`:`🔴`}`);
43+
if (change) {
44+
$done(); //Kill the connection. Due to the characteristics of Surge, it will auto reconnect with the new policy.
45+
} else {
46+
$done({});
47+
}
48+
} else {
49+
$done({});
50+
}

0 commit comments

Comments
 (0)