add bili to switch region search

This commit is contained in:
NobyDa 2021-05-02 21:27:25 +08:00
parent 811c84e986
commit da2cfdfd25
1 changed files with 38 additions and 16 deletions

View File

@ -5,7 +5,7 @@
如需禁用豆瓣评分或策略通知, 可前往BoxJs设置.
BoxJs订阅地址: https://raw.githubusercontent.com/NobyDa/Script/master/NobyDa_BoxJs.json
Update: 2021.05.01
Update: 2021.05.02
Author: @NobyDa
Use: Surge, QuanX, Loon
@ -26,6 +26,8 @@ https://raw.githubusercontent.com/DivineEngine/Profiles/master/Quantumult/Filter
绑定相关select或static策略组并且需要具有相关的区域代理服务器纳入您的子策略中子策略可以是服务器也可以是其他区域策略组
最后您可以通过BoxJs设置策略名和子策略名或者手动填入脚本.
如需搜索指定地区番剧, 可在搜索框添加后缀" 港", " 台", " 中". 例如: 进击的巨人
QX用户注: 使用切换地区功能请确保您的QX=>其他设置=>温和策略机制处于关闭状态, 以及填写策略名和子策略名时注意大小写.
****************************
@ -34,6 +36,9 @@ Surge 4.7+ 远程脚本配置 :
[Script]
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
#可选, 适用于搜索指定地区的番剧
Bili Search = type=http-request,pattern=^https:\/\/app\.bilibili\.com\/x\/v2\/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
[MITM]
hostname = ap?.bilibili.com
@ -43,6 +48,9 @@ Quantumult X 远程脚本配置 :
[rewrite_local]
^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
#可选, 适用于搜索指定地区的番剧
^https:\/\/app\.bilibili\.com\/x\/v2\/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
[mitm]
hostname = ap?.bilibili.com
@ -56,26 +64,27 @@ Loon 远程脚本配置 :
[Script]
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自动地区
#可选, 适用于搜索指定地区的番剧
http-request ^https:\/\/app\.bilibili\.com\/x\/v2\/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自动地区(搜索)
[Mitm]
hostname = ap?.bilibili.com
***************************/
let body = JSON.parse($response.body);
let $ = nobyda();
const play = body.data || body.result || {};
const run = SwitchRegion();
let run = EnvInfo();
async function SwitchRegion() {
async function SwitchRegion(play) {
const Group = $.read('BiliArea_Policy') || '📺 DomesticMedia'; //Your blibli policy group name.
const CN = $.read('BiliArea_CN') || 'DIRECT'; //Your China sub-policy name.
const TW = $.read('BiliArea_TW') || '🇹🇼 sub-policy'; //Your Taiwan sub-policy name.
const HK = $.read('BiliArea_HK') || '🇭🇰 sub-policy'; //Your HongKong sub-policy name.
const current = await $.getPolicy(Group) || 'Policy error ⚠️';
const area = (() => {
if (/\u50c5[\u4e00-\u9fa5]+\u6e2f/.test(play.title)) {
if (/\u50c5[\u4e00-\u9fa5]+\u6e2f|%20%E6%B8%AF&/.test(play)) {
if (current != HK) return HK;
} else if (/\u50c5[\u4e00-\u9fa5]+\u53f0/.test(play.title)) {
} else if (/\u50c5[\u4e00-\u9fa5]+\u53f0|%20%E5%8F%B0&/.test(play)) {
if (current != TW) return TW;
} else if (current != CN) return CN;
})()
@ -83,18 +92,31 @@ async function SwitchRegion() {
if (area) {
const change = await $.setPolicy(Group, area);
const notify = $.read('BiliAreaNotify') === 'true';
if (!notify) $.notify(play.title || ``, ``, `${current} => ${area} => ${change?`🟢`:`🔴`}`);
if (change && !$.isQuanX) {
$done(); //Kill the connection. Due to the characteristics of Surge, it will auto reconnect with the new policy.
} else {
QueryRating();
}
const msg = `${current} => ${change?area:'sub-policy error ⚠️'} => ${change?`🟢`:`🔴`}`;
if (!notify) $.notify(/^http/.test(play) || !play ? `` : play, ``, msg);
else console.log(`${/^http/.test(play)||!play?``:play}\n${msg}`);
if (change) return true;
}
return false;
}
function EnvInfo() {
if (typeof($response) !== 'undefined') {
const raw = JSON.parse($response.body);
const data = raw.data || raw.result || {};
//if surge or loon, $done() will auto reconnect with the new policy
SwitchRegion(data.title)
.then(s => s && !$.isQuanX ? $done() : QueryRating(raw, data));
} else {
QueryRating();
const raw = $request.url;
const res = {
url: raw.replace(/%20(%E6%B8%AF|%E5%8F%B0|%E4%B8%AD)&/g, '&')
};
SwitchRegion(raw).then(() => $done(res));
}
}
async function QueryRating() {
async function QueryRating(body, play) {
try {
const ratingEnabled = $.read('BiliDoubanRating') === 'false';
if (!ratingEnabled && play.title && body.data && body.data.badge_info) {
@ -212,7 +234,7 @@ function nobyda() {
return response;
}
const getPolicy = (groupName) => {
const m = `切换策略失败, 您的版本不支持该功能\n`
const m = `Version error ⚠️`
if (isSurge) {
if (typeof($httpAPI) === 'undefined') return m;
return new Promise((resolve) => {