Rules-For-Quantumult-X/Scripts/Unlock/BiliBili-proto.js

124 lines
210 KiB
JavaScript
Raw Normal View History

let protobuf = null;
// protobuf.js 6.11.2
(function(undefined){"use strict";(function prelude(modules,cache,entries){function $require(name){var $module=cache[name];if(!$module)modules[name][0].call($module=cache[name]={exports:{}},$require,$module,$module.exports);return $module.exports}protobuf=$require(entries[0]);protobuf.util.global.protobuf=protobuf;if(typeof define==="function"&&define.amd)define(["long"],function(Long){if(Long&&Long.isLong){protobuf.util.Long=Long;protobuf.configure()}return protobuf});if(typeof module==="object"&&module&&module.exports)module.exports=protobuf})({1:[function(require,module,exports){"use strict";module.exports=asPromise;function asPromise(fn,ctx){var params=new Array(arguments.length-1),offset=0,index=2,pending=true;while(index<arguments.length)params[offset++]=arguments[index++];return new Promise(function executor(resolve,reject){params[offset]=function callback(err){if(pending){pending=false;if(err)reject(err);else{var params=new Array(arguments.length-1),offset=0;while(offset<params.length)params[offset++]=arguments[offset];resolve.apply(null,params)}}};try{fn.apply(ctx||null,params)}catch(err){if(pending){pending=false;reject(err)}}})}},{}],2:[function(require,module,exports){"use strict";var base64=exports;base64.length=function length(string){var p=string.length;if(!p)return 0;var n=0;while(--p%4>1&&string.charAt(p)==="=")++n;return Math.ceil(string.length*3)/4-n};var b64=new Array(64);var s64=new Array(123);for(var i=0;i<64;)s64[b64[i]=i<26?i+65:i<52?i+71:i<62?i-4:i-59|43]=i++;base64.encode=function encode(buffer,start,end){var parts=null,chunk=[];var i=0,j=0,t;while(start<end){var b=buffer[start++];switch(j){case 0:chunk[i++]=b64[b>>2];t=(b&3)<<4;j=1;break;case 1:chunk[i++]=b64[t|b>>4];t=(b&15)<<2;j=2;break;case 2:chunk[i++]=b64[t|b>>6];chunk[i++]=b64[b&63];j=0;break}if(i>8191){(parts||(parts=[])).push(String.fromCharCode.apply(String,chunk));i=0}}if(j){chunk[i++]=b64[t];chunk[i++]=61;if(j===1)chunk[i++]=61}if(parts){if(i)parts.push(String.fromCharCode.apply(String,chunk.slice(0,i)));return parts.join("")}return String.fromCharCode.apply(String,chunk.slice(0,i))};var invalidEncoding="invalid encoding";base64.decode=function decode(string,buffer,offset){var start=offset;var j=0,t;for(var i=0;i<string.length;){var c=string.charCodeAt(i++);if(c===61&&j>1)break;if((c=s64[c])===undefined)throw Error(invalidEncoding);switch(j){case 0:t=c;j=1;break;case 1:buffer[offset++]=t<<2|(c&48)>>4;t=c;j=2;break;case 2:buffer[offset++]=(t&15)<<4|(c&60)>>2;t=c;j=3;break;case 3:buffer[offset++]=(t&3)<<6|c;j=0;break}}if(j===1)throw Error(invalidEncoding);return offset-start};base64.test=function test(string){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string)}},{}],3:[function(require,module,exports){"use strict";module.exports=codegen;function codegen(functionParams,functionName){if(typeof functionParams==="string"){functionName=functionParams;functionParams=undefined}var body=[];function Codegen(formatStringOrScope){if(typeof formatStringOrScope!=="string"){var source=toString();if(codegen.verbose)console.log("codegen: "+source);source="return "+source;if(formatStringOrScope){var scopeKeys=Object.keys(formatStringOrScope),scopeParams=new Array(scopeKeys.length+1),scopeValues=new Array(scopeKeys.length),scopeOffset=0;while(scopeOffset<scopeKeys.length){scopeParams[scopeOffset]=scopeKeys[scopeOffset];scopeValues[scopeOffset]=formatStringOrScope[scopeKeys[scopeOffset++]]}scopeParams[scopeOffset]=source;return Function.apply(null,scopeParams).apply(null,scopeValues)}return Function(source)()}var formatParams=new Array(arguments.length-1),formatOffset=0;while(formatOffset<formatParams.length)formatParams[formatOffset]=arguments[++formatOffset];formatOffset=0;formatStringOrScope=formatStringOrScope.replace(/%([%dfijs])/g,function replace($0,$1){var value=formatParams[formatOffset++];switch($1){case"d":case"f":return String(Number(value));case"i":return String(Math.floor(value));case"j":return JSON.stringify(value);case"s":return String(value)}return"%"});if(formatOffset!==formatParams.length)throw Error(
2022-10-29 11:42:12 +08:00
// pako 2.0.4
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).pako={})}(this,(function(t){"use strict";function e(t){let e=t.length;for(;--e>=0;)t[e]=0}const a=256,i=286,n=30,s=15,r=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),l=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),o=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),h=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),d=new Array(576);e(d);const _=new Array(60);e(_);const f=new Array(512);e(f);const c=new Array(256);e(c);const u=new Array(29);e(u);const w=new Array(n);function b(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}let g,p,m;function k(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}e(w);const v=t=>t<256?f[t]:f[256+(t>>>7)],y=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},x=(t,e,a)=>{t.bi_valid>16-a?(t.bi_buf|=e<<t.bi_valid&65535,y(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=a-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=a)},z=(t,e,a)=>{x(t,a[2*e],a[2*e+1])},A=(t,e)=>{let a=0;do{a|=1&t,t>>>=1,a<<=1}while(--e>0);return a>>>1},E=(t,e,a)=>{const i=new Array(16);let n,r,l=0;for(n=1;n<=s;n++)i[n]=l=l+a[n-1]<<1;for(r=0;r<=e;r++){let e=t[2*r+1];0!==e&&(t[2*r]=A(i[e]++,e))}},R=t=>{let e;for(e=0;e<i;e++)t.dyn_ltree[2*e]=0;for(e=0;e<n;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},Z=t=>{t.bi_valid>8?y(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},U=(t,e,a,i)=>{const n=2*e,s=2*a;return t[n]<t[s]||t[n]===t[s]&&i[e]<=i[a]},S=(t,e,a)=>{const i=t.heap[a];let n=a<<1;for(;n<=t.heap_len&&(n<t.heap_len&&U(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!U(e,i,t.heap[n],t.depth));)t.heap[a]=t.heap[n],a=n,n<<=1;t.heap[a]=i},D=(t,e,i)=>{let n,s,o,h,d=0;if(0!==t.last_lit)do{n=t.pending_buf[t.d_buf+2*d]<<8|t.pending_buf[t.d_buf+2*d+1],s=t.pending_buf[t.l_buf+d],d++,0===n?z(t,s,e):(o=c[s],z(t,o+a+1,e),h=r[o],0!==h&&(s-=u[o],x(t,s,h)),n--,o=v(n),z(t,o,i),h=l[o],0!==h&&(n-=w[o],x(t,n,h)))}while(d<t.last_lit);z(t,256,e)},T=(t,e)=>{const a=e.dyn_tree,i=e.stat_desc.static_tree,n=e.stat_desc.has_stree,r=e.stat_desc.elems;let l,o,h,d=-1;for(t.heap_len=0,t.heap_max=573,l=0;l<r;l++)0!==a[2*l]?(t.heap[++t.heap_len]=d=l,t.depth[l]=0):a[2*l+1]=0;for(;t.heap_len<2;)h=t.heap[++t.heap_len]=d<2?++d:0,a[2*h]=1,t.depth[h]=0,t.opt_len--,n&&(t.static_len-=i[2*h+1]);for(e.max_code=d,l=t.heap_len>>1;l>=1;l--)S(t,a,l);h=r;do{l=t.heap[1],t.heap[1]=t.heap[t.heap_len--],S(t,a,1),o=t.heap[1],t.heap[--t.heap_max]=l,t.heap[--t.heap_max]=o,a[2*h]=a[2*l]+a[2*o],t.depth[h]=(t.depth[l]>=t.depth[o]?t.depth[l]:t.depth[o])+1,a[2*l+1]=a[2*o+1]=h,t.heap[1]=h++,S(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const a=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,r=e.stat_desc.has_stree,l=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let d,_,f,c,u,w,b=0;for(c=0;c<=s;c++)t.bl_count[c]=0;for(a[2*t.heap[t.heap_max]+1]=0,d=t.heap_max+1;d<573;d++)_=t.heap[d],c=a[2*a[2*_+1]+1]+1,c>h&&(c=h,b++),a[2*_+1]=c,_>i||(t.bl_count[c]++,u=0,_>=o&&(u=l[_-o]),w=a[2*_],t.opt_len+=w*(c+u),r&&(t.static_len+=w*(n[2*_+1]+u)));if(0!==b){do{for(c=h-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[h]--,b-=2}while(b>0);for(c=h;0!==c;c--)for(_=t.bl_count[c];0!==_;)f=t.heap[--d],f>i||(a[2*f+1]!==c&&(t.opt_len+=(c-a[2*f+1])*a[2*f],a[2*f+1]=c),_--)}})(t,e),E(a,d,t.bl_count)},O=(t,e,a)=>{let i,n,s=-1,r=e[1],l=0,o=7,h=4;for(0===r&&(o=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)n=r,r=e[2*(i+1)+1],++l<o&&n===r||(l<h?t.bl_tree[2*n]+=l:0!==n?(n!==s&&t.bl_tree[2*n]++,t.bl_tree[32]++):l<=10?t.bl_tree[34]++:t.bl_tree[36]++,l=0,s=n,0===r?(o=138,h=3):n===r?(o=6,h=3):(o=7,h=4))},I=(t,e,a)=>{let i,n,s=-1,r=e[1],l=0,o=7,h=4;for(0===r&&(o=138
const biliJson = {"nested":{"bilibili":{"nested":{"ad":{"nested":{"v1":{"options":{"java_package":"com.smile.bilibili.model"},"nested":{"AdAutoPlayVideoDto":{"fields":{"avid":{"type":"int64","id":1},"cid":{"type":"int64","id":2},"page":{"type":"int64","id":3},"from":{"type":"string","id":4},"url":{"type":"string","id":5},"cover":{"type":"string","id":6},"autoPlay":{"type":"bool","id":7},"btnDycColor":{"type":"bool","id":8},"btnDycTime":{"type":"int32","id":9},"bizId":{"type":"int64","id":10},"process0Urls":{"rule":"repeated","type":"string","id":11},"play3SUrls":{"rule":"repeated","type":"string","id":12},"play5SUrls":{"rule":"repeated","type":"string","id":13},"orientation":{"type":"int32","id":14},"fromSpmid":{"type":"string","id":15},"autoPlayValue":{"type":"int32","id":16}}},"AdBusinessMarkDto":{"fields":{"type":{"type":"int32","id":1},"text":{"type":"string","id":2},"textColor":{"type":"string","id":3},"textColorNight":{"type":"string","id":4},"bgColor":{"type":"string","id":5},"bgColorNight":{"type":"string","id":6},"borderColor":{"type":"string","id":7},"borderColorNight":{"type":"string","id":8},"imgUrl":{"type":"string","id":9},"imgHeight":{"type":"int32","id":10},"imgWidth":{"type":"int32","id":11},"bgBorderColor":{"type":"string","id":12}}},"AdButtonDto":{"fields":{"type":{"type":"int32","id":1},"text":{"type":"string","id":2},"jumpUrl":{"type":"string","id":3},"reportUrls":{"rule":"repeated","type":"string","id":4},"dlsucCallupUrl":{"type":"string","id":5},"gameId":{"type":"int32","id":6},"gameMonitorParam":{"type":"string","id":7}}},"AdCardDto":{"fields":{"cardType":{"type":"int32","id":1},"title":{"type":"string","id":2},"desc":{"type":"string","id":3},"extraDesc":{"type":"string","id":4},"longDesc":{"type":"string","id":5},"shortTitle":{"type":"string","id":6},"danmuTitle":{"type":"string","id":7},"danmuHeight":{"type":"int32","id":8},"danmuWidth":{"type":"int32","id":9},"danmuLife":{"type":"int32","id":10},"danmuBegin":{"type":"int32","id":11},"danmuColor":{"type":"string","id":12},"danmuH5Url":{"type":"string","id":13},"danmuIcon":{"type":"string","id":14},"foldTime":{"type":"int32","id":15},"adTag":{"type":"string","id":16},"covers":{"rule":"repeated","type":"AdCoverDto","id":17},"jumpUrl":{"type":"string","id":18},"imaxLandingPageJsonString":{"type":"string","id":19},"callupUrl":{"type":"string","id":20},"universalApp":{"type":"string","id":21},"oriPrice":{"type":"string","id":22},"curPrice":{"type":"int32","id":23},"priceDesc":{"type":"string","id":24},"priceSymbol":{"type":"string","id":25},"goodsCurPrice":{"type":"string","id":26},"goodsOriPrice":{"type":"string","id":27},"good":{"type":"AdGoodDto","id":28},"rank":{"type":"int32","id":29},"hotScore":{"type":"int32","id":30},"button":{"type":"AdButtonDto","id":31},"adverLogo":{"type":"string","id":32},"adverName":{"type":"string","id":33},"adverPageUrl":{"type":"string","id":34},"videoBarrage":{"rule":"repeated","type":"string","id":35},"adTagStyle":{"type":"AdBusinessMarkDto","id":36},"video":{"type":"AdAutoPlayVideoDto","id":37},"feedbackPanel":{"type":"AdFeedbackPanelDto","id":38},"adverMid":{"type":"int64","id":39},"adverAccountId":{"type":"int64","id":40},"duration":{"type":"string","id":41},"qualityInfos":{"rule":"repeated","type":"QualityInfo","id":42},"dynamicText":{"type":"string","id":43},"adver":{"type":"AdverDto","id":44},"gradeLevel":{"type":"int32","id":45},"supportTransition":{"type":"bool","id":46},"transition":{"type":"string","id":47},"underPlayerInteractionStyle":{"type":"int32","id":48},"imaxLandingPageV2":{"type":"string","id":49},"subcardModule":{"type":"SubCardModule","id":50},"gradeDenominator":{"type":"int32","id":51},"starLevel":{"type":"int32","id":52}}},"SubCardModule":{"fields":{"subcardType":{"type":"string","id":1},"icon":{"type":"string","id":2},"desc":{"type":"string","id":3},"rankStars":{"type":"string","id":4},"amountNumber":{"type":"string","id":5},"avatar":{"type":"string","id":6},"title":{"type":"string","id":7},"button":{"type":"AdButtonDto","id":8},"tagInfos":{"rule":"repeated","type":"TagInfo","id":9}}},"TagI
2022-10-29 11:42:12 +08:00
const url = $request.url;
const method = $request.method;
const postMethod = "POST";
const isQuanX = typeof $task != "undefined";
2022-10-29 11:42:12 +08:00
const binaryBody = isQuanX ? new Uint8Array($response.bodyBytes) : $response.body;
const unGzipBody = pako.ungzip(binaryBody.slice(5));
2022-10-29 11:42:12 +08:00
let body;
const biliRoot = protobuf.Root.fromJSON(biliJson);
let needProcessFlag = false;
if (url.indexOf("Dynamic/DynAll") !== -1 && method === postMethod) {
2022-10-29 11:42:12 +08:00
console.log('动态DynAll');
const dynAllReplyType = biliRoot.lookupType("bilibili.app.dynamic.DynAllReply");
let dynAllReplyMessage = dynAllReplyType.decode(unGzipBody);
if (!dynAllReplyMessage.hasOwnProperty('topicList') || dynAllReplyMessage.topicList === null) {
2022-10-29 11:42:12 +08:00
console.log('topicList为空');
} else {
needProcessFlag = true;
dynAllReplyMessage.topicList = null;
2022-10-29 11:42:12 +08:00
console.log('推荐话题topicList去除');
}
if (!dynAllReplyMessage.dynamicList.hasOwnProperty('list') || dynAllReplyMessage.dynamicList.list === null || dynAllReplyMessage.dynamicList.list.length === 0) {
2022-10-29 11:42:12 +08:00
console.log('动态列表list为空');
} else {
let adCount = 0;
dynAllReplyMessage.dynamicList.list = dynAllReplyMessage.dynamicList.list.filter(item => {
if (item.cardType !== 15) {
2022-10-29 11:42:12 +08:00
return true;
}
adCount++;
return false;
});
if (adCount !== 0) {
2022-10-29 11:42:12 +08:00
needProcessFlag = true;
}
console.log(`动态列表广告数量:${adCount}`);
}
if (needProcessFlag) {
body = processNewBody(dynAllReplyType.encode(dynAllReplyMessage).finish());
2022-10-29 11:42:12 +08:00
}
} else if (url.indexOf("View/View") !== -1 && method === postMethod) {
2022-10-29 11:42:12 +08:00
console.log('视频播放页View/View');
const viewReplyType = biliRoot.lookupType("bilibili.app.view.ViewReply");
let viewReplyMessage = viewReplyType.decode(unGzipBody);
if (!viewReplyMessage.hasOwnProperty('cms') || viewReplyMessage.cms === null || viewReplyMessage.cms.length === 0) {
2022-10-29 11:42:12 +08:00
console.log('cms为空');
} else {
let adCount = 0;
const sourceContentDtoType = biliRoot.lookupType("bilibili.ad.v1.SourceContentDto");
for (let i = 0; i < viewReplyMessage.cms.length; i++) {
let item = viewReplyMessage.cms[i];
if (item.sourceContent !== null && item.sourceContent.hasOwnProperty('value')) {
2022-10-29 11:42:12 +08:00
// 注意这里虽然proto没有属性value 但是viewReplyMessage解析的有
const sourceContentDtoMessage = sourceContentDtoType.decode(item.sourceContent.value);
if (sourceContentDtoMessage.hasOwnProperty('adContent')) {
2022-10-29 11:42:12 +08:00
adCount++;
}
}
}
viewReplyMessage.cms = [];
2022-10-29 11:42:12 +08:00
console.log(`up主推荐广告:${adCount}`);
if (adCount !== 0) {
2022-10-29 11:42:12 +08:00
needProcessFlag = true;
}
}
if (!viewReplyMessage.hasOwnProperty('relates') || viewReplyMessage.relates === null || viewReplyMessage.relates.length === 0) {
2022-10-29 11:42:12 +08:00
console.log('relates相关推荐为空');
} else {
let adCount = 0;
viewReplyMessage.relates = viewReplyMessage.relates.filter(item => {
if (item.goto === 'cm') {
2022-10-29 11:42:12 +08:00
adCount++;
return false;
}
return true;
});
console.log(`相关推荐广告:${adCount}`);
if (adCount !== 0) {
2022-10-29 11:42:12 +08:00
needProcessFlag = true;
}
}
let tIconMap = viewReplyMessage.tIcon;
for (const i in tIconMap) {
if (tIconMap[i] === null) {
// 解决tIcon的null is not an object问题
console.log(`tIconMap:${i}`);
delete tIconMap[i];
}
2022-10-29 11:42:12 +08:00
}
if (needProcessFlag) {
body = processNewBody(viewReplyType.encode(viewReplyMessage).finish());
2022-10-29 11:42:12 +08:00
}
} else {
$notification.post('bilibili-proto', "路径/请求方法匹配错误:", method + "," + url);
2022-10-29 11:42:12 +08:00
}
if (needProcessFlag) {
2022-10-29 11:42:12 +08:00
console.log(`${body.byteLength}---${body.buffer.byteLength}`);
if (isQuanX) {
$done({bodyBytes: body.buffer.slice(body.byteOffset, body.byteLength + body.byteOffset)});
2022-10-29 11:42:12 +08:00
} else {
$done({body});
2022-10-29 11:42:12 +08:00
}
} else {
$done({});
}
function processNewBody(unGzipBody) {
const gzipBody = pako.gzip(unGzipBody);
const length = gzipBody.length;
2022-10-29 11:42:12 +08:00
let merge = new Uint8Array(5 + length);
merge.set(Uint8Array.from([...binaryBody.slice(0, 2), (length >> 16) & 0xff, (length >> 8) & 0xff, length & 0xff]));
merge.set(gzipBody, 5);
2022-10-29 11:42:12 +08:00
return merge;
}