55如需禁用豆瓣评分或策略通知, 可前往BoxJs设置.
66BoxJs订阅地址: https://raw.githubusercontent.com/NobyDa/Script/master/NobyDa_BoxJs.json
77
8- Update: 2021.09.26
8+ Update: 2022.01.18
99Author: @NobyDa
1010Use: Surge, QuanX, Loon
1111
@@ -34,7 +34,7 @@ QX用户注: 使用切换地区功能请确保您的QX=>其他设置=>温和策
3434Surge 4.7+ 远程脚本配置 :
3535****************************
3636[Script]
37- Bili Region = type=http-response,pattern=^https:\/\/ap(p|i)\.bilibili\.com\/(pgc\/view\/( v\d\/)? app|x( \/v\d)?\/view\/video)\/(season|online )\?access_key,requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
37+ Bili Region = type=http-response,pattern=^https:\/\/ap(p|i)\.bilibili\.com\/(pgc\/view\/v\d\/app\/season|x \/v\d\/search\/defaultwords )\?access_key,requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
3838
3939#可选, 适用于搜索指定地区的番剧
4040Bili Search = type=http-request,pattern=^https:\/\/app\.bilibili\.com\/x\/v\d\/search(\/type)?\?.+?%20(%E6%B8%AF|%E5%8F%B0|%E4%B8%AD)&,script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
@@ -46,7 +46,7 @@ hostname = ap?.bilibili.com
4646Quantumult X 远程脚本配置 :
4747****************************
4848[rewrite_local]
49- ^https:\/\/ap(p|i)\.bilibili\.com\/(pgc\/view\/( v\d\/)? app|x( \/v\d)?\/view\/video)\/(season|online )\?access_key url script-response-body https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
49+ ^https:\/\/ap(p|i)\.bilibili\.com\/(pgc\/view\/v\d\/app\/season|x \/v\d\/search\/defaultwords )\?access_key url script-response-body https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
5050
5151#可选, 适用于搜索指定地区的番剧
5252^https:\/\/app\.bilibili\.com\/x\/v\d\/search(\/type)?\?.+?%20(%E6%B8%AF|%E5%8F%B0|%E4%B8%AD)& url script-request-header https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js
@@ -62,7 +62,7 @@ ip-cidr, 203.107.1.1/24, reject
6262Loon 远程脚本配置 :
6363****************************
6464[Script]
65- http-response ^https:\/\/ap(p|i)\.bilibili\.com\/(pgc\/view\/( v\d\/)? app|x( \/v\d)?\/view\/video)\/(season|online )\?access_key script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js, requires-body=true, tag=bili自动地区
65+ http-response ^https:\/\/ap(p|i)\.bilibili\.com\/(pgc\/view\/v\d\/app\/season|x \/v\d\/search\/defaultwords )\?access_key script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js, requires-body=true, tag=bili自动地区
6666
6767#可选, 适用于搜索指定地区的番剧
6868http-request ^https:\/\/app\.bilibili\.com\/x\/v\d\/search(\/type)?\?.+?%20(%E6%B8%AF|%E5%8F%B0|%E4%B8%AD)& script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Surge/JS/Bili_Auto_Regions.js, requires-body=true, tag=bili自动地区(搜索)
@@ -80,23 +80,35 @@ async function SwitchRegion(play) {
8080 const CN = $ . read ( 'BiliArea_CN' ) || 'DIRECT' ; //Your China sub-policy name.
8181 const TW = $ . read ( 'BiliArea_TW' ) || '🇹🇼 sub-policy' ; //Your Taiwan sub-policy name.
8282 const HK = $ . read ( 'BiliArea_HK' ) || '🇭🇰 sub-policy' ; //Your HongKong sub-policy name.
83+ const DF = $ . read ( 'BiliArea_DF' ) || '🏁 sub-policy' ; //Sub-policy name used after region is blocked(e.g. url 404)
84+ const off = $ . read ( 'BiliArea_disabled' ) || '' ; //WiFi blacklist(disable region change), separated by commas.
8385 const current = await $ . getPolicy ( Group ) ;
8486 const area = ( ( ) => {
87+ let select ;
8588 if ( / \u50c5 [ \u4e00 - \u9fa5 ] + \u6e2f | % 2 0 % E 6 % B 8 % A F & / . test ( play ) ) {
86- if ( current != HK ) return HK ;
89+ const test = / \u50c5 [ \u4e00 - \u9fa5 ] + \u53f0 / . test ( play ) ;
90+ if ( current != HK && ( current == TW && test ? 0 : 1 ) ) select = HK ;
8791 } else if ( / \u50c5 [ \u4e00 - \u9fa5 ] + \u53f0 | % 2 0 % E 5 % 8 F % B 0 & / . test ( play ) ) {
88- if ( current != TW ) return TW ;
89- } else if ( current != CN ) return CN ;
92+ if ( current != TW ) select = TW ;
93+ } else if ( play === - 404 ) {
94+ if ( current != DF ) select = DF ;
95+ } else if ( current != CN ) {
96+ select = CN ;
97+ }
98+ if ( $ . isQuanX && current === 'direct' && select === 'DIRECT' ) {
99+ select = null ; //avoid loops in some cases
100+ }
101+ return select ;
90102 } ) ( )
91103
92- if ( area ) {
104+ if ( area && ! off . includes ( $ . ssid || undefined ) ) {
93105 const change = await $ . setPolicy ( Group , area ) ;
94106 const notify = $ . read ( 'BiliAreaNotify' ) === 'true' ;
95107 const msg = SwitchStatus ( change , current , area ) ;
96108 if ( ! notify ) {
97- $ . notify ( / ^ h t t p / . test ( play ) || ! play ? `` : play , `` , msg ) ;
109+ $ . notify ( ( / ^ ( h t t p | - 4 0 4 ) / . test ( play ) || ! play ) ? `` : play , `` , msg ) ;
98110 } else {
99- console . log ( `${ / ^ h t t p / . test ( play ) || ! play ?`` :play } \n${ msg } ` ) ;
111+ console . log ( `${ ( / ^ ( h t t p | - 4 0 4 ) / . test ( play ) || ! play ) ?`` :play } \n${ msg } ` ) ;
100112 }
101113 if ( change ) {
102114 return true ;
@@ -106,7 +118,7 @@ async function SwitchRegion(play) {
106118}
107119
108120function SwitchStatus ( status , original , newPolicy ) {
109- if ( status ) {
121+ if ( status && typeof original !== 'number' ) {
110122 return `${ original } => ${ newPolicy } => 🟢` ;
111123 } else if ( original === 2 ) {
112124 return `切换失败, 策略组名未填写或填写有误 ⚠️`
@@ -123,9 +135,14 @@ function EnvInfo() {
123135 if ( typeof ( $response ) !== 'undefined' ) {
124136 const raw = JSON . parse ( $response . body ) ;
125137 const data = raw . data || raw . result || { } ;
126- //if surge or loon, $done() will auto reconnect with the new policy
127- SwitchRegion ( data . title )
128- . then ( s => s && ! $ . isQuanX ? $done ( ) : QueryRating ( raw , data ) ) ;
138+ SwitchRegion ( data . title || ( raw . code === - 404 ? - 404 : null ) )
139+ . then ( s => s ? $done ( {
140+ status : $ . isQuanX ? "HTTP/1.1 408 Request Timeout" : 408 ,
141+ headers : {
142+ Connection : "close"
143+ } ,
144+ body : "{}"
145+ } ) : QueryRating ( raw , data ) ) ;
129146 } else {
130147 const raw = $request . url ;
131148 const res = {
@@ -237,6 +254,17 @@ function nobyda() {
237254 const isLoon = typeof $loon != "undefined" ;
238255 const isQuanX = typeof $task != "undefined" ;
239256 const isSurge = typeof $network != "undefined" && typeof $script != "undefined" ;
257+ const ssid = ( ( ) => {
258+ if ( isQuanX && typeof ( $environment ) !== 'undefined' ) {
259+ return $environment . ssid ;
260+ }
261+ if ( isSurge && $network . wifi ) {
262+ return $network . wifi . ssid ;
263+ }
264+ if ( isLoon ) {
265+ return JSON . parse ( $config . getConfig ( ) ) . ssid ;
266+ }
267+ } ) ( ) ;
240268 const notify = ( title , subtitle , message ) => {
241269 console . log ( `${ title } \n${ subtitle } \n${ message } ` ) ;
242270 if ( isQuanX ) $notify ( title , subtitle , message ) ;
@@ -328,6 +356,7 @@ function nobyda() {
328356 isLoon,
329357 notify,
330358 read,
359+ ssid,
331360 get
332361 }
333362}
0 commit comments