| 76 | let run = EnvInfo(); |
| 77 | |
| 78 | async function SwitchRegion(title, url, body) { |
| 79 | const Group = $.read('BiliArea_Policy') || '📺 DomesticMedia'; //Your blibli policy group name. |
| 80 | const CN = $.read('BiliArea_CN') || 'DIRECT'; //Your China sub-policy name. |
| 81 | const TW = $.read('BiliArea_TW') || '🇹🇼 sub-policy'; //Your Taiwan sub-policy name. |
| 82 | 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. |
| 85 | const current = await $.getPolicy(Group); |
| 86 | const area = (() => { |
| 87 | let select = {}; |
| 88 | let chtMatch = title && title.split('').some(v => zhHans().includes(v)); |
| 89 | if (/\u6e2f[\u4e00-\u9fa5]+\u5340|%20%E6%B8%AF&/.test(title || url)) { |
| 90 | const test = /\u53f0[\u4e00-\u9fa5]+\u5340/.test(title); |
| 91 | if (current != HK && (current == TW && test ? 0 : 1)) |
| 92 | select = { policy: HK, mode: '香港' }; |
| 93 | } else if (/\u53f0[\u4e00-\u9fa5]+\u5340|%20%E5%8F%B0&/.test(title || url)) { |
| 94 | if (current != TW) select = { policy: TW, mode: '台湾' }; |
| 95 | } else if (body.code === -404 || chtMatch) { |
| 96 | if (current != DF) select = { policy: DF, mode: '后备' }; |
| 97 | } else if (current != CN) { |
| 98 | select = { policy: CN, mode: '直连' }; |
| 99 | } |
| 100 | if ($.isQuanX && current === 'direct' && select.policy === 'DIRECT') { |
| 101 | select = {}; //prevent loopback in some cases |
| 102 | } |
| 103 | return select; |
| 104 | })() |
| 105 | |
| 106 | if (area.policy && !off.includes($.ssid || undefined)) { |
| 107 | const change = await $.setPolicy(Group, area.policy); |
| 108 | const msg = (() => { |
| 109 | if (change && typeof current !== 'number') { |
| 110 | return `${current} ➤ ${area.policy}`; |
| 111 | } else if (current === 2) { |
| 112 | return `策略组名未填写或填写有误 ⚠️` |
| 113 | } else if (current === 3) { |
| 114 | return `不支持您的VPN应用版本 ⚠️` |
| 115 | } else if (change === 0) { |
| 116 | return `子策略名未填写或填写有误 ⚠️` |
| 117 | } else { |
| 118 | return `未知错误 ⚠️` |
| 119 | } |
| 120 | })() |
| 121 | if ($.read('BiliAreaNotify') === 'true') { |
| 122 | console.log(`${title || ''}\n模式: 策略组使用"${area.mode}"子策略\n走向: ${msg}`); |
| 123 | } else { |
| 124 | $.notify(title || '', ``, `模式: 策略组使用"${area.mode}"子策略\n走向: ${msg}`); |
| 125 | } |
| 126 | if (change) { |
| 127 | return true; |
| 128 | } |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | function EnvInfo() { |
| 134 | const url = $request.url; |