-
Notifications
You must be signed in to change notification settings - Fork 94
/
B站直播间挂机助手.js
6670 lines (6653 loc) · 352 KB
/
B站直播间挂机助手.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 B站直播间挂机助手
// @name:en B站直播间挂机助手
// @namespace https://github.com/andywang425
// @author andywang425
// @description 自动获取小心心,参加天选时刻抽奖,直播区签到,应援团签到,银瓜子换硬币,完成主站每日任务(登录,观看视频,投币,分享视频),批量送礼,发送粉丝勋章打卡弹幕,参与实物抽奖,参与Bilibili直播区礼物抽奖,参加被广播的节奏风暴,定时发弹幕,快捷购买粉丝勋章,优化弹幕体验,发弹幕前自动佩戴当前直播间的粉丝勋章
// @description:en 自动获取小心心,参加天选时刻抽奖,直播区签到,应援团签到,银瓜子换硬币,完成主站每日任务(登录,观看视频,投币,分享视频),批量送礼,发送粉丝勋章打卡弹幕,参与实物抽奖,参与Bilibili直播区礼物抽奖,参加被广播的节奏风暴,定时发弹幕,快捷购买粉丝勋章,优化弹幕体验,发弹幕前自动佩戴当前直播间的粉丝勋章
// @updateURL https://raw.githubusercontent.com/andywang425/BLTH/master/B%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B.user.js
// @downloadURL https://raw.githubusercontent.com/andywang425/BLTH/master/B%E7%AB%99%E7%9B%B4%E6%92%AD%E9%97%B4%E6%8C%82%E6%9C%BA%E5%8A%A9%E6%89%8B.user.js
// @homepageURL https://github.com/andywang425/BLTH
// @supportURL https://github.com/andywang425/BLTH/issues
// @icon https://cdn.jsdelivr.net/gh/andywang425/BLTH@7d7ca494edd314806460e24c6b59be8ae1bd7dc6/img/script-icon.png
// @copyright 2021, andywang425 (https://github.com/andywang425)
// @license MIT
// @compatible chrome 80 or later
// @compatible firefox 77 or later
// @compatible opera 69 or later
// @compatible safari 13.1 or later
// @version 5.6.9
// @include /https?:\/\/live\.bilibili\.com\/[blanc\/]?[^?]*?\d+\??.*/
// @run-at document-start
// @connect passport.bilibili.com
// @connect api.live.bilibili.com
// @connect api.bilibili.com
// @connect api.vc.bilibili.com
// @connect live-trace.bilibili.com
// @connect sc.ftqq.com
// @connect push.xuthus.cc
// @connect sctapi.ftqq.com
// @connect pushplus.plus
// @connect cdn.jsdelivr.net
// @connect raw.fastgit.org
// @connect raw.githubusercontent.com
// @connect andywang.top
// @require https://cdn.jsdelivr.net/gh/andywang425/BLTH@dac0d115a45450e6d3f3e17acd4328ab581d0514/assets/js/library/Ajax-hook.min.js
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/pako.min.js
// @require https://cdn.jsdelivr.net/gh/andywang425/BLTH@84aacffd78056bee0ebfb551f657a1b061ca5335/assets/js/library/bliveproxy.min.js
// @require https://cdn.jsdelivr.net/gh/andywang425/BLTH@d7e974a95e3c0328691561c52c66c39287e3b89f/assets/js/library/BilibiliAPI_Mod.min.js
// @require https://cdn.jsdelivr.net/gh/andywang425/BLTH@4368883c643af57c07117e43785cd28adcb0cb3e/assets/js/library/layer.min.js
// @require https://cdn.jsdelivr.net/gh/andywang425/BLTH@dac0d115a45450e6d3f3e17acd4328ab581d0514/assets/js/library/libBilibiliToken.min.js
// @require https://cdn.jsdelivr.net/gh/andywang425/BLTH@dac0d115a45450e6d3f3e17acd4328ab581d0514/assets/js/library/libWasmHash.min.js
// @resource layerCss https://cdn.jsdelivr.net/gh/andywang425/BLTH@f9a554a9ea739ccde68918ae71bfd17936bae252/assets/css/layer.css
// @resource myCss https://cdn.jsdelivr.net/gh/andywang425/BLTH@da3d8ce68cde57f3752fbf6cf071763c34341640/assets/css/myCss.min.css
// @resource main https://cdn.jsdelivr.net/gh/andywang425/BLTH@afff97b8be7d446a7a2224587245bd51c784f8be/assets/html/main.min.html
// @resource eula https://cdn.jsdelivr.net/gh/andywang425/BLTH@da3d8ce68cde57f3752fbf6cf071763c34341640/assets/html/eula.min.html
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_notification
// @grant GM_openInTab
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_addStyle
// ==/UserScript==
(function () {
localstorage2gm();
const NAME = 'BLTH',
W = typeof unsafeWindow === 'undefined' ? window : unsafeWindow,
eventListener = W.addEventListener,
wfetch = window.fetch,
ts_ms = () => Date.now(), // 当前毫秒
ts_s = () => Math.round(ts_ms() / 1000), // 当前秒
tz_offset = new Date().getTimezoneOffset() + 480, // 本地时间与东八区差的分钟数
anchorFollowTagName = 'BLTH天选关注UP',
anchorPrizeTagName = 'BLTH天选中奖UP',
delayCall = (callback, delay = 120e3) => {
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;
},
MYDEBUG = (sign, ...data) => {
if (!SP_CONFIG.debugSwitch) return;
if (typeof data[0] === "object" && data[0].netError) return MYERROR(sign, ...data);
let d = new Date();
d = `%c[${NAME}]%c[${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}:${d.getMilliseconds()}]%c`;
if (data.length === 1) { console.log(d, "font-weight: bold;", "color: #0920e6;", "", `${sign}:`, data[0],); return }
console.log(d, "font-weight: bold;", "color: #0920e6;", "", `${sign}:`, data,);
},
MYERROR = (sign, ...data) => {
let d = new Date();
d = `[${NAME}][${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}:${d.getMilliseconds()}]`;
if (data.length === 1) { console.error(d, `${sign}:`, data[0]); return }
console.error(d, `${sign}:`, data);
},
runMidnight = (callback, msg) => {
// 明天凌晨0点1分再次运行
const t = new Date();
let name = msg || ' ';
t.setMinutes(t.getMinutes() + tz_offset);
t.setDate(t.getDate() + 1);
t.setHours(0, 1, 0, 0);
t.setMinutes(t.getMinutes() - tz_offset);
setTimeout(callback, t - ts_ms());
MYDEBUG('runMidnight', name + " " + t.toString());
},
runExactMidnight = (callback, msg) => {
// 明天凌晨0点再次运行
const t = new Date();
let name = msg || ' ';
t.setMinutes(t.getMinutes() + tz_offset);
t.setDate(t.getDate() + 1);
t.setHours(0, 0, 0, 0);
t.setMinutes(t.getMinutes() - tz_offset);
setTimeout(callback, t - ts_ms());
MYDEBUG('runExactMidnight', name + " " + t.toString());
},
runTomorrow = (callback, hour, minute, msg) => {
// 明天运行,可自定义时间
const t = new Date();
let name = msg || ' ';
t.setMinutes(t.getMinutes() + tz_offset);
t.setDate(t.getDate() + 1);
t.setHours(hour, minute, 0, 0);
t.setMinutes(t.getMinutes() - tz_offset);
setTimeout(callback, t - ts_ms());
MYDEBUG('runTomorrow', name + " " + t.toString());
},
runToday = (callback, hour, minute, msg) => {
// 今天运行,可自定义时间
const t = new Date();
let name = msg || ' ';
t.setMinutes(t.getMinutes() + tz_offset);
t.setHours(hour, minute, 0, 0);
t.setMinutes(t.getMinutes() - tz_offset);
setTimeout(callback, t - ts_ms());
MYDEBUG('runToday', name + " " + t.toString());
},
getCHSdate = () => {
// 返回东八区 Date
return new Date(ts_ms() + tz_offset * 60000);
},
appToken = new BilibiliToken(),
baseQuery = `actionKey=appkey&appkey=${BilibiliToken.appKey}&build=5561000&channel=bili&device=android&mobi_app=android&platform=android&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%225.57.0%22%2C%22abtest%22%3A%22%22%7D`,
setToken = async () => {
if (tokenData.time > ts_s()) {
userToken = tokenData;
} else {
tokenData = await appToken.getToken();
if (tokenData === undefined) return MYERROR('appToken', 'tokenData获取失败');
tokenData.time = ts_s() + tokenData.expires_in;
GM_setValue(`Token`, tokenData);
userToken = tokenData;
};
MYDEBUG(`appToken`, tokenData);
return 'OK';
},
newWindow = {
init: () => {
return newWindow.Toast.init();
},
Toast: {
// 设置右上角浮动提示框 Need Init
init: () => {
try {
const list = [];
window.toast = (msg, type = 'info', timeout = 5e3) => {
switch (type) {
case 'success':
case 'info':
case 'caution':
case 'error':
break;
default:
type = 'info';
}
const a = $(`<div class="link-toast ${type} fixed" style="z-index:2001"><span class="toast-text">${msg}</span></div>`)[0];
document.body.appendChild(a);
MYDEBUG("toast-" + type, msg);
a.style.top = (document.body.scrollTop + list.length * 40 + 10) + 'px';
a.style.left = (document.body.offsetWidth + document.body.scrollLeft - a.offsetWidth - 5) + 'px';
if (!SP_CONFIG.windowToast) $('.link-toast').hide();
list.push(a);
setTimeout(() => {
a.className += ' out';
setTimeout(() => {
list.shift();
list.forEach((v) => {
v.style.top = (parseInt(v.style.top, 10) - 40) + 'px';
});
$(a).remove();
}, 200);
}, timeout);
};
return $.Deferred().resolve();
} catch (err) {
MYERROR(`初始化浮动提示时出现异常`, err);
return $.Deferred().reject();
}
}
}
},
addStyle = () => {
const layerCss = GM_getResourceText('layerCss');
const myCss = GM_getResourceText('myCss');
const allCss = layerCss + myCss;
return GM_addStyle(allCss);
},
getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
}),
linkMsg = (link, msg = link) => '<a href="' + link + '"target="_blank" style="color:">' + msg + '</a>',
liveRoomUrl = 'https://live.bilibili.com/',
upperNum = { 0: ")", 1: "!", 2: "@", 3: "#", 4: "$", 5: "%", 6: "^", 7: "7", 8: "*", 9: "(" },
isRegexp = /^\/.+\/[i|g|m]?$/,
SP_CONFIG_DEFAULT = {
showEula: true, // 显示EULA
storageLastFixVersion: "0", // 上次修复设置的版本
mainDisplay: 'show', // UI隐藏开关
debugSwitch: false, // 控制台日志开关
windowToast: true, // 右上提示信息
nosleep: true, // 屏蔽挂机检测
invisibleEnter: false, // 隐身入场
banP2p: false, // 禁止p2p上传
lastShowUpdateMsgVersion: "0", // 上次显示更新信息的版本
DANMU_MODIFY: false, // 修改弹幕
blockLiveStream: false, // 拦截直播流
blockliveDataUpdate: false, // 拦截直播观看数据上报
wear_medal_before_danmu: false, // 手动发弹幕前自动佩戴当前房间勋章
wear_medal_type: 'ONLY_FIRST' // 自动佩戴勋章方式
};
let otherScriptsRunningCheck = $.Deferred(),
otherScriptsRunning = false,
SP_CONFIG = GM_getValue("SP_CONFIG") || {},
winPrizeNum = 0,
winPrizeTotalCount = 0,
SEND_GIFT_NOW = false, // 立刻送出礼物
SEND_DANMU_NOW = false, // 立刻发弹幕
LIGHT_MEDAL_NOW = false, // 立刻点亮勋章
hideBtnClickable = false,
getFollowBtnClickable = true,
unFollowBtnClickable = true,
mainSiteTasksBtnClickable = true,
danmuTaskRunning = false,
medalDanmuRunning = false,
hasWornMedal = false,
Live_info = {
room_id: undefined,
short_room_id: undefined,
uid: undefined,
ruid: undefined,
gift_list: [{ id: 6, price: 1e3 }, { id: 1, price: 100 }, { id: 30607, price: 5e3 }],
rnd: undefined,
visit_id: undefined,
bili_jct: undefined,
tid: undefined,
uname: undefined,
user_level: undefined, // 直播等级
level: undefined, // 主站等级
danmu_length: undefined, // 直播弹幕长度限制
medal: undefined // 当前直播间勋章的 target_id
},
medal_info = { status: $.Deferred(), medal_list: [] },
userToken = undefined,
tokenData = GM_getValue("Token") || { time: 0 },
mainIndex = undefined,
logIndex = undefined,
layerUiMain = undefined, // 控制面板
layerLogWindow = undefined, // 日志窗口
logDiv = undefined,
tabContent = undefined,
JQlogRedPoint = undefined,
JQmenuWindow = undefined,
layerLogWindow_Height = undefined,
layerLogWindow_ScrollHeight = undefined,
layerLogWindow_ScrollTop = undefined,
layerLogWindow_ScrollY = undefined,
awardScrollCount = 0,
readConfigArray = [undefined],
noticeJson = GM_getValue("noticeJson") || {}; // 检查更新时获取的json
/**
* 替换字符串中所有的匹配项(可处理特殊字符如括号)
* @param oldSubStr 搜索的字符串
* @param newSubStr 替换内容
*/
String.prototype.replaceall = function (oldSubStr, newSubStr) {
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& 代表所有被匹配的字符串
}
return this.replace(new RegExp(escapeRegExp(oldSubStr), 'g'), () => newSubStr);
}
// 初始化特殊设置
mergeObject(SP_CONFIG, SP_CONFIG_DEFAULT);
// 拦截直播流/数据上报,需要尽早
if (SP_CONFIG.blockLiveStream || SP_CONFIG.blockliveDataUpdate || SP_CONFIG.wear_medal_before_danmu) {
W.fetch = (...arg) => {
if (SP_CONFIG.blockLiveStream && arg[0].includes('bilivideo')) {
return $.Deferred().resolve();
} else if (SP_CONFIG.blockliveDataUpdate && arg[0].includes("data.bilibili.com/gol/postweb")) {
return $.Deferred().resolve();
} else if (SP_CONFIG.wear_medal_before_danmu && arg[0].includes('//api.live.bilibili.com/msg/send')) {
if (medal_info.status.state() !== "resolved" || Live_info.medal === null || (SP_CONFIG.wear_medal_type === "ONLY_FIRST" && hasWornMedal)) return wfetch(...arg);
if (typeof Live_info.medal === "undefined") {
for (const m of medal_info.medal_list) {
if (m.roomid === Live_info.short_room_id) {
Live_info.medal = m;
break;
}
}
}
if (typeof Live_info.medal === "undefined") {
Live_info.medal = null; // 没有该勋章,之后无需再检查
return wfetch(...arg);
}
return BAPI.xlive.wearMedal(Live_info.medal.medal_id).then((response) => {
MYDEBUG('API.xlive.wearMedal', response);
if (response.code === 0) {
hasWornMedal = true;
try {
let medalJqItem = $(".dp-i-block.medal-item-margin");
if (medalJqItem === null) return;
let border = medalJqItem.find(".v-middle.fans-medal-item");
const medalColor = '#' + Live_info.medal.color.toString(16);
const medalLevel = Live_info.medal.medal_level;
const medalText = Live_info.medal.medalName;
if (border.length !== 0) {
// 之前戴着勋章
let background = border.find('.fans-medal-label');
let level = border.find('.fans-medal-level');
let text = background.find('.fans-medal-content');
border.css('border-color', medalColor);
background.css('background-image', `linear-gradient(45deg, ${medalColor}, ${medalColor})`);
level.text(medalLevel);
text.text(medalText);
} else {
// 如果没戴勋章则需插入缺失的 html
$(".action-item.medal.wear-medal").remove(); // 移除提示水印
medalJqItem.html(`<div data-v-2c4630d2="" data-v-34b5b0e1="" class="v-middle fans-medal-item" style="border-color: ${medalColor}">
<div data-v-2c4630d2="" class="fans-medal-label" style="background-image: linear-gradient(45deg, ${medalColor}, ${medalColor});">
<span data-v-2c4630d2="" class="fans-medal-content">${medalText}</span>
</div>
<div data-v-2c4630d2="" class="fans-medal-level" style="color: ${medalColor};">${medalLevel}</div>
</div>`);
}
} catch (e) {
MYERROR("修改弹幕框左侧粉丝拍样式出错", e);
}
} else {
window.toast(`自动佩戴粉丝勋章出错 ${response.message}`, 'error');
}
return wfetch(...arg);
}, () => {
window.toast('自动佩戴粉丝勋章失败,请检查网络', 'error');
return wfetch(...arg);
})
}
else {
return wfetch(...arg);
}
}
}
// DOM加载完成后运行
$(function () {
// 若 window 下无 BilibiliLive,则说明页面有 iframe,此时脚本在在 top 中运行 或 发生错误
if (W.BilibiliLive === undefined) return;
// 初始化右上角提示信息弹窗
newWindow.init();
// 检查浏览器版本并显示提示信息
const checkBrowserArr = checkBrowserVersion();
if (checkBrowserArr[0] !== "ok") {
window.toast(...checkBrowserArr);
if (checkBrowserArr[1] === "error") return;
}
// 唯一运行检测
onlyScriptCheck();
if (SP_CONFIG.DANMU_MODIFY) {
window.bliveproxy.hook();
MYDEBUG('bliveproxy hook complete', window.bliveproxy);
}
if (SP_CONFIG.nosleep) {
setInterval(() => mouseMove(), 300e3);
W.addEventListener = (...arg) => {
if (arg[0].indexOf('visibilitychange') > -1) return;
else return eventListener(...arg);
}
}
if (SP_CONFIG.invisibleEnter || SP_CONFIG.blockliveDataUpdate) {
try {
ah.proxy({
onRequest: (XHRconfig, handler) => {
if (SP_CONFIG.invisibleEnter && XHRconfig.url.includes('//api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser')) {
MYDEBUG('getInfoByUser request', XHRconfig);
XHRconfig.url = '//api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser?room_id=22474988&from=0';
handler.next(XHRconfig);
} else if (SP_CONFIG.blockliveDataUpdate && XHRconfig.url.includes('//data.bilibili.com/log')) {
handler.resolve("ok");
} else {
handler.next(XHRconfig);
}
},
onResponse: async (response, handler) => {
if (response.config.url.includes('//api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser')) {
MYDEBUG('getInfoByUser response', response);
if (!response.response.includes('"code":0')) {
MYDEBUG('隐身入场出错,取消隐身入场并以当前房间号再次获取用户数据');
response.response = await BAPI.xlive.getInfoByUser(W.BilibiliLive.ROOMID).then((re) => {
MYDEBUG('API.xlive.getInfoByUser(W.BilibiliLive.ROOMID)', re);
if (re.code === 0) return JSON.stringify(re);
else return window.toast(`获取房间基础信息失败 ${re.message}`, 'error')
});
}
response.response = response.response.replace('"is_room_admin":false', '"is_room_admin":true');
const json_response = JSON.parse(response.response);
Live_info.danmu_length = json_response.data.property.danmu.length;
}
handler.next(response);
}
})
} catch (e) { MYDEBUG('ah.proxy Ajax-hook代理运行出错', e) }
}
if (SP_CONFIG.banP2p) {
const RTClist = ["RTCPeerConnection", "RTCDataChannel", "mozRTCPeerConnection", "webkitRTCPeerConnection", "DataChannel"];
for (const i of RTClist) {
delete W[i];
}
}
const loadInfo = (delay = 0) => {
return setTimeout(async () => {
if (parseInt(W.BilibiliLive.UID) === 0 || isNaN(parseInt(W.BilibiliLive.UID))) {
//MYDEBUG(`${GM_info.script.name}`,'无配置信息');
return loadInfo(500);
} else {
window.toast("正在获取礼物 / 用户 / 账号 / 粉丝勋章数据...", "info");
Live_info.room_id = W.BilibiliLive.ROOMID;
Live_info.short_room_id = W.BilibiliLive.SHORT_ROOMID;
Live_info.uid = W.BilibiliLive.UID;
Live_info.tid = W.BilibiliLive.ANCHOR_UID;
await BAPI.gift.gift_config().then((response) => {
MYDEBUG('InitData: API.gift.gift_config', response);
if (response.data && Array.isArray(response.data)) {
return Live_info.gift_list = response.data;
} else if (response.data.list && Array.isArray(response.data.list)) {
return Live_info.gift_list = response.data.list;
} else {
return window.toast(`直播间礼物数据获取失败 ${response.message}\n使用默认数据`, 'warning');
}
});
await BAPI.getuserinfo().then((re) => {
MYDEBUG('InitData: API.getuserinfo', re);
if (re.code === "REPONSE_OK") {
Live_info.uname = re.data.uname;
Live_info.user_level = re.data.user_level;
}
else {
window.toast(`API.getuserinfo 获取用户信息失败 ${re.message}`, 'error');
return delayCall(() => loadInfo());
}
});
await BAPI.x.getAccInfo(Live_info.uid).then((re) => {
MYDEBUG('InitData: API.x.getAccInfo', re);
if (re.code === 0) {
Live_info.level = re.data.level;
} else {
window.toast(`API.x.getAccInfo 获取账号信息失败 ${re.message}`, 'error');
return delayCall(() => loadInfo());
}
});
Live_info.bili_jct = BAPI.getCookie('bili_jct');
Live_info.ruid = W.BilibiliLive.ANCHOR_UID;
Live_info.rnd = W.BilibiliLive.RND;
Live_info.visit_id = W.__statisObserver ? W.__statisObserver.__visitId : '';
MYDEBUG("Live_info", Live_info);
await getMedalList();
MYDEBUG("medla_info", medal_info);
init();
}
}, delay);
};
return loadInfo();
});
function init() { // 初始化各项功能
const MY_API = {
CONFIG_DEFAULT: {
AUTO_DANMU: false, // 发送弹幕
AUTO_GIFT: false, // 自动送礼
AUTO_GIFT_ROOMID: ["0"], // 送礼优先房间
AUTO_GROUP_SIGN: true, // 应援团签到开关
ANCHOR_LOTTERY: false, // 天选时刻
ANCHOR_AUTO_DEL_FOLLOW: false, // 检测到未中奖自动取关
ANCHOR_MAXROOM: 500, // 天选检查房间最大数量
ANCHOR_MAXLIVEROOM_SAVE: 100, // 天选上传保存房间最大数量
ANCHOR_CHECK_INTERVAL: 5, // 天选检查间隔(分钟)
ANCHOR_IGNORE_BLACKLIST: true, // 天选忽略关键字(选项)
ANCHOR_IGNORE_PWDROOM: true, // 不参加有密码的直播间的天选
ANCHOR_BLACKLIST_WORD: ['测试', '钓鱼', '炸鱼', '黑屋', '脚本', '空气'], // 天选忽略关键字
ANCHOR_INTERVAL: 350, // 天选(检查天选和取关)请求间隔
ANCHOR_NEED_GOLD: 0, // 忽略所需金瓜子大于_的抽奖
ANCHOR_GOLD_JOIN_TIMES: 1, // 每个付费天选参加_次
ANCHOR_WAIT_REPLY: true, // 请求后等待回复
ANCHOR_UPLOAD_DATA: false, // 天选上传数据
ANCHOR_UPLOAD_DATA_INTERVAL: 10, // 上传数据间隔
ANCHOR_UPLOAD_MSG: false, // 天选上传时的附加信息开关
ANCHOR_PERSONAL_PROFILE: "", // 天选上传的个人简介表层信息
ANCHOR_UPLOAD_MSG_CONTENT: "", // 附加信息
ANCHOR_IGNORE_UPLOAD_MSG: false, // 天选忽略附加信息
ANCHOR_UPLOAD_ROOMLIST: false, // 上传天选数据至 BLTH-server
ANCHOR_SERVER_APIKEY: "", // 天选时刻 BLTH-server apikey
ANCHOR_TYPE_SERVER: false, // 天选时刻 - BLTH-server
ANCHOR_TYPE_POLLING: true, // 天选模式 - 轮询
ANCHOR_TYPE_LIVEROOM: false, // 天选模式 - 直播间简介
ANCHOR_TYPE_FOLLOWING: false, // 天选模式 - 关注用户
ANCHOR_TYPE_CUSTOM: false, // 天选模式 - 自定义房间列表
ANCHOR_CUSTOM_ROOMLIST: [], // 自定义房间列表
ANCHOR_GETDATA_ROOM: 22474988, // 获取天选数据的直播间
ANCHOR_IGNORE_ROOM: true, // 天选忽略直播间
ANCHOR_IGNORE_ROOMLIST: ["22647871"], // 天选忽略直播间房间列表
ANCHOR_PRIVATE_LETTER: false, // 中奖后给UP发一条私信
ANCHOR_LETTER_CONTENT: 'UP我中天选了,请问怎么领奖[doge]', // 私信内容
ANCHOR_ADD_TO_WHITELIST: false, // 天选中奖后把发起抽奖的UP加入白名单
ANCHOR_MOVETO_FOLLOW_TAG: true, // 把关注的UP移到新分组
ANCHOR_MOVETO_PRIZE_TAG: true, // 把中奖的UP移到新分组
ANCHOR_DANMU: false, // 天选中奖后弹幕
ANCHOR_DANMU_CONTENT: ["我中啦!", "芜湖"], // 天选中奖后弹幕内容
ANCHOR_IGNORE_MONEY: 0, // 忽略金额小于_的天选
ANCHOR_MONEY_ONLY: false, // 仅参加现金抽奖
ANCHOR_FANS_CHECK: false, // 忽略粉丝数小于__的天选
ANCHOR_FANS_LEAST: 0, // 最少粉丝数
CHECK_HOUR_ROOM: false, // 检查小时榜
CHECK_HOUR_ROOM_INTERVAL: 600, // 小时榜检查间隔时间(秒)
COIN: false, // 投币
COIN_NUMBER: 0, // 投币数量
COIN_TYPE: "COIN_DYN", // 投币方法 动态/UID
COIN_UID: ['0'], // 投币up主
COIN2SILVER: false, // 银币换银瓜子
COIN2SILVER_NUM: 1, // 银币换银瓜子,硬币数量
CP_NOTICE: false, // 酷推
CP_Skey: 'Skey', // 酷推Skey
DANMU_CONTENT: ["这是一条弹幕"], // 弹幕内容
DANMU_ROOMID: ["22474988"], // 发弹幕房间号
DANMU_INTERVAL_TIME: ["10m"], // 弹幕发送时间
DANMU_MODIFY_REGEX: ["/【/"],// 匹配弹幕 正则字符串
DANMU_MODIFY_UID: [0], // 匹配弹幕 UID
DANMU_MODIFY_POOL: [4], // 修改弹幕 弹幕池
DANMU_MODIFY_COLOR: ["#f7335d"], // 修改弹幕 颜色
DANMU_MODIFY_SIZE: [1.2], // 修改弹幕 大小
FORCE_LIGHT: false, // 点亮勋章时忽略亲密度上限
GIFT_LIMIT: 1, // 礼物到期时间(天)
GIFT_SEND_HOUR: 23, // 送礼小时
GIFT_SEND_MINUTE: 59, // 送礼分钟
GIFT_INTERVAL: 5, // 送礼间隔
GIFT_METHOD: "GIFT_SEND_TIME", // 送礼时间策略
GIFT_SORT: 'GIFT_SORT_HIGH', // 送礼优先高等级
GIFT_ALLOW_TYPE: ["1", "6", "30607"], // 允许送出的礼物类型,默认:辣条,亿圆, 小心心
GIFT_SEND_METHOD: "GIFT_SEND_BLACK", // 送礼黑白名单策略
GIFT_SEND_ROOM: ["0"], // 送礼黑白名单策略 - 房间列表
GM_NOTICE: false, // GM通知
IN_TIME_RELOAD_DISABLE: false, // 休眠时段是否禁止刷新直播间 false为刷新
LOTTERY: false, // 参与抽奖
LIVE_SIGN: true, // 直播区签到
LOGIN: true, // 主站登陆
LITTLE_HEART: true, // 获取小心心
LIGHT_MEDALS: ["0"], // 点亮勋章
LIGHT_METHOD: "LIGHT_WHITE",
MEDAL_DANMU_ROOM: ["0"], // 打卡弹幕房间列表
MEDAL_DANMU_METHOD: "MEDAL_DANMU_BLACK", // 打卡弹幕发送方式
MEDAL_DANMU_INTERVAL: 2, // 打卡弹幕发送间隔(秒)
MATERIAL_LOTTERY: true, // 实物抽奖
MATERIAL_LOTTERY_CHECK_INTERVAL: 60, // 实物抽奖检查间隔
MATERIAL_LOTTERY_IGNORE_QUESTIONABLE_LOTTERY: true, // 实物抽奖忽略存疑抽奖
MEDAL_DANMU: false, // 粉丝勋章打卡弹幕
MATERIAL_LOTTERY_REM: 10, // 每次检查aid数量
MEDAL_DANMU_CONTENT: ["(⌒▽⌒)", "( ̄▽ ̄)", "(=・ω・=)", "(`・ω・´)", "(〜 ̄△ ̄)〜", "(・∀・)", "(°∀°)ノ", "( ̄3 ̄)", "╮( ̄▽ ̄)╭", "_(:3」∠)_", "(^・ω・^ )", "(● ̄(エ) ̄●)", "ε=ε=(ノ≧∇≦)ノ", "⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄", "←◡←"], // 粉丝勋章打卡弹幕内容
PP_NOTICE: false, // 推送加开关
PP_token: "token", // 推送加 token
QUESTIONABLE_LOTTERY: ['test', 'encrypt', '测试', '钓鱼', '加密', '炸鱼'], // 存疑实物抽奖
RANDOM_DELAY: true, // 抽奖随机延迟
RANDOM_SEND_DANMU: 0, // 随机弹幕发送概率
RANDOM_SKIP: 0, // 随机跳过抽奖概率
REMOVE_ELEMENT_2233: false, // 移除2233
REMOVE_ELEMENT_activity: true, // 移除活动入口
REMOVE_ELEMENT_rank: true, // 移除排行榜入口
REMOVE_ELEMENT_followSideBar: false, // 移除右侧关注按钮及弹窗
REMOVE_ELEMENT_flipView: true, // 移除移除礼物栏下方广告
REMOVE_ELEMENT_anchor: false, // 移除天选时刻弹窗及图标
REMOVE_ELEMENT_pk: false, // 移除PK弹窗及进度条
REMOVE_ELEMENT_playerIcon: true, // 移除直播水印
RND_DELAY_END: 5, // 延迟最大值
RND_DELAY_START: 2, // 延迟最小值
SEND_ALL_GIFT: false, // 送满全部勋章
SHARE: true, // 分享
SILVER2COIN: false, // 银瓜子换硬币
ServerTurbo_NOTICE: false, // Server酱·Turbo版
ServerTurbo_SendKey: "SendKey", // Server酱·Turbo版SendKey
SPARE_GIFT_ROOM: "0", // 剩余礼物送礼房间
STORM: false, // 节奏风暴
STORM_MAX_COUNT: 100, // 单个风暴最大尝试次数
STORM_ONE_LIMIT: 200, // 单个风暴参与次数间隔(毫秒)
STORM_QUEUE_SIZE: 3, // 允许同时参与的风暴次数
TIME_AREA_DISABLE: true, // 不抽奖时段开关
TIME_AREA_END_H0UR: 8, // 不抽奖结束小时
TIME_AREA_END_MINUTE: 0, // 不抽奖结束分钟
TIME_AREA_START_H0UR: 2, // 不抽奖开始小时
TIME_AREA_START_MINUTE: 0, // 不抽奖开始分钟
TIME_RELOAD: false, // 定时刷新直播间
TIME_RELOAD_MINUTE: 120, // 直播间重载时间
UPDATE_TIP: true, //更新提示
WATCH: true // 观看视频
},
CACHE_DEFAULT: {
AUTO_SEND_DANMU_TS: [], // 弹幕发送
AUTO_GROUP_SIGH_TS: 0, // 应援团签到
DailyReward_TS: 0, // 每日任务
LiveReward_TS: 0, // 直播每日任务
Silver2Coin_TS: 0, // 银瓜子换硬币
Coin2Sliver_TS: 0, // 硬币换银瓜子
Gift_TS: 0, // 自动送礼(定时)
GiftInterval_TS: 0, // 自动送礼(间隔)
LittleHeart_TS: 0, // 小心心
MaterialObject_TS: 0, // 实物抽奖
AnchorLottery_TS: 0,
last_aid: 732, // 实物抽奖最后一个有效aid
MedalDanmu_TS: 0 //粉丝勋章打卡
},
GIFT_COUNT_DEFAULT: {
COUNT: 0, // 辣条(目前没用)
ANCHOR_COUNT: 0, // 天选
MATERIAL_COUNT: 0, // 实物
CLEAR_TS: 0, // 重置统计
},
CONFIG: {},
CACHE: {},
GIFT_COUNT: {},
init: () => {
addStyle();
const tabList = $('.tab-list.dp-flex'),
ct = $(".chat-history-panel"),
ctWidth = ct.width(),
aside_area_vmHeight = $('#aside-area-vm').height(),
chat_control_panel_vmHeight = $('#chat-control-panel-vm').height(),
eleList = ['.chat-history-list', '.attention-btn-ctnr', '.live-player-mounter'];
tabContent = $('.tab-content');
logDiv = $(`<li data-v-2fdbecb2="" data-v-d2be050a="" class="item dp-i-block live-skin-separate-border border-box t-center pointer live-skin-normal-text" style = 'font-weight:bold;color: #999;' id = "logDiv"><span id="logDivText">日志</span><div class="blth_num" style="display: none;" id = 'logRedPoint'>0</div></mli>`);
let tabOffSet = 0, top = 0, left = 0;
if (eleList.some(i => i.length === 0) || tabList.length === 0 || tabContent.length === 0) {
window.toast('必要页面元素缺失,强制运行(可能会看不到控制面板,提示信息)', 'error');
}
tabList.append(logDiv);
JQlogRedPoint = $('#logRedPoint');
let tabListItems = [];
for (let i = 0; i < tabList.children('li').length; i++) {
tabListItems.push(tabList.children('li')[i]);
};
logIndex = layer.open({
type: 1,
title: false,
offset: [String(top) + 'px', String(left) + 'px'],
closeBtn: 0,
shade: 0,
zIndex: 2000,
fixed: false,
area: [String(ctWidth) + 'px', String(aside_area_vmHeight - chat_control_panel_vmHeight) + 'px'], //宽高
anim: -1,
isOutAnim: false,
resize: false,
content: '<div id = "menuWindow"></div>',
success: () => {
layerLogWindow = $('#layui-layer1 .layui-layer-content');
JQmenuWindow = $('#menuWindow');
let logDivText = $('#logDivText');
layerLogWindow.on("DOMNodeInserted", function () {
layerLogWindow_Height = $(this).height();
layerLogWindow_ScrollHeight = $(this)[0].scrollHeight;
if (layerLogWindow_ScrollHeight > layerLogWindow_Height) {
layerLogWindow.scrollTop(layerLogWindow.prop("scrollHeight"));
$(this).off("DOMNodeInserted");
}
})
layerLogWindow.scroll(function () {
layerLogWindow_Height = $(this).height();
layerLogWindow_ScrollHeight = $(this)[0].scrollHeight;
layerLogWindow_ScrollTop = $(this)[0].scrollTop;
layerLogWindow_ScrollY = layerLogWindow_ScrollTop + layerLogWindow_Height + 1;
if (layerLogWindow_ScrollY < layerLogWindow_ScrollHeight && winPrizeNum === 0) logDivText.text('日志🚀');
else logDivText.text('日志');
});
}
});
layer.style(logIndex, {
'box-shadow': 'none',
'display': 'none',
'background-color': '#f2f3f5'
});
for (const i of tabListItems) {
let JQi = $(i);
JQi.click(() => {
for (const item of tabListItems) {
let JQitem = $(item);
if (item != i) {
if (JQitem.css('color') !== 'rgb(153, 153, 153)') JQitem.css("color", "#999");
if (JQitem.hasClass('live-skin-main-text')) JQitem.removeClass('live-skin-main-text');
if (JQitem.hasClass('active')) JQitem.removeClass('active');
if (!JQitem.hasClass('live-skin-normal-text')) JQitem.addClass('live-skin-normal-text')
} else {
if (JQitem.css('color') !== 'rgb(51, 51, 51)') JQi.css("color", "#333");
if (!JQitem.hasClass('live-skin-main-text')) JQi.addClass('live-skin-main-text');
if (!JQitem.hasClass('active')) JQi.addClass('active');
if (JQitem.hasClass('live-skin-normal-text')) JQi.removeClass('live-skin-normal-text');
}
}
if (JQi.attr('id') === "logDiv") {
if (!tabOffSet) {
tabOffSet = $('.tab-content').offset();
top = tabOffSet.top;
left = tabOffSet.left;
layer.style(logIndex, {
'top': String(top) + 'px',
'left': String(left) + 'px'
});
}
layer.style(logIndex, {
'display': 'block'
});
if (winPrizeNum === 0) {
JQlogRedPoint.hide();
if (layerLogWindow_ScrollY < layerLogWindow_ScrollHeight || layerLogWindow_ScrollY === undefined)
layerLogWindow.scrollTop(layerLogWindow.prop("scrollHeight"));
} else if (winPrizeNum > 0 && awardScrollCount < winPrizeTotalCount && $('.chatLogWinPrize').length > 0) {
$('.chatLogWinPrize')[awardScrollCount++].scrollIntoView(false);
$(window).scrollTop(0);
JQlogRedPoint.text(--winPrizeNum);
if (winPrizeNum === 0) JQlogRedPoint.hide();
}
} else {
layer.style(logIndex, {
'display': 'none'
});
}
})
};
let p1 = $.Deferred(), p2 = $.Deferred(), p3 = $.Deferred();
try {
// 设置token
BAPI.setCommonArgs(Live_info.bili_jct);
p1.resolve()
} catch (err) {
MYERROR(`设置token错误`, err);
p1.reject();
}
try {
MY_API.loadConfig().then(() => {
MY_API.chatLog('脚本载入配置成功', 'success');
p2.resolve()
});
} catch (e) {
MYERROR('API初始化出错', e);
MY_API.chatLog('API初始化出错', 'error');
p2.reject()
}
try {
MY_API.loadCache().then(() => {
window.toast('CACHE载入成功', 'success')
p3.resolve()
});
} catch (e) {
MYERROR('CACHE初始化出错', e);
window.toast('CACHE初始化出错', 'error')
p3.reject()
}
return $.when(p1, p2, p3);
},
loadConfig: () => {
// 加载配置函数
let p = $.Deferred();
try {
MY_API.CONFIG = GM_getValue("CONFIG") || {};
mergeObject(MY_API.CONFIG, MY_API.CONFIG_DEFAULT);
// 载入礼物统计
MY_API.loadGiftCount();
p.resolve()
} catch (e) {
MYDEBUG('API载入配置失败,加载默认配置', e);
MY_API.setDefaults();
p.reject()
}
return p
},
loadCache: () => {
// 加载CACHE
let p = $.Deferred();
try {
MY_API.CACHE = GM_getValue("CACHE") || {}
mergeObject(MY_API.CACHE, MY_API.CACHE_DEFAULT);
p.resolve()
} catch (e) {
MYDEBUG('CACHE载入配置失败,加载默认配置', e);
MY_API.setDefaults();
p.reject()
}
return p
},
newMessage: (version) => {
try {
const cache = SP_CONFIG.lastShowUpdateMsgVersion;
if (cache === undefined || cache === null || versionStringCompare(cache, version) === -1) { // cache < version
const mliList = [
"重构了BAPI中的ajax请求,现在请求出错时能返回错误原因。",
"修复刷新直播间不生效的bug。",
"天选时刻模块新增BLTH-server相关功能(测试中)。"
];
let mliHtml = "";
for (const mli of mliList) {
mliHtml = mliHtml + "<mli>" + mli + "</mli>";
}
layer.open({
title: `${version}更新提示`,
area: [String($(window).width() * 0.382) + 'px', String($(window).height() * 0.618) + 'px'],
content: `<mol>${mliHtml}</mol>
<hr><em style="color:grey;">
如果使用过程中遇到问题,欢迎去 ${linkMsg('https://github.com/andywang425/BLTH/issues', 'github')}反馈。
也可以进q群讨论:${linkMsg("https://jq.qq.com/?_wv=1027&k=fCSfWf1O", '1106094437')},${linkMsg('https://jq.qq.com/?_wv=1027&k=Bf951teI', '907502444(新)')}
</em>`
});
SP_CONFIG.lastShowUpdateMsgVersion = version;
saveSpConfig();
}
} catch (e) {
MYDEBUG('提示信息CACHE载入失败', e);
}
},
saveConfig: (show = true) => {
// 保存配置函数
try {
GM_setValue("CONFIG", MY_API.CONFIG);
if (show) window.toast('配置已保存,部分设置需刷新后才能生效', 'info');
MYDEBUG('MY_API.CONFIG', MY_API.CONFIG);
return true
} catch (e) {
MYDEBUG('API保存出错', e);
return false
}
},
saveCache: (logswitch = true) => {
// 保存缓存函数
try {
GM_setValue("CACHE", MY_API.CACHE);
if (logswitch) MYDEBUG('CACHE已保存', MY_API.CACHE)
return true
} catch (e) {
MYDEBUG('CACHE保存出错', e);
return false
}
},
setDefaults: () => {
// 重置配置函数
MY_API.CONFIG = MY_API.CONFIG_DEFAULT;
MY_API.CACHE = MY_API.CACHE_DEFAULT;
MY_API.saveConfig();
MY_API.saveCache();
layer.msg('配置和CACHE已重置为默认。3秒后刷新页面', { icon: 1 });
setTimeout(() => {
window.location.reload()
}, 3000);
},
ReDoAllTasks: () => {
window.toast('3秒后再次执行所有任务', 'info');
const taskList = [
function () { MY_API.CACHE = MY_API.CACHE_DEFAULT },
MY_API.GroupSign.run, // 应援团签到
MY_API.DailyReward.run, // 每日任务
MY_API.LiveReward.run, // 直播每日任务
MY_API.Exchange.runS2C, // 银瓜子换硬币
MY_API.Exchange.runC2S, // 硬币换银瓜子
MY_API.Gift.run, // 送礼物
MY_API.LITTLE_HEART.run, // 小心心
MY_API.AUTO_DANMU.run, // 发弹幕
MY_API.MaterialObject.run, // 实物抽奖
MY_API.AnchorLottery.run, // 天选时刻
MY_API.MEDAL_DANMU.run, // 粉丝勋章打卡弹幕
];
runAllTasks(3000, 200, taskList);
},
loadGiftCount: () => { // 读取统计数量
try {
let giftCount = MY_API.GIFT_COUNT_DEFAULT;
MY_API.GIFT_COUNT = $.extend(true, giftCount, GM_getValue("GIFT_COUNT") || {});
MYDEBUG('MY_API.GIFT_COUNT', MY_API.GIFT_COUNT);
} catch (e) {
MYDEBUG('读取统计失败', e);
}
},
saveGiftCount: (show = true) => {
try {
GM_setValue(`GIFT_COUNT`, MY_API.GIFT_COUNT);
if (show) MYDEBUG('统计保存成功', MY_API.GIFT_COUNT);
return true
} catch (e) {
MYDEBUG('统计保存出错', e);
return false
}
},
addAnchor: (count = 1) => {
MY_API.GIFT_COUNT.ANCHOR_COUNT += count;
$('#giftCount .anchor .statNum').text(MY_API.GIFT_COUNT.ANCHOR_COUNT);
MY_API.saveGiftCount(false);
},
addMaterial: (count = 1) => {
MY_API.GIFT_COUNT.MATERIAL_COUNT += count;
$('#giftCount .material .statNum').text(MY_API.GIFT_COUNT.MATERIAL_COUNT);
MY_API.saveGiftCount(false);
},
removeUnnecessary: () => {
// 移除不必要的页面元素
const unnecessaryObj = [
{
// 2233
settingName: 'REMOVE_ELEMENT_2233',
rmJQpath: ['#my-dear-haruna-vm']
},
{
// 活动入口
settingName: 'REMOVE_ELEMENT_activity',
rmJQpath: ['.activity-entry']
},
{
// 排行榜
settingName: 'REMOVE_ELEMENT_rank',
rmJQpath: ['.activity-rank']
},
{
// 关注按钮及弹窗
settingName: 'REMOVE_ELEMENT_followSideBar',
rmJQpath: ['div[data-upgrade-intro="Follow"]', '.side-bar-popup-cntr.ts-dot-4']
},
{
// 礼物栏下方广告
settingName: 'REMOVE_ELEMENT_flipView',
rmJQpath: ['.flip-view']
},
{
// 天选时刻弹窗及图标
settingName: 'REMOVE_ELEMENT_anchor',
addCss: '.anchor-lottery-entry * {display: none;} #anchor-guest-box-id * {display: none;}',
eval: `setInterval(() => {$("iframe").contents().find("#app .close-btn").click()}, 200)`
},
{
// PK弹窗及进度条
settingName: 'REMOVE_ELEMENT_pk',
addCss: '.process-box * {display: none;} #chaos-pk-vm * {display:none;}',
eval: `setInterval(() => {$("iframe").contents().find("#app .closeBtn").click()}, 200)`
},
{
// 直播水印
settingName: 'REMOVE_ELEMENT_playerIcon',
rmJQpath: ['.web-player-icon-roomStatus']
}
];
const removeElement = (obj) => {
if (MY_API.CONFIG[obj.settingName]) {
if (obj.hasOwnProperty('rmJQpath')) {
for (const path of obj.rmJQpath) {
let timer = setInterval(() => {
const unnecessaryItem = $(path);
if (unnecessaryItem.length > 0) {
unnecessaryItem.remove();
clearInterval(timer)
}
}, 200);
}
}
if (obj.hasOwnProperty('addCss')) GM_addStyle(obj.addCss);
if (obj.hasOwnProperty('eval')) eval(obj.eval);
}
};
for (const i of unnecessaryObj) {
removeElement(i);
};
},
buyFanMedal: (room_id) => {
return BAPI.live_user.get_anchor_in_room(room_id).then(function (response) {
MYDEBUG('API.live_user.get_anchor_in_room response', response)
if (response.code === 0 && response.data.info) {
const uid = String(response.data.info.uid),
uname = response.data.info.uname;
layer.confirm(`<div style = "text-align:center">是否消耗20硬币购买UP主<br>${linkMsg("https://space.bilibili.com/" + uid, uname)}<br>的粉丝勋章?</div>`, {
title: `购买勋章 房间号:${room_id}`,
btn: ['是', '否']
}, function () {
BAPI.link_group.buy_medal(response.data.info.uid).then((re) => {
MYDEBUG('API.link_group.buy_medal re', re);
if (re.code === 0) {
layer.msg('购买成功', {
time: 2000,
icon: 1
});
} else {
layer.msg(`购买失败 ${re.message}`, {
time: 2500,
icon: 2