This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
forked from SeaLoong/BLRHH
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Bilibili直播间挂机助手-魔改.user.js
4221 lines (4187 loc) · 438 KB
/
Bilibili直播间挂机助手-魔改.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
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name Bilibili直播间挂机助手-魔改
// @namespace SeaLoong
// @version 2.4.6.9
// @description Bilibili直播间自动签到,领瓜子,参加抽奖,完成任务,送礼,自动点亮勋章,挂小心心等,包含恶意代码
// @author SeaLoong,lzghzr,pjy612
// @updateURL https://raw.githubusercontent.com/pjy612/Bilibili-LRHH/master/Bilibili%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B-%E9%AD%94%E6%94%B9.user.js
// @downloadURL https://raw.githubusercontent.com/pjy612/Bilibili-LRHH/master/Bilibili%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B-%E9%AD%94%E6%94%B9.user.js
// @homepageURL https://github.com/pjy612/Bilibili-LRHH
// @supportURL https://github.com/pjy612/Bilibili-LRHH/issues
// @include /https?:\/\/live\.bilibili\.com\/[blanc\/]?[^?]*?\d+\??.*/
// @include /https?:\/\/api\.live\.bilibili\.com\/_.*/
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require https://cdn.jsdelivr.net/gh/pjy612/Bilibili-LRHH@master/BilibiliAPI_Plus.js
// @require https://cdn.jsdelivr.net/gh/pjy612/Bilibili-LRHH@master/OCRAD.min.js
// @run-at document-idle
// @license MIT License
// @connect passport.bilibili.com
// @connect api.live.bilibili.com
// @grant GM_xmlhttpRequest
// ==/UserScript==
/*
如果 jsdelivr 不可用时,推荐换Host 并调整为以下支持库源
// @require https://raw.githubusercontent.com/pjy612/Bilibili-LRHH/master/BilibiliAPI_Plus.js
// @require https://raw.githubusercontent.com/pjy612/Bilibili-LRHH/master/OCRAD.min.js
// @require https://raw.githubusercontent.com/lzghzr/TampermonkeyJS/master/libBilibiliToken/libBilibiliToken.user.js
*/
/*
如果 raw.githubusercontent.com 无法访问 请自行尝试修改 Hosts 后 再尝试访问
151.101.76.133 raw.githubusercontent.com
*/
//https://cdn.jsdelivr.net/gh/lzghzr/TampermonkeyJS@master/libBilibiliToken/libBilibiliToken.user.js
class BilibiliToken {
constructor() {
this._W = typeof unsafeWindow === 'undefined' ? window : unsafeWindow;
this.biliLocalId = BilibiliToken.biliLocalId;
this.buvid = BilibiliToken.buvid;
this.deviceId = this.biliLocalId;
this.fingerprint = BilibiliToken.fingerprint;
this.guid = this.buvid;
this.localFingerprint = this.fingerprint;
this.localId = this.buvid;
this.headers = {
'User-Agent': 'Mozilla/5.0 BiliTV/1.2.4.1 ([email protected])',
'APP-KEY': BilibiliToken.mobiApp,
'Buvid': this.buvid,
'env': 'prod'
};
}
static get biliLocalId() { return this.RandomID(20); }
static get buvid() { return this.RandomID(37).toLocaleUpperCase(); }
static get deviceId() { return this.biliLocalId; }
static get fingerprint() { return this.RandomID(62); }
static get guid() { return this.buvid; }
static get localFingerprint() { return this.fingerprint; }
static get localId() { return this.buvid; }
static get TS() { return Math.floor(Date.now() / 1000); }
static get RND() { return this.RandomNum(9); }
static RandomNum(length) {
const words = '0123456789';
let randomNum = '';
randomNum += words[Math.floor(Math.random() * 9) + 1];
for (let i = 0; i < length - 1; i++)
randomNum += words[Math.floor(Math.random() * 10)];
return +randomNum;
}
static RandomID(length) {
const words = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
let randomID = '';
randomID += words[Math.floor(Math.random() * 61) + 1];
for (let i = 0; i < length - 1; i++)
randomID += words[Math.floor(Math.random() * 62)];
return randomID;
}
static get headers() {
return {
'User-Agent': 'Mozilla/5.0 BiliTV/1.2.4.1 ([email protected])',
'APP-KEY': this.mobiApp,
'Buvid': this.buvid,
'env': 'prod'
};
}
static get loginQuery() {
const biliLocalId = this.biliLocalId;
const buvid = this.buvid;
const fingerprint = this.fingerprint;
return `appkey=${this.loginAppKey}&bili_local_id=${biliLocalId}&build=${this.build}&buvid=${buvid}&channel=${this.channel}&device=${biliLocalId}\
&device_id=${this.deviceId}&device_name=${this.deviceName}&device_platform=${this.devicePlatform}&fingerprint=${fingerprint}&guid=${buvid}\
&local_fingerprint=${fingerprint}&local_id=${buvid}&mobi_app=${this.mobiApp}&networkstate=${this.networkstate}&platform=${this.platform}`;
}
get loginQuery() {
const biliLocalId = this.biliLocalId;
const buvid = this.buvid;
const fingerprint = this.fingerprint;
return `appkey=${BilibiliToken.loginAppKey}&bili_local_id=${biliLocalId}&build=${BilibiliToken.build}&buvid=${buvid}&channel=${BilibiliToken.channel}&device=${biliLocalId}\
&device_id=${this.deviceId}&device_name=${BilibiliToken.deviceName}&device_platform=${BilibiliToken.devicePlatform}&fingerprint=${fingerprint}&guid=${buvid}\
&local_fingerprint=${fingerprint}&local_id=${buvid}&mobi_app=${BilibiliToken.mobiApp}&networkstate=${BilibiliToken.networkstate}&platform=${BilibiliToken.platform}`;
}
static signQuery(params, ts = true, secretKey = this.__secretKey) {
let paramsSort = params;
if (ts)
paramsSort = `${params}&ts=${this.TS}`;
paramsSort = paramsSort.split('&').sort().join('&');
const paramsSecret = paramsSort + secretKey;
const paramsHash = md5(paramsSecret);
return `${paramsSort}&sign=${paramsHash}`;
}
static signLoginQuery(params) {
const paramsBase = params === undefined ? this.loginQuery : `${params}&${this.loginQuery}`;
return this.signQuery(paramsBase, true, this.__loginSecretKey);
}
signLoginQuery(params) {
const paramsBase = params === undefined ? this.loginQuery : `${params}&${this.loginQuery}`;
return BilibiliToken.signQuery(paramsBase, true, BilibiliToken.__loginSecretKey);
}
async getAuthCode() {
const authCode = await BilibiliToken.XHR({
GM: true,
anonymous: true,
method: 'POST',
url: 'https://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code',
data: this.signLoginQuery(),
responseType: 'json',
headers: this.headers
});
if (authCode !== undefined && authCode.response.status === 200 && authCode.body.code === 0)
return authCode.body.data.auth_code;
return console.error('getAuthCode', authCode);
}
async qrcodeConfirm(authCode, csrf) {
const confirm = await BilibiliToken.XHR({
GM: true,
method: 'POST',
url: 'https://passport.bilibili.com/x/passport-tv-login/h5/qrcode/confirm',
data: `auth_code=${authCode}&csrf=${csrf}`,
responseType: 'json',
headers: this.headers
});
if (confirm !== undefined && confirm.response.status === 200 && confirm.body.code === 0)
return confirm.body.data.gourl;
return console.error('qrcodeConfirm', confirm);
}
async qrcodePoll(authCode) {
const poll = await BilibiliToken.XHR({
GM: true,
anonymous: true,
method: 'POST',
url: 'https://passport.bilibili.com/x/passport-tv-login/qrcode/poll',
data: this.signLoginQuery(`auth_code=${authCode}`),
responseType: 'json',
headers: this.headers
});
if (poll !== undefined && poll.response.status === 200 && poll.body.code === 0)
return poll.body.data;
return console.error('qrcodePoll', poll);
}
async getToken() {
const cookie = this._W.document.cookie.match(/bili_jct=(?<csrf>.*?);/);
debugger
if (cookie === null || cookie.groups === undefined)
return console.error('getToken', 'cookie获取失败');
const csrf = cookie.groups['csrf'];
const authCode = await this.getAuthCode();
if (authCode === undefined)
return;
const confirm = await this.qrcodeConfirm(authCode, csrf);
if (confirm === undefined)
return;
const token = await this.qrcodePoll(authCode);
if (token === undefined)
return;
return token;
}
static XHR(XHROptions) {
return new Promise(resolve => {
const onerror = (error) => {
console.error(GM_info.script.name, error);
resolve(undefined);
};
if (XHROptions.GM) {
if (XHROptions.method === 'POST') {
if (XHROptions.headers === undefined)
XHROptions.headers = {};
if (XHROptions.headers['Content-Type'] === undefined)
XHROptions.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
}
XHROptions.timeout = 30 * 1000;
XHROptions.onload = res => resolve({ response: res, body: res.response || res.responseText });
XHROptions.onerror = onerror;
XHROptions.ontimeout = onerror;
GM_xmlhttpRequest(XHROptions);
}
else {
const xhr = new XMLHttpRequest();
xhr.open(XHROptions.method, XHROptions.url);
if (XHROptions.method === 'POST' && xhr.getResponseHeader('Content-Type') === null)
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
if (XHROptions.cookie)
xhr.withCredentials = true;
if (XHROptions.responseType !== undefined)
xhr.responseType = XHROptions.responseType;
xhr.timeout = 30 * 1000;
xhr.onload = ev => {
const res = ev.target;
resolve({ response: res, body: res.response || res.responseText });
};
xhr.onerror = onerror;
xhr.ontimeout = onerror;
xhr.send(XHROptions.data);
}
});
}
}
BilibiliToken.__loginSecretKey = '59b43e04ad6965f34319062b478f83dd';
BilibiliToken.loginAppKey = '4409e2ce8ffd12b8';
BilibiliToken.__secretKey = '560c52ccd288fed045859ed18bffd973';
BilibiliToken.appKey = '1d8b6e7d45233436';
BilibiliToken.build = '102401';
BilibiliToken.channel = 'master';
BilibiliToken.device = 'Sony';
BilibiliToken.deviceName = 'J9110';
BilibiliToken.devicePlatform = 'Android10SonyJ9110';
BilibiliToken.mobiApp = 'android_tv_yst';
BilibiliToken.networkstate = 'wifi';
BilibiliToken.platform = 'android';
(function ($) {
'use strict';
function safeAdd(x, y) {
var lsw = (x & 0xffff) + (y & 0xffff);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xffff);
}
function bitRotateLeft(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
function md5cmn(q, a, b, x, s, t) {
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
}
function md5ff(a, b, c, d, x, s, t) {
return md5cmn((b & c) | (~b & d), a, b, x, s, t);
}
function md5gg(a, b, c, d, x, s, t) {
return md5cmn((b & d) | (c & ~d), a, b, x, s, t);
}
function md5hh(a, b, c, d, x, s, t) {
return md5cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5ii(a, b, c, d, x, s, t) {
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
}
function binlMD5(x, len) {
x[len >> 5] |= 0x80 << len % 32;
x[(((len + 64) >>> 9) << 4) + 14] = len;
var i;
var olda;
var oldb;
var oldc;
var oldd;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for (i = 0; i < x.length; i += 16) {
olda = a;
oldb = b;
oldc = c;
oldd = d;
a = md5ff(a, b, c, d, x[i], 7, -680876936);
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
b = md5gg(b, c, d, a, x[i], 20, -373897302);
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
d = md5hh(d, a, b, c, x[i], 11, -358537222);
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
a = md5ii(a, b, c, d, x[i], 6, -198630844);
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
a = safeAdd(a, olda);
b = safeAdd(b, oldb);
c = safeAdd(c, oldc);
d = safeAdd(d, oldd);
}
return [a, b, c, d];
}
function binl2rstr(input) {
var i;
var output = '';
var length32 = input.length * 32;
for (i = 0; i < length32; i += 8) {
output += String.fromCharCode((input[i >> 5] >>> i % 32) & 0xff);
}
return output;
}
function rstr2binl(input) {
var i;
var output = [];
output[(input.length >> 2) - 1] = undefined;
for (i = 0; i < output.length; i += 1) {
output[i] = 0;
}
var length8 = input.length * 8;
for (i = 0; i < length8; i += 8) {
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32;
}
return output;
}
function rstrMD5(s) {
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
}
function rstrHMACMD5(key, data) {
var i;
var bkey = rstr2binl(key);
var ipad = [];
var opad = [];
var hash;
ipad[15] = opad[15] = undefined;
if (bkey.length > 16) {
bkey = binlMD5(bkey, key.length * 8);
}
for (i = 0; i < 16; i += 1) {
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5c5c5c5c;
}
hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
return binl2rstr(binlMD5(opad.concat(hash), 512 + 128));
}
function rstr2hex(input) {
var hexTab = '0123456789abcdef';
var output = '';
var x;
var i;
for (i = 0; i < input.length; i += 1) {
x = input.charCodeAt(i);
output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f);
}
return output;
}
function str2rstrUTF8(input) {
return unescape(encodeURIComponent(input));
}
function rawMD5(s) {
return rstrMD5(str2rstrUTF8(s));
}
function hexMD5(s) {
return rstr2hex(rawMD5(s));
}
function rawHMACMD5(k, d) {
return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d));
}
function hexHMACMD5(k, d) {
return rstr2hex(rawHMACMD5(k, d));
}
function md5(string, key, raw) {
if (!key) {
if (!raw) {
return hexMD5(string);
}
return rawMD5(string);
}
if (!raw) {
return hexHMACMD5(key, string);
}
return rawHMACMD5(key, string);
}
$.md5 = md5;
})(this);
(function BLRHH_Plus() {
'use strict';
const NAME = 'BLRHH-Plus';
const VERSION = '2.4.6.9';
try {
var tmpcache = JSON.parse(localStorage.getItem(`${NAME}_CACHE`));
const t = Date.now() / 1000;
if (t - tmpcache.unique_check >= 0 && t - tmpcache.unique_check <= 60) {
console.error('魔改脚本重复运行')
return;
}
} catch (e) {}
let scriptRuning = false;
let API;
let TokenUtil;
let Token;
const window = typeof unsafeWindow === 'undefined' ? window : unsafeWindow;
const isSubScript = () => window.frameElement && window.parent[NAME] && window.frameElement[NAME];
const DEBUGMODE = false || window.top.localStorage.getItem('BLRHH-DEBUG');
const DEBUG = (sign, ...data) => {
if (!DEBUGMODE) return;
let d = new Date();
d =
`[${NAME}]${(isSubScript() ? 'SubScript:' : '')}[${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}:${d.getMilliseconds()}]`;
if (data.length === 1) console.debug(d, `${sign}:`, data[0]);
else console.debug(d, `${sign}:`, data);
};
let CONFIG;
let CACHE;
let Info = {
short_id: undefined,
roomid: undefined,
uid: undefined,
ruid: undefined,
rnd: undefined,
csrf_token: undefined,
visit_id: undefined,
silver: undefined,
gold: undefined,
mobile_verify: undefined,
identification: undefined,
gift_list: undefined,
gift_list_str: '礼物对照表',
blocked: false,
awardBlocked: false,
appToken: undefined
};
const getAccessToken = async () => {
if (Token && TokenUtil) {
const userToken = await Token.getToken();
if (userToken === undefined) {
console.error('未获取到移动端token,部分功能可能失效');
}
return userToken;
}
return null;
};
const tz_offset = new Date().getTimezoneOffset() + 480;
const ts_s = () => Math.round(ts_ms() / 1000);
const ts_ms = () => Date.now();
const getCookie = (name) => {
let arr;
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
if ((arr = document.cookie.match(reg))) {
return unescape(arr[2]);
} else {
return null;
}
};
const delayCall = (callback, delay = 10e3) => {
const p = $.Deferred();
setTimeout(() => {
const t = callback();
if (t && t.then) t.then((arg1, arg2, arg3, arg4, arg5, arg6) => p.resolve(arg1, arg2, arg3,
arg4, arg5, arg6));
else p.resolve();
}, delay);
return p;
};
const checkNewDay = (ts) => {
// 检查是否为新的一天,以UTC+8为准
const t = new Date(ts);
t.setMinutes(t.getMinutes() + tz_offset);
t.setHours(0, 0, 0, 0);
const d = new Date();
d.setMinutes(t.getMinutes() + tz_offset);
return (d - t > 86400e3);
};
const runTomorrow = (callback,hours = 0) => {
const t = new Date();
t.setMinutes(t.getMinutes() + tz_offset);
t.setDate(t.getDate() + 1);
t.setHours(hours, 1, 0, 0);
t.setMinutes(t.getMinutes() - tz_offset);
setTimeout(callback, t - ts_ms());
DEBUG('runTomorrow', t.toString());
};
if (!isSubScript()) {
const runUntilSucceed = (callback, delay = 0, period = 100) => {
setTimeout(() => {
if (!callback()) runUntilSucceed(callback, period, period);
}, delay);
};
const addCSS = (context) => {
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = context;
document.getElementsByTagName('head')[0].appendChild(style);
};
const Essential = {
init: () => {
return Essential.Toast.init().then(() => {
return Essential.AlertDialog.init().then(() => {
return Essential.Config.init().then(() => {
Essential.DataSync.init();
Essential.Cache.load();
Essential.Config.load();
});
});
});
},
Toast: {
init: () => {
try {
const toastList = [];
window.toast = (msg, type = 'info', timeout = 3e3) => {
let d = new Date().toLocaleTimeString();
switch (type) {
case 'success':
case 'info':
console.info(`[${NAME}][${d}]${msg}`);
break;
case 'caution':
console.warn(`[${NAME}][${d}]${msg}`);
break;
case 'error':
console.error(`[${NAME}][${d}]${msg}`);
break;
default:
type = 'info';
console.log(`[${NAME}][${d}]${msg}`);
}
if (CONFIG && !CONFIG.SHOW_TOAST) return;
const a = $(
`<div class="link-toast ${type} fixed"><span class="toast-text">${msg}</span></div>`
)[0];
document.body.appendChild(a);
a.style.top = (document.body.scrollTop + toastList.length * 40 + 10) + 'px';
a.style.left = (document.body.offsetWidth + document.body.scrollLeft - a.offsetWidth -
5) + 'px';
toastList.push(a);
setTimeout(() => {
a.className += ' out';
setTimeout(() => {
toastList.shift();
toastList.forEach((v) => {
v.style.top = (parseInt(v.style.top, 10) -
40) + 'px';
});
$(a).remove();
}, 200);
}, timeout);
};
return $.Deferred().resolve();
} catch (err) {
console.error(`[${NAME}]初始化浮动提示时出现异常`);
console.error(`[${NAME}]`, err);
return $.Deferred().reject();
}
}
}, // Need Init
AlertDialog: {
init: () => {
try {
const div_background = $(`<div id="${NAME}_alertdialog"/>`);
div_background[0].style =
'display: table;position: fixed;height: 100%;width: 100%;top: 0;left: 0;font-size: 12px;z-index: 10000;background-color: rgba(0,0,0,.5);';
const div_position = $('<div/>');
div_position[0].style = 'display: table-cell;vertical-align: middle;';
const div_style = $('<div/>');
div_style[0].style =
'position: relative;top: 50%;width: 40%;padding: 16px;border-radius: 5px;background-color: #fff;margin: 0 auto;';
div_position.append(div_style);
div_background.append(div_position);
const div_title = $('<div/>');
div_title[0].style = 'position: relative;padding-bottom: 12px;';
const div_title_span = $('<span>提示</span>');
div_title_span[0].style = 'margin: 0;color: #23ade5;font-size: 16px;';
div_title.append(div_title_span);
div_style.append(div_title);
const div_content = $('<div/>');
div_content[0].style =
'display: inline-block;vertical-align: top;font-size: 14px;overflow: auto;height: 300px;';
div_style.append(div_content);
const div_button = $('<div/>');
div_button[0].style = 'position: relative;height: 32px;margin-top: 12px;';
div_style.append(div_button);
const button_ok = $('<button><span>确定</span></button>');
button_ok[0].style =
'position: absolute;height: 100%;min-width: 68px;right: 0;background-color: #23ade5;color: #fff;border-radius: 4px;font-size: 14px;border: 0;cursor: pointer;';
div_button.append(button_ok);
window.alertdialog = (title, content) => {
div_title_span.html(title);
div_content.html(content);
button_ok.click(() => {
$(`#${NAME}_alertdialog`).remove();
});
$('body > .link-popup-ctnr').first().append(div_background);
};
return $.Deferred().resolve();
} catch (err) {
window.toast('初始化帮助界面时出现异常', 'error');
console.error(`[${NAME}]`, err);
return $.Deferred().reject();
}
}
}, // Need Init After Toast.init
Config: {
CONFIG_DEFAULT: {
DD_BP: true,
DD_BP_CONFIG:{
BP_KEY: "",
DM_STORM: true,
},
AUTO_SIGN: true,
AUTO_TREASUREBOX: false,
AUTO_GROUP_SIGN: true,
MOBILE_HEARTBEAT: false,
AUTO_LOTTERY: true,
AUTO_LOTTERY_CONFIG: {
SLEEP_RANGE: "",
RANK_TOP:false,
GIFT_LOTTERY: true,
GIFT_LOTTERY_CONFIG: {
REFRESH_INTERVAL: 0
},
GUARD_AWARD: true,
GUARD_AWARD_CONFIG: {
LISTEN_NUMBER: 1,
CHANGE_ROOM_INTERVAL: 60
},
PK_AWARD: true,
MATERIAL_OBJECT_LOTTERY: true,
MATERIAL_OBJECT_LOTTERY_CONFIG: {
CHECK_INTERVAL: 10,
IGNORE_QUESTIONABLE_LOTTERY: true
},
STORM: false,
STORM_CONFIG: {
NO_REAL_CHECK: false,
STORM_MAX_TIME: 20,
STORM_ONE_LIMIT: 120,
},
HIDE_POPUP: true
},
AUTO_TASK: true,
AUTO_GIFT: false,
AUTO_GIFT_CONFIG: {
ROOMID: [0],
EXCLUDE_ROOMID: [0],
GIFT_INTERVAL: 10,
GIFT_LIMIT: 86400,
GIFT_SORT: true,
AUTO_LIGHT: true,
AUTO_LIGHT_LIMIT_LEVEL:10,
SEND_ALL: false
},
SILVER2COIN: false,
AUTO_DAILYREWARD: true,
AUTO_DAILYREWARD_CONFIG: {
LOGIN: true,
WATCH: true,
COIN: false,
COIN_CONFIG: {
NUMBER: 5
},
SHARE: true
},
SHOW_TOAST: true
},
NAME: {
DD_BP: 'BiliPush推送',
DD_BP_CONFIG:{
BP_KEY: 'Key',
DM_STORM: 'DD弹幕风暴',
},
AUTO_SIGN: '自动签到',
AUTO_TREASUREBOX: '自动领取银瓜子',
AUTO_GROUP_SIGN: '自动应援团签到',
MOBILE_HEARTBEAT: '移动端心跳',
AUTO_LOTTERY: '自动抽奖',
AUTO_LOTTERY_CONFIG: {
SLEEP_RANGE: '休眠时间',
RANK_TOP: '小时榜',
GIFT_LOTTERY: '礼物抽奖',
GIFT_LOTTERY_CONFIG: {
REFRESH_INTERVAL: '刷新间隔'
},
GUARD_AWARD: '舰队领奖',
GUARD_AWARD_CONFIG: {
LISTEN_NUMBER: '监听倍数',
CHANGE_ROOM_INTERVAL: '换房间隔'
},
PK_AWARD: '乱斗领奖',
MATERIAL_OBJECT_LOTTERY: '实物抽奖',
MATERIAL_OBJECT_LOTTERY_CONFIG: {
CHECK_INTERVAL: '检查间隔',
IGNORE_QUESTIONABLE_LOTTERY: '忽略存疑的抽奖'
},
STORM: '节奏风暴',
STORM_CONFIG: {
NO_REAL_CHECK: '非实名模式*',
STORM_MAX_TIME: '最大持续时间',
STORM_ONE_LIMIT: '尝试间隔',
},
HIDE_POPUP: '隐藏抽奖提示框'
},
AUTO_TASK: '自动完成任务',
AUTO_GIFT: '自动送礼物',
AUTO_GIFT_CONFIG: {
ROOMID: '优先房间号',
EXCLUDE_ROOMID: '排除房间号',
GIFT_INTERVAL: '检查间隔(分钟)',
GIFT_SORT: '优先高等级',
GIFT_LIMIT: '到期时间(秒)',
AUTO_LIGHT: '自动点亮勋章',
AUTO_LIGHT_LIMIT_LEVEL: '点亮最低等级线',
SEND_ALL: '送满全部勋章'
},
SILVER2COIN: '银瓜子换硬币',
AUTO_DAILYREWARD: '自动每日奖励',
AUTO_DAILYREWARD_CONFIG: {
LOGIN: '登录',
WATCH: '观看',
COIN: '投币',
COIN_CONFIG: {
NUMBER: '数量'
},
SHARE: '分享'
},
SHOW_TOAST: '显示浮动提示'
},
PLACEHOLDER: {
DD_BP_CONFIG:{
BP_KEY: 'key',
},
AUTO_LOTTERY_CONFIG: {
SLEEP_RANGE: '时间范围03:00-08:00',
GIFT_LOTTERY_CONFIG: {
REFRESH_INTERVAL: '单位(分钟)'
},
GUARD_AWARD_CONFIG: {
LISTEN_NUMBER: '1~5,默认1',
CHANGE_ROOM_INTERVAL: '单位(分钟)'
},
MATERIAL_OBJECT_LOTTERY_CONFIG: {
CHECK_INTERVAL: '单位(分钟)'
},
STORM_CONFIG: {
STORM_MAX_TIME: '单位(秒)',
STORM_ONE_LIMIT: '单位(毫秒)',
},
},
AUTO_GIFT_CONFIG: {
ROOMID: '为0不送礼',
GIFT_DEFAULT: '为空默认不送',
GIFT_ALLOWED: '为空允许所有'
}
},
HELP: {
DD_BP: '魔改助手核心监控,启用后由服务器推送全区礼物/舰队/PK(但需要验证使用者身份并带有DD传送门等附加功能)',
DD_BP_CONFIG:{
DM_STORM: 'DD弹幕风暴(娱乐功能),配合DD传送门进行人力节奏风暴,用于活跃直播间气氛。',
},
MOBILE_HEARTBEAT: '发送移动端心跳数据包,可以完成双端观看任务',
AUTO_LOTTERY: '设置是否自动参加抽奖功能,包括礼物抽奖、活动抽奖、实物抽奖<br>会占用更多资源并可能导致卡顿,且有封号风险',
AUTO_LOTTERY_CONFIG: {
SLEEP_RANGE: '休眠时间范围,英文逗号分隔<br>例如:<br>3:00-8:00,16:50-17:30<br>表示 3:00-8:00和16:50-17:30不进行礼物检测。<br>小时为当天只能为0-23,如果要转钟请单独配置aa:aa-23:59,00:00-bb:bb',
RANK_TOP:'自动扫描小时榜',
GIFT_LOTTERY: '包括小电视、摩天大楼、C位光环及其他可以通过送礼触发广播的抽奖<br>内置几秒钟的延迟',
GIFT_LOTTERY_CONFIG: {
REFRESH_INTERVAL: '设置页面自动刷新的时间间隔,设置为0则不启用,单位为分钟<br>太久导致页面崩溃将无法正常运行脚本'
},
GUARD_AWARD_CONFIG: {
LISTEN_NUMBER: '设置在各大分区中的每一个分区监听的直播间的数量,1~5之间的一个整数<br>可能导致占用大量内存或导致卡顿',
CHANGE_ROOM_INTERVAL: '设置在多久之后改变监听的房间,单位为分钟,0表示不改变'
},
MATERIAL_OBJECT_LOTTERY: '部分房间设有实物奖励抽奖,脚本使用穷举的方式检查是否有实物抽奖<br>请注意中奖后记得及时填写相关信息领取实物奖励',
MATERIAL_OBJECT_LOTTERY_CONFIG: {
CHECK_INTERVAL: '每次穷举实物抽奖活动ID的时间间隔,单位为分钟',
IGNORE_QUESTIONABLE_LOTTERY: '对部分实物抽奖的标题存在疑问,勾选后不参加这部分抽奖'
},
STORM: '尝试参与节奏风暴<br>如果出现验证码提示的话请尝试实名制后再试',
STORM_CONFIG: {
NO_REAL_CHECK:'使用移动端模式去抢风暴,不用实名(但是可能造成用户大会员异常冻结,自行取舍)',
STORM_MAX_TIME: '单个风暴最大尝试时间(不推荐超过90)',
STORM_ONE_LIMIT: '单个风暴参与次数间隔(毫秒)',
},
HIDE_POPUP: '隐藏位于聊天框下方的抽奖提示框<br>注意:脚本参加抽奖后,部分抽奖仍然可以手动点击参加,为避免小黑屋,不建议点击'
},
AUTO_GIFT_CONFIG: {
ROOMID: '数组,优先送礼物的直播间ID(即地址中live.bilibili.com/后面的数字), 设置为0则无优先房间,小于0也视为0(因为你没有0的勋章)<br>例如:17171,21438956<br>不管[优先高等级]如何设置,会根据[送满全部勋章](补满或者只消耗当日到期)条件去优先送17171的,再送21438956<br>之后根据[优先高等级]决定送高级还是低级',
EXCLUDE_ROOMID: '数组,排除送礼的直播间ID(即地址中live.bilibili.com/后面的数字),填写的直播间不会自动送礼',
GIFT_INTERVAL: '检查间隔(分钟)',
GIFT_SORT: '打钩优先赠送高等级勋章,不打勾优先赠送低等级勋章',
GIFT_LIMIT: '到期时间范围(秒),86400为1天,时间小于1天的会被送掉',
GIFT_DEFAULT: () => (`设置默认送的礼物类型编号,多个请用英文逗号(,)隔开,为空则表示默认不送出礼物<br>${Info.gift_list_str}`),
GIFT_ALLOWED: () => (
`设置允许送的礼物类型编号(任何未在此列表的礼物一定不会被送出!),多个请用英文逗号(,)隔开,为空则表示允许送出所有类型的礼物<br><br>${Info.gift_list_str}`
),
SEND_ALL: '打钩 送满全部勋章,否则 送出包裹中今天到期的礼物(会送出"默认礼物类型"之外的礼物,若今日亲密度已满则不送)',
AUTO_LIGHT: '自动用小心心点亮亲密度未满且未被排除的灰掉的勋章',
AUTO_LIGHT_LIMIT_LEVEL: '自动点亮等级>=设定值的勋章,低于等级的不自动点亮'
},
SILVER2COIN: '用银瓜子兑换硬币,每天只能兑换一次<br>700银瓜子兑换1个硬币',
AUTO_DAILYREWARD: '自动完成每日经验的任务',
AUTO_DAILYREWARD_CONFIG: {
LOGIN: '自动完成登录任务(凌晨的时候不一定能完成)',
WATCH: '自动完成观看任务(凌晨的时候不一定能完成)',
COIN: '对你关注的动态中最新几期的视频投币,直到投完设定的数量',
SHARE: '自动分享你关注的动态中最新一期的视频(可以完成任务,但实际上不会出现这条动态)'
},
SHOW_TOAST: '选择是否显示浮动提示,但提示信息依旧会在控制台显示'
},
showed: false,
init: () => {
try {
const p = $.Deferred();
const getConst = (itemname, obj) => {
if (itemname.indexOf('-') > -1) {
const objname = itemname.match(/(.+?)-/)[1];
if (objname && obj[objname]) return getConst(itemname.replace(
`${objname}-`, ''), obj[objname]);
else return undefined;
}
if (typeof obj[itemname] === 'function') return obj[itemname]();
return obj[itemname];
};
const recur = (cfg, element, parentname = undefined) => {
for (const item in cfg) {
let itemname;
if (parentname) itemname = `${parentname}-${item}`;
else itemname = item;
const id = `${NAME}_config_${itemname}`;
const name = getConst(itemname, Essential.Config.NAME);
const placeholder = getConst(itemname, Essential.Config.PLACEHOLDER);
let e;
let h;
if (getConst(itemname, Essential.Config.HELP)) h = $(
`<div class="${NAME}_help" id="${id}_help" style="display: inline;"><span class="${NAME}_clickable">?</span></div>`
);
switch ($.type(cfg[item])) {
case 'number':
case 'string':
e = $(`<div class="${NAME}_setting_item"></div>`);
e.html(
`<label style="display: inline;" title="${name}">${name}<input id="${id}" type="text" class="${NAME}_input_text" placeholder="${placeholder}"></label>`
);
if (h) e.append(h);
element.append(e);
break;
case 'boolean':
e = $(`<div class="${NAME}_setting_item"></div>`);
e.html(
`<label style="display: inline;" title="${name}"><input id="${id}" type="checkbox" class="${NAME}_input_checkbox">${name}</label>`
);
if (h) e.append(h);
element.append(e);
if (getConst(`${itemname}_CONFIG`, Essential.Config.NAME)) $(
`#${id}`).addClass(`${NAME}_control`);
break;
case 'array':
e = $(`<div class="${NAME}_setting_item"></div>`);
e.html(
`<label style="display: inline;" title="${name}">${name}<input id="${id}" type="text" class="${NAME}_input_text" placeholder="${placeholder}"></label>`
);
if (h) e.append(h);
element.append(e);
break;
case 'object':
e = $(`<div id="${id}" style="margin: 0px 0px 8px 12px;"/>`);
element.append(e);
recur(cfg[item], e, itemname);
break;
}
}
};
runUntilSucceed(() => {
try {
let findSp = false;
let blancFrames = $('iframe');
if (blancFrames && blancFrames.length > 0) {
blancFrames.each((k, v) => {
if (v.src.includes('/blanc/')) {
findSp = true;
window.toast('检查到特殊活动页,尝试跳转...', 'info', 5e3);
setTimeout(() => {
location.replace(v.src);
}, 10);
return false;
}
});
}
if (findSp) {
p.reject();
return true;
}
//if (!$('#sidebar-vm div.side-bar-cntr')[0]) return false;
if (!$('#sidebar-vm')[0]) return false;
// 加载css
addCSS(
`.${NAME}_clickable {font-size: 12px;color: #0080c6;cursor: pointer;text-decoration: underline;}
.${NAME}_setting_item {margin: 6px 0px;}
.${NAME}_input_checkbox {vertical-align: bottom;}
.${NAME}_input_text {margin: -2px 0 -2px 4px;padding: 0;}`
);
// 绘制右下角按钮
const div_button_span = $('<span>魔改助手设置</span>');
div_button_span[0].style =
'font-size: 12px;line-height: 16px;color: #0080c6;';
const div_button = $('<div/>');
div_button[0].style =
'cursor: pointer;text-align: center;padding: 0px;';
const div_side_bar = $('<div/>');
div_side_bar[0].style =
'width: 56px;height: 32px;overflow: hidden;position: fixed;right: 0px;bottom: 10%;padding: 4px 4px;background-color: rgb(255, 255, 255);z-index: 10001;border-radius: 8px 0px 0px 8px;box-shadow: rgba(0, 85, 255, 0.0980392) 0px 0px 20px 0px;border: 1px solid rgb(233, 234, 236);';
div_button.append(div_button_span);
div_side_bar.append(div_button);
//$('#sidebar-vm div.side-bar-cntr').first().after(div_side_bar);
$('#sidebar-vm').after(div_side_bar);
// 绘制设置界面
const div_position = $('<div/>');
div_position[0].style =
'display: none;position: fixed;height: 300px;width: 350px;bottom: 5%;z-index: 9999;';
const div_style = $('<div/>');
div_style[0].style =
'display: block;overflow: hidden;height: 300px;width: 350px;border-radius: 8px;box-shadow: rgba(106, 115, 133, 0.219608) 0px 6px 12px 0px;border: 1px solid rgb(233, 234, 236);background-color: rgb(255, 255, 255);';
div_position.append(div_style);
document.body.appendChild(div_position[0]);
// 绘制标题栏及按钮
const div_title = $('<div/>');
div_title[0].style =
'display: block;border-bottom: 1px solid #E6E6E6;height: 35px;line-height: 35px;margin: 0;padding: 0;overflow: hidden;';
const div_title_span = $(
'<span style="float: left;display: inline;padding-left: 8px;font: 700 14px/35px SimSun;">Bilibili直播间挂机助手-魔改</span>'
);
const div_title_button = $('<div/>');
div_title_button[0].style =
'float: right;display: inline;padding-right: 8px;';
const div_button_line = $(`<div style="display: inline;"></div>`);
const span_button_state = $(
`<span class="${NAME}_clickable">统计</span>`)
div_button_line.append(span_button_state);
div_button_line.append(" ");
const span_button_clear = $(
`<span class="${NAME}_clickable">清除缓存</span>`)
div_button_line.append(span_button_clear);
div_title_button.append(div_button_line);
div_title.append(div_title_span);
div_title.append(div_title_button);
div_style.append(div_title);
// 绘制设置项内容
const div_context_position = $('<div/>');