-
Notifications
You must be signed in to change notification settings - Fork 113
/
ipcjs_bilibili_bangumi_area_limit_hack_mobile.user.js
731 lines (693 loc) · 36.1 KB
/
ipcjs_bilibili_bangumi_area_limit_hack_mobile.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
// ==UserScript==
// @name 解除移动版B站区域限制
// @namespace http://tampermonkey.net/
// @version 0.4.3.4
// @description 通过替换获取视频地址接口的方式, 实现解除B站区域限制; 只对HTML5播放器生效;
// @author ipcjs
// @supportURL https://github.com/zzc10086
// @compatible chrome
// @compatible firefox
// @license MIT
// @require https://static.hdslb.com/js/md5.js
// @include *://m.bilibili.com/bangumi/play/ep*
// @include *://m.bilibili.com/bangumi/play/ss*
// @include *://m.bilibili.com/video/BV*
// @run-at document-start
// @grant none
// ==/UserScript==
/*
需要搭配User-Agnent Switcher这样的修改UA的插件.直接使用脚本会出现无法播放,视频流请求403错误
将视频的CDN域名UA改为IOS和PC平台的即可正常播放
*/
const log = console.log.bind(console, 'injector:')
function injector() {
if (document.getElementById('balh-injector-source')) {
log(`脚本已经注入过, 不需要执行`)
return
}
// @require https://static.hdslb.com/js/md5.js
GM_info.scriptMetaStr.replace(new RegExp('// @require\\s+https?:(//.*)'), (match, /*p1:*/url) => {
log('@require:', url)
let $script = document.createElement('script')
$script.className = 'balh-injector-require'
$script.setAttribute('type', 'text/javascript')
$script.setAttribute('src', url)
document.head.appendChild($script)
return match
})
let $script = document.createElement('script')
$script.id = 'balh-injector-source'
$script.appendChild(document.createTextNode(`
;(function(GM_info){
${scriptSource.toString()}
${scriptSource.name}('${GM_info.scriptHandler}.${injector.name}')
})(${JSON.stringify(GM_info)})
`))
document.head.appendChild($script)
log('注入完成')
}
if (!Object.getOwnPropertyDescriptor(window, 'XMLHttpRequest').writable) {
log('XHR对象不可修改, 需要把脚本注入到页面中', GM_info.script.name, location.href, document.readyState)
injector()
return
}
function scriptSource(invokeBy) {
let log = console.log.bind(console, 'injector:')
if (document.getElementById('balh-injector-source') && invokeBy === GM_info.scriptHandler) {
// 当前, 在Firefox+GM4中, 当返回缓存的页面时, 脚本会重新执行, 并且此时XMLHttpRequest是可修改的(为什么会这样?) + 页面中存在注入的代码
// 导致scriptSource的invokeBy直接是GM4...
log(`页面中存在注入的代码, 但invokeBy却等于${GM_info.scriptHandler}, 这种情况不合理, 终止脚本执行`)
return
}
if (document.readyState === 'uninitialized') { // Firefox上, 对于ifame中执行的脚本, 会出现这样的状态且获取到的href为about:blank...
log('invokeBy:', invokeBy, 'readState:', document.readyState, 'href:', location.href, '需要等待进入loading状态')
setTimeout(() => scriptSource(invokeBy + '.timeout'), 0) // 这里会暴力执行多次, 直到状态不为uninitialized...
return
}
/**
* 创建元素的快捷方法:
* 1. type, props, children
* 2. type, props, innerHTML
* 3. 'text', text
* @param type string, 标签名; 特殊的, 若为text, 则表示创建文字, 对应的t为文字的内容
* @param props object, 属性; 特殊的属性名有: className, 类名; style, 样式, 值为(样式名, 值)形式的object; event, 值为(事件名, 监听函数)形式的object;
* @param children array, 子元素; 也可以直接是html文本;
*/
const util_ui_element_creator = (type, props, children) => {
let elem = null;
if (type === "text") {
return document.createTextNode(props);
} else {
elem = document.createElement(type);
}
for (let n in props) {
if (n === "style") {
for (let x in props.style) {
elem.style[x] = props.style[x];
}
} else if (n === "className") {
elem.className = props[n];
} else if (n === "event") {
for (let x in props.event) {
elem.addEventListener(x, props.event[x]);
}
} else {
elem.setAttribute(n, props[n]);
}
}
if (children) {
if (typeof children === 'string') {
elem.innerHTML = children;
} else {
for (let i = 0; i < children.length; i++) {
if (children[i] != null)
elem.appendChild(children[i]);
}
}
}
return elem;
}
const _ = util_ui_element_creator
const util_cookie = (function () {
function getCookies() {
var map = document.cookie.split('; ').reduce(function (obj, item) {
var entry = item.split('=');
obj[entry[0]] = entry[1];
return obj;
}, {});
return map;
}
function getCookie(key) {
return getCookies()[key];
}
/**
* @param key key
* @param value 为undefined时, 表示删除cookie
* @param options 为undefined时, 表示过期时间为3年
* 为''时, 表示Session cookie
* 为数字时, 表示指定过期时间
* 为{}时, 表示指定所有的属性
* */
function setCookie(key, value, options) {
if (typeof options !== 'object') {
options = {
domain: '.bilibili.com',
path: '/',
'max-age': value === undefined ? 0 : (options === undefined ? 94608000 : options)
};
}
var c = Object.keys(options).reduce(function (str, key) {
return str + '; ' + key + '=' + options[key];
}, key + '=' + value);
document.cookie = c;
return c;
}
return new Proxy({ set: setCookie, get: getCookie, all: getCookies }, {
get: function (target, prop) {
if (prop in target) return target[prop]
return getCookie(prop)
},
set: function (target, prop, value) {
setCookie(prop, value)
return true
}
})
}())
const _raw = (str) => str.replace(/(\.|\?)/g, '\\$1')
const util_regex_url = (url) => new RegExp(`^(https?:)?//${_raw(url)}`)
const util_regex_url_path = (path) => new RegExp(`^(https?:)?//[\\w\\-\\.]+${_raw(path)}`)
const util_url_param = function (url, key) {
return (url.match(new RegExp('[?|&]' + key + '=(\\w+)')) || ['', ''])[1];
}
const util_safe_get = (code) => {
return eval(`
(()=>{
try{
return ${code}
}catch(e){
console.warn(e.toString())
return null
}
})()
`)
}
const balh_feature_area_limit_new = (function () {
let INITIAL_STATE
Object.defineProperty(window, '__INITIAL_STATE__', {
configurable: true,
enumerable: true,
get: ()=>{
if(INITIAL_STATE &&INITIAL_STATE.epInfo.rights){
INITIAL_STATE.epInfo.rights.area_limit=0;
if(INITIAL_STATE.epInfo.badge_info.text=='受限')INITIAL_STATE.epInfo.badge_info.text='';
INITIAL_STATE.epInfo.status=2
}
if(INITIAL_STATE &&INITIAL_STATE.epList.length>0){
for (let ep of [INITIAL_STATE.epInfo, ...INITIAL_STATE.epList]) {
if (ep.rights.area_limit === 1) {
ep.rights.area_limit = 0
if(ep.badge_info.text=='受限')ep.badge_info.text='';
}
if(ep.status === 13){
ep.status=2
}
}
}
return INITIAL_STATE
},
set: (value) => {
INITIAL_STATE=value
return true
}
})
})()
function replace_upos(data){
if(!(typeof data.code == "undefined"))data=data.result;
let replace_url;
let uposArr=[
["ks3u","https://upos-sz-mirrorks3.bilivideo.com"],
//https://upos-hz-mirrorks3u.acgvideo.com 金山CDN(403错误)
//https://upos-sz-mirrorks3.bilivideo.com 金山CDN
//https://upos-sz-mirrorks3c.bilivideo.com 金山CDN
["hw","https://upos-sz-mirrorhw.bilivideo.com"],
//https://upos-hz-mirrorhw.acgvideo.com 华为CDN(资源权限不足)
//https://upos-sz-mirrorhw.bilivideo.com 华为CDN
["xycdn","https://upos-hz-mirrorxycdn.acgvideo.com"],
//https://upos-hz-mirrorxycdn.acgvideo.com 迅雷CDN(证书错误)
["kodou","https://upos-sz-mirrorkodo.bilivideo.com"],
//https://upos-hz-mirrorkodou.acgvideo.com 七牛CDN
//https://upos-sz-mirrorkodo.bilivideo.com 七牛CDN
["cosu","https://upos-sz-mirrorcos.bilivideo.com"],
//https://upos-hz-mirrorcosu.acgvideo.com 腾讯CDN
//https://upos-sz-mirrorcos.bilivideo.com 腾讯CDN
["wcsu","https://upos-sz-mirrorwcs.bilivideo.com"],
//https://upos-hz-mirrorwcsu.acgvideo.com 网宿CDN
//https://upos-sz-mirrorwcs.bilivideo.com 网宿CDN
["bosu","https://upos-sz-mirrorbos.bilivideo.com"]
//https://upos-hz-mirrorbosu.acgvideo.com 百度CDN(403错误)
//https://upos-sz-mirrorbos.bilivideo.com 百度CDN(403错误)
];
//https://upos-hz-mirrorakam.akamaized.net AKAMAI_CDN(海外)
let upos_server=util_cookie.get("balh_");
if(upos_server&&upos_server!=""){
for(let i in uposArr){
if(uposArr[i][0]==upos_server){
replace_url=uposArr[i][1];
break;
}
}
if(data.dash){
for(let i in data.dash.audio){
data.dash.audio[i].baseUrl=data.dash.audio[i].baseUrl.replace(/http.*?upgcxcode/,replace_url+"/upgcxcode");
data.dash.audio[i].base_url=data.dash.audio[i].base_url.replace(/http.*?upgcxcode/,replace_url+"/upgcxcode");
}
for(let i in data.dash.video){
data.dash.video[i].baseUrl=data.dash.video[i].baseUrl.replace(/http.*?upgcxcode/,replace_url+"/upgcxcode");
data.dash.video[i].base_url=data.dash.video[i].base_url.replace(/http.*?upgcxcode/,replace_url+"/upgcxcode");
}
}else if(data.durl){
for(let i in data.durl){
data.durl[i].url= data.durl[i].url.replace(/http.*?upgcxcode/,replace_url+"/upgcxcode");
}
}
}
return data;
}
const util_promise_timeout = function (timeout) {
return new Promise((resolve, reject) => {
setTimeout(resolve, timeout);
})
}
const util_promise_condition = function (condition, promiseCreator, retryCount = Number.MAX_VALUE, interval = 1) {
const loop = (time) => {
if (!condition()) {
if (time < retryCount) {
return util_promise_timeout(interval).then(loop.bind(null, time + 1))
} else {
return Promise.reject(`util_promise_condition timeout, condition: ${condition.toString()}`)
}
} else {
return promiseCreator()
}
}
return loop(0)
}
const util_ajax = function (options) {
const creator = () => new Promise(function (resolve, reject) {
typeof options !== 'object' && (options = { url: options });
options.async === undefined && (options.async = true);
options.xhrFields === undefined && (options.xhrFields = { withCredentials: true });
options.success = function (data) {
resolve(data);
};
options.error = function (err) {
reject(err);
};
log('ajax:', options.url)
$.ajax(options);
})
return util_promise_condition(() => window.$, creator, 100, 100) // 重试 100 * 100 = 10s
}
//bv转av
const util_str_bv2aid = function (bv) {
var table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF';
var tr = {};
for (var i = 0; i < 58; ++i) {
tr[table[i]] = i;
}
var s = [11, 10, 3, 8, 4, 6];
var xor = 177451812;
var add = 8728348608;
var r = 0;
for (let i = 0; i < 6; ++i) {
r += tr[bv[s[i]]] * (Math.pow(58, i));
}
return String((r - add) ^ xor);
}
const balh_feature_area_limit = (function () {
//太大了,可能导致错过需要拦截的url,丢给页面自己加载吧
(()=>{
let bv = (location.pathname.match(/\/video\/(BV\w+)/) || ['', ''])[1]
if (bv) {
window.location.href="https://m.bilibili.com/video/av"+util_str_bv2aid(bv);
}
let $script = document.createElement('script')
$script.setAttribute('type', 'text/javascript')
$script.setAttribute('src', "//s2.hdslb.com/bfs/static/player/main/video.4c8e48ce.js?v=20200706")
document.head.appendChild($script)
})()
function isAreaLimitForPlayUrl(json) {
return ((json.code!==0 || json.message!== "success")&& json.message !== "不允许播放预览");
}
function isBangumi(season_type) {
log(`season_type: ${season_type}`)
// 1是动画
// 5是电视剧
// 2是电影
return season_type != null // 有season_type, 就是bangumi?
}
function isBangumiPage() {
return isBangumi(util_safe_get('window.__INITIAL_STATE__.epType || window.__INITIAL_STATE__.ssType'))
}
var bilibiliApis = (function () {
function AjaxException(message, code = 0/*用0表示未知错误*/) {
this.name = 'AjaxException'
this.message = message
this.code = code
}
function BilibiliApi(props) {
Object.assign(this, props);
}
BilibiliApi.prototype.asyncAjax = function (originUrl) {
return util_ajax(this.transToProxyUrl(originUrl))
.then(r => this.processProxySuccess(r))
.compose() // 出错时, 提示服务器连不上
}
var playurl_by_proxy = new BilibiliApi({
_asyncAjax: function (originUrl, bangumi) {
return util_ajax(this.transToProxyUrl(originUrl, bangumi))
.then(r => this.processProxySuccess(r, false))
},
transToProxyUrl: function (url, bangumi) {
let params = url.split('?')[1];
// 管他三七二十一, 强行将module=bangumi替换成module=pgc _(:3」∠)_
params = params.replace(/&?module=(\w+)/, '')
params += '&module=pgc'
return `https://bili-proxy.98e.org/BPplayurl.php?${params}`;
},
processProxySuccess: function (data, alertWhenError = true) {
// data有可能为null
if (data && data.code === -403) {
alert("代理服务器依旧被限制")
} else if (data === null || data.code) {
log(data);
if (alertWhenError) {
alert("获取播放地址失败")
} else {
return Promise.reject(new AjaxException(`服务器错误: ${JSON.stringify(data)}`, data ? data.code : 0))
}
}
return data;
}
})
const playurl = new BilibiliApi({
asyncAjax: function (originUrl) {
log('从代理服务器拉取视频地址中...')
return playurl_by_proxy._asyncAjax(originUrl) // 优先从代理服务器获取
.catch(e => {
if (e instanceof AjaxException) {
if (e.code === 1) { // code: 1 表示非番剧视频, 不能使用番剧视频参数
return playurl_by_proxy._asyncAjax(originUrl, false)
.catch(e2 => Promise.reject(e)) // 忽略e2, 返回原始错误e
} else if (e.code === 10004) { // code: 10004, 表示视频被隐藏, 一般添加module=bangumi参数可以拉取到视频
return playurl_by_proxy._asyncAjax(originUrl, true)
.catch(e2 => Promise.reject(e))
}
}
return Promise.reject(e)
})
.catch(e => {
return Promise.reject(e)
})
// 报错时, 延时1秒再发送错误信息
.catch(e => util_promise_timeout(1000).then(r => Promise.reject(e)))
.catch(e => {
let msg
if (typeof e === 'object' && e.statusText == 'error') {
alert( '代理服务器临时不可用')
}
alert("获取播放地址失败")
return Promise.reject(e)
})
.then(data => {
return replace_upos(data)
})
}
})
const pcPlayurl = new BilibiliApi({
asyncAjax: function (originUrl) {
log('从B站PC网页端服务器拉取视频地址中...')
return util_ajax(originUrl)
.then(data => {
if(!isAreaLimitForPlayUrl(data)){
return data
}else{
alert(data.message)
return Promise.reject(data)
}
})
.catch(e=>{
log('PC网页端播放地址获取失败')
return Promise.reject(e)
})
}
})
return {
_playurl: playurl,
_pcPlayurl:pcPlayurl,
};
})();
function addPlayer(playurl) {
if($("#flvPlay").length==0)$("#bofqi").html(_('video',{id:"flvPlay",style:{"z-index":101,float:"left",width:"100%",height: "100%"},controls:"ture",autoplay:"autoplay"}));
if(window.player){window.player.reset();window.player=dashjs.MediaPlayer().create()}else{window.player=dashjs.MediaPlayer().create()}
// window.player.setP2pType("xl-eg","//s1.hdslb.com/bfs/static/pcdnjs/pcdn-xldash-20.07.01.min.js")
window.player.initialize($("#flvPlay")[0],playurl.result.dash,false,true)
if($(".player-mask.relative").length!==0)$(".player-mask.relative").css("display","none")
if($(".no-source").length!==0)$(".no-source").css("display","none")
if($(".video-length").length!==0)$(".video-length").css("display","none")
$("#bofqi").css("display","")
}
// let playurllist=new Array();
// for(let i in playurl.result.durl){
// playurllist[i]={
// duration: playurl.result.durl[i].length,
// filesize: playurl.result.durl[i].size,
// url: playurl.result.durl[i].url
// };
// };
// if (flvjs.isSupported()) {
// window.player = flvjs.createPlayer({
// type: 'flv',
// url: playurl.result.durl[0].url,
// segments: playurllist
// });
// window.player.attachMediaElement(videoElement);
// window.player.load();
// window.player.play();
// }
// }
// return new DPlayer({
// container: document.getElementById('bofqi'),
// autoplay: true,
// theme: '#FADFA3',
// loop: false,
// lang: 'zh-cn',
// screenshot: false,
// hotkey: true,
// preload: 'auto',
// volume: 0.7,
// mutex: true,
// video: {
// url: playurl.result.durl[0].url,
// type:"auto",
// },
// pluginOptions: {
// flv: {
// type: "flv",
// segments:playurllist,
// },
// },
// });
(function injectXHR() {
log('XMLHttpRequest的描述符:', Object.getOwnPropertyDescriptor(window, 'XMLHttpRequest'))
let firstCreateXHR = true
window.XMLHttpRequest = new Proxy(window.XMLHttpRequest, {
construct: function (target, args) {
let container = {} // 用来替换responseText等变量
const dispatchResultTransformer = p => {
let event = {} // 伪装的event
return p
.then(r => {
container.readyState = 4
container.response = r
container.__onreadystatechange(event) // 直接调用会不会存在this指向错误的问题? => 目前没看到, 先这样(;¬_¬)
})
.catch(e => {
// 失败时, 让原始的response可以交付
container.__block_response = false
if (container.__response != null) {
container.readyState = 4
container.response = container.__response
container.__onreadystatechange(event) // 同上
}
})
}
return new Proxy(new target(...args), {
set: function (target, prop, value, receiver) {
if (prop === 'onreadystatechange') {
container.__onreadystatechange = value
let cb = value
value = function (event) {
if (target.readyState === 4) {
if (target.responseURL.match(util_regex_url('bangumi.bilibili.com/view/web_api/season/user/status'))
|| target.responseURL.match(util_regex_url('api.bilibili.com/pgc/view/web/season/user/status'))) {
log('/season/user/status:', target.responseText)
let json = JSON.parse(target.responseText)
let rewriteResult = false
if (json.code === 0 && json.result) {
if (json.result.area_limit !== 0) {
json.result.area_limit = 0 // 取消区域限制
rewriteResult = true
}
if (json.result.pay !== 1) {
json.result.pay = 1
rewriteResult = true
}
if (rewriteResult) {
container.responseText = JSON.stringify(json)
}
}
} else if (target.responseURL.match(util_regex_url('bangumi.bilibili.com/web_api/season_area'))) {
log('/season_area', target.responseText)
let json = JSON.parse(target.responseText)
if (json.code === 0 && json.result) {
if (json.result.play === 0) {
json.result.play = 1
container.responseText = JSON.stringify(json)
}
}
} else if (target.responseURL.match(util_regex_url('api.bilibili.com/x/web-interface/nav'))) {
const isFromReport = util_url_param(target.responseURL, 'from') === 'report'
let json = JSON.parse(target.responseText)
log('/x/web-interface/nav', (json.data && json.data.isLogin)
? { uname: json.data.uname, isLogin: json.data.isLogin, level: json.data.level_info.current_level, vipType: json.data.vipType, vipStatus: json.data.vipStatus, isFromReport: isFromReport }
: target.responseText)
if (json.code === 0 && !isFromReport // report时, 还是不伪装了...
) {
json.data.vipType = 2; // 类型, 年度大会员
json.data.vipStatus = 1; // 状态, 启用
container.responseText = JSON.stringify(json)
}
}else if (!window.__INITIAL_STATE__&&target.responseURL.match(util_regex_url('api.bilibili.com/pgc/view/web/h5/season'))){
//当返回脚本时wiwindow.__INITIAL_STATE__为空,从api中取个一样的放进去
let json=JSON.parse(target.responseText)
json.result.status=2
let epInfo
let ss=location.href.match(/[0-9]+/)
let is_ep=target.responseURL.match(/ep_id/)?true:false;
if(json.result.episodes){
json.result.episodes.forEach((episode,index,episodes)=>{
episode.status=2
if (episode.rights.area_limit === 1) {
episode.rights.area_limit = 0
if(episode.epStatus === 13){
episode.badge='会员'
episode.badgeColor='#FB7299'
}
if(episode.badge=='受限')ep.badge='';
}
if(is_ep){
//ss666形式下获取aid,cid
if(episode.id==ss){
epInfo=episode
}
}else{
//ep666形式下获取aid,cid
if(json.result.season_id==ss){
epInfo=episode
}
}
})
}
if(!window.__INITIAL_STATE__)window.__INITIAL_STATE__={"epInfo":epInfo,"epList":json.result.episodes,firstGet:false}
container.responseText = JSON.stringify(json)
}else if (container.__url.match(util_regex_url('api.bilibili.com/pgc/player/web/playurl/html5'))
&& !util_url_param(container.__url, 'balh_ajax')) {
log('/pgc/player/web/playurl')
// debugger
if(window.__INITIAL_STATE__&&window.__INITIAL_STATE__.epList){
$(".ep-list-pre-container.no-wrap li").each((index,li)=>{
if(li.className=="episode-item item-lg single-line cur"){
window.__INITIAL_STATE__.epInfo=window.__INITIAL_STATE__.epList[index]
}
})
}
let url = container.__url
url=url.replace(/ep_id=.*/,"cid="+window.__INITIAL_STATE__.epInfo.cid+"&avid="+window.__INITIAL_STATE__.epInfo.aid+"&otype=json&qn=112&fnver=0&fnval=16")
if(isAreaLimitForPlayUrl(JSON.parse(target.responseText))){
bilibiliApis._playurl.asyncAjax(url)
.then(data => {
if (data.code == "0") {
data = {
code: 0,
result: data,
message: "0",
}
}
log('/pgc/player/web/playurl', 'proxy_biliplus(redirect)', data)
addPlayer(data)
return data
})
.catch(data =>{
container.__block_response = true
dispatchResultTransformer()
})
}else{
url=url.replace(/\/html5/,"")
bilibiliApis._pcPlayurl.asyncAjax(url)
.then(data => {
log('/pgc/player/web/playurl', 'proxy_bili(redirect)', data)
addPlayer(data)
return data
})
.catch(data =>{
container.__block_response = true
dispatchResultTransformer()
})
}
}
if (container.__block_response) {
// 屏蔽并保存response
container.__response = target.response
return
}
}
// 这里的this是原始的xhr, 在container.responseText设置了值时需要替换成代理对象
cb.apply(container.responseText ? receiver : this, arguments)
}
}
target[prop] = value
return true
},
get: function (target, prop, receiver) {
if (prop in container) return container[prop]
let value = target[prop]
if (typeof value === 'function') {
let func = value
// open等方法, 必须在原始的xhr对象上才能调用...
value = function () {
if (prop === 'open') {
container.__method = arguments[0]
container.__url = arguments[1]
} else if (prop === 'send') {
let dispatchResultTransformerCreator = () => {
container.__block_response = true
return dispatchResultTransformer
}
}
return func.apply(target, arguments)
}
}
return value
}
})
}
})
})()
})()
//触发平台检查发回页面是脚本,会添加失败,所以用定时器
setTimeout(()=>{
if($("upos-server").length<1){
$(".media-option-tab").append(_('select', {
class: 'upos-server',
event: {
change: function () {
util_cookie.set("balh_",$(".upos-server option:selected").val(),)
location.reload()
}
}
}, [
_('option', { value: "" }, [_('text', '不替换')]),
_('option', { value: "ks3u" }, [_('text', 'ks3(金山)')]),
_('option', { value: "kodou" }, [_('text', 'kodo(七牛)')]),
_('option', { value: "cosu" }, [_('text', 'cos(腾讯)')]),
_('option', { value: "bosu" }, [_('text', 'bos(百度)')]),
_('option', { value: "wcsu" }, [_('text', 'wcs(网宿)')]),
_('option', { value: "xycdn" }, [_('text', 'xycdn(迅雷)')]),
_('option', { value: "hw" }, [_('text', 'hw(251)')]),
]))
$(".upos-server").val(util_cookie.get("balh_"))
}
},2000)
}
scriptSource(GM_info.scriptHandler);