/
userTag.ts
1587 lines (1518 loc) · 67.9 KB
/
userTag.ts
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 lycoris
// @version 2.6.2
// @description 根据 Bilibili 用户近期动态、粉丝勋章内容检测成分添加自定义标签,按规则屏蔽评论
// @author Lyzoris
// @supportURL https://github.com/lyzoris/Bilibili-UserComponentTag
// @compatible chrome 80 or later
// @compatible edge 80 or later
// @match https://www.bilibili.com
// @match https://www.bilibili.com/video/*
// @match https://www.bilibili.com/opus/*
// @match https://t.bilibili.com/*
// @match https://space.bilibili.com/*
// @match https://www.bilibili.com/bangumi/play/*
// @match https://www.bilibili.com/read/*
// @icon https://static.hdslb.com/images/favicon.ico
// @connect bilibili.com
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_setClipboard
// @require https://greasyfork.org/scripts/448895-elementgetter%E5%BA%93/code/ElementGetter%E5%BA%93.js?version=1106656
// @license MIT
// @run-at document-end
// ==/UserScript==
(function() {
"use surict"
const elmGetter = new ElementGetter();
const Cookie:string = document.cookie
const goOldVideo = Cookie.match(/(?<=go_old_video=)[-\d]{1,2}/)
let isNew:boolean = true
if(Cookie && goOldVideo){
isNew = goOldVideo[0] === '-1'
}// 检测B站版本
console.log('版本: '+isNew)
let Page:string = ''; // 页面
const webType:{[key:string]:string}= {'^https:\/\/www.bilibili.com[\/]$':'Main', 'https:\/\/(t|space).bilibili.com':'Dynamic', 'https:\/\/www.bilibili.com\/video':'Video'};
Object.keys(webType).map(urlReg=>{if(RegExp(urlReg).test(location.href)){Page = webType[urlReg]}}) // 检测当前页面
const ApiUrl:{[key:string]:string} = {
blog:'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?offset=&host_mid=',
concerns:'https://api.bilibili.com/x/relation/followings?vmid=',
medal: 'https://api.live.bilibili.com/xlive/web-ucenter/user/MedalWall?target_id='
};
const childTagReg = new RegExp(/^(\[.*?\])(\[.*?\])*(\[.*?\])$/);
const tagClassHide:{[key:string]:string} = {
true:'.tag-class {display:none;}',
false:'.tag-class {display:flex;}'
}
const Style_tagClassHide = elmGetter.create(`<style>${tagClassHide.false}</style>`)
const ScriptStyle_STR:string = `
<style>
.adblock-tips{
display:none!important;
}
.userTag {
display: inline-block;
position: relative;
text-align: center;
border-width: 0px;
vertical-align: sub;
margin-left: 4px;
margin-right:4px;
cursor: default;
}
.tag-name {
border-color: rgba(169, 195, 233, 0.1803921568627451);
color: rgba(87, 127, 184, 1);
background-color: #9ebae833;
float: left;
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: center;
border-width: 0.5px;
border-style: solid;
border-bottom-left-radius: 1px;
border-top-left-radius: 1px;
height: 16px;
}
.tag-class {
position: relative;
border-bottom-right-radius: 1px;
border-top-right-radius: 1px;
float: left;
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: center;
box-sizing: content-box;
border-width: 0.5px;
border-color: #f25d8e;
border-style: solid;
border-bottom-left-radius: 1px;
border-top-left-radius: 1px;
color: #f25d8e;
height: 16px;
}
.tag-font {
font-weight: 400;
font-size: 10px;
}
.script-hide {
position: fixed;
right: 10px;
bottom: 10px;
width: 20px;
height: 20px;
font-size: 15px;
line-height: 20px;
text-align: center;
color: #009688;
background-color: #e2e1e2b3;
border-radius: 5px;
box-shadow: 2px 0px 4px 0px #0000002b;
}
.script-hide svg{
width: 100%;
height: 100%;
vertical-align: unset;
}
.script-hide:hover {
background-color: #76cb9dc9;
box-shadow: 2px 0px 4px 0px #76cb9d91;
}
.script-hide:hover svg path {
fill: #ffffff;
}
.script-like{
display: none;
position: fixed;
right: 10px;
bottom: 40px;
width: 20px;
height: 20px;
font-size: 15px;
line-height: 26px;
text-align: center;
color: #009688;
background-color: #e2e1e2b3;
border-radius: 5px;
box-shadow: 2px 0px 4px 0px #0000002b;
}
.script-like:hover{
background-color: #76cb9dc9;
box-shadow: 2px 0px 4px 0px #76cb9d91;
}
.script-like svg{
width: 80%;
height: 80%;
margin-left: 1px;
vertical-align: unset;
}
.script-like:hover svg path {
fill: #ffffff;
}
.tagbar-active {
background-color: #ab85d1c9;
box-shadow: 2px 0px 4px 0px #c893e291;
}
.tagbar-active svg path {
fill: #ffffff;
}
.script-main {
display: none;
position: fixed;
z-index: 999;
right: 65px;
bottom: 20px;
background-color: #ffffff;
color: #929292;
height: 320px;
width: 270px;
border-radius: 4px;
box-sizing: border-box;
box-shadow: 0px 0px 4px 2px #0000002b;
padding: 10px;
}
svg.icon {
width: 10px;
height: 10px;
}
.tagbar-action {
position: absolute;
top: 2px;
width: 15px;
height: 15px;
line-height: 15px;
margin: 0;
border-radius: 50%;
background-color: #fff0;
text-align: center;
font-size: small;
color: #929292;
}
.script-main input[type="checkbox"],input[type="radio"]{
appearance: auto;
}
.tagbar-btn {
background-color: #ffffff;
color: #929292;
height: 20px;
margin: 5px 0px 5px 0;
padding: 0 4px 0 4px;
border: none;
border-radius: 4px;
font-weight: bold;
transform-origin: center;
transform: scale(0.9) translate(-10%, -10%);
font-size: 13px;
text-align: center;
box-shadow: #b1b1b13d 0px 0px 3px 2px;
}
.tagbar-btn:hover {
color: #37a279ab;
}
.tagbar-btn:active {
color: #b4b6ee;
}
.input-tag,#input-comment-reg {
margin-bottom: 4px;
width: 74%;
left: 20%;
border-radius: 4px;
border: solid 1px #b0b0b0;
}
.input-tag:focus,#input-comment-reg:focus {
outline: none;
background-color: #d5d5d559;
}
.tagbar-label {
font-size: 12px;
display: inline-block;
margin-right: 10px;
}
#input-tagcolor {
width: 52px;
height: 20px;
border-radius: 4px;
border: solid 1px #b0b0b0;
}
.tags {
display: inline-block;
width: 40px;
height: 20px;
font-size: 12px;
border-radius: 5px;
color: #49414b;
text-align: center;
transform-origin: center;
transform: scale(0.9) translate(-10%, -10%);
line-height: 20px;
background-color: #ededed;
margin-top: 5px;
margin-left: 5px;
cursor: pointer;
box-shadow: 0px 1px 5px 0 #00000033;
}
.tags:hover {
background-color: #ced1d2c4;
}
.delete-tag {
position: relative;
top: -3px;
right: 0;
width: 20px;
height: 20px;
border-radius: 50%;
transform-origin: center;
transform: scale(0.6) translate(-50%, -50%);
font-size: 20px;
color: #ffffff00;
line-height: 18px;
background-color: #ffffff00;
}
.delete-tag:hover{
color: white!important;
background-color: crimson!important;
}
.tags:hover > .delete-tag{
color: #434343fa;
background-color: #bbb5b54d;
}
.tag-info {
position: relative;
margin-top: -20px;
line-height: unset;
font-weight: bold;
}
.scriptBar{
display: flex;
flex-direction: column;
margin-top: 25px;
height: 92%;
}
.tagbar-taglist, .tagbar-commentlist {
margin-top: 5px;
width: 100%;
flex: auto;
bottom: 0px;
border-radius: 4px;
background-color: rgb(243, 238, 233);
overflow-y: auto;
padding: 4px;
box-sizing: border-box;
}
.tagbar-taglist::-webkit-scrollbar,
.tagbar-commentlist::-webkit-scrollbar,
.medal-table::-webkit-scrollbar,
#import-area::-webkit-scrollbar {
width: 4px;
height: 4px;
}
.tagbar-taglist::-webkit-scrollbar-thumb,
.tagbar-commentlist::-webkit-scrollbar-thumb,
.medal-table::-webkit-scrollbar-thumb,
#import-area::-webkit-scrollbar-thumb {
border-radius: 5px;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
background: rgba(0, 0, 0, 0.2);
}
.tagbar-taglist::-webkit-scrollbar-track,
.tagbar-commentlist::-webkit-scrollbar-track,
.medal-table::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
border-radius: 0px;
background: rgba(0, 0, 0, 0.1);
}
.tagSize {
margin: 5px 0 5px 0;
}
.tagSize-label {
display: inline-block;
text-align: center;
}
.tagSize-radio {
vertical-align: text-bottom;
}
.set-label {
font-size: 12px;
display: inline-block;
margin: 5px 0 5px 0;
}
.medalTag {
margin-left: 5px;
cursor: pointer;
}
.medal-table {
display: none;
position: absolute;
padding: 5px;
max-width: 230px;
max-height: 160px;
overflow-y: auto;
font-size: 12px;
background-color: #fffefd;
border-radius: 5px;
cursor: default;
z-index: 2;
box-shadow: 0px 0px 4px 2px #0000002b;
}
.fans-tag {
float: left;
margin: 4px 4px 4px 4px;
border: solid 1px #6a99de;
border-radius: 2px;
}
.fans-tag .tag-name {
border: none;
width: 18px;
}
#import-area {
font-size: 10px;
margin: 10px 0 0 0;
max-width: 244px;
min-width: 244px;
height: 40px;
min-height: 20px;
max-height: 40px;
background-color: #f3f3f3;
border-radius: 5px;
}
#import-area:focus {
outline: none;
}
.topnav {
top: 8px;
left: 5px;
height: 20px;
line-height: 20px;
position: absolute;
color: #8e8e8e;
background-color: #ddddd98c;
border-radius: 4px;
cursor: default;
}
.topnav-active {
color: #dd7a7a;
background-color: #ffffff;
border-radius: 4px;
height: 16px;
line-height: 16px;
box-shadow: 0 0 3px 1px #3f3d3d80;
}
.topnav-option {
display: inline-block;
font-size: 12px;
font-weight: bold;
padding: 0 5px 0 5px;
}
.topnav-option:nth-child(2) {
margin: 0 38px 0 38px;
}
#dynamic-like svg{
width: 25px;
height: 25px;
margin: 0 0 0 25px;
}
#dynamic-like:hover svg path{
fill: #19aada;
}
.search-btn{
display: inline-block;
font-size: 15px;
background-color: #eef1f3;
color: #377f79b3;
width: 44px;
border-radius: 10px;
text-align: center;
margin: 0 5px 0 5px!important;
transform: scale(0.8) translate(-15%, 0%);
box-shadow: none;
cursor: default;
}
.search-btn:hover{
color: #9c27b0;
box-shadow: 0px 0px 3px 1px #33323229;
}
.block-btn{
margin: 0 20px 0 20px;
cursor: pointer;
}
.block-btn:hover{
color: #00aeec;
}
.search-btn:active{
color: #dd4438;
}
.close-btn{
text-align: center;
font-size: 14px;
color: #99a2aa;
border-top: 1px solid #e5e9ef;
margin: 0;
overflow: hidden;
padding: 12px 0 10px;
position: relative;
}
.close-btn a{
color: #99a2aa!important;
}
.close-btn a:hover{
color: #e132c2!important;
}
#detectionMode,#blockUser{
display: inline-block;
font-size: 14px;
font-weight: bold;
text-align: center;
width: 250px;
margin: 4px 0 8px 0;
cursor: default;
}
#detectionMode-input,#blockUser-input {
display: none;
}
#detectionMode-label {
display: inline-block;
width: 50px;
height: 16px;
border-radius: 16px;
background: #4fb153;
border: 1px solid #eee;
cursor: pointer;
position: relative;
overflow: hidden;
margin: 0 8px 0 8px;
vertical-align: text-bottom;
}
#detectionMode-label::before,#blockUser-label::before {
display: block;
content: '';
width: 16px;
height: 16px;
border-radius: 50%;
background: white;
position: absolute;
left: 0px;
top: 50%;
transform: translateY(-50%);
transition: all .3s;
}
#detectionMode-label::after {
display: block;
content: '';
width: 0;
height: 100%;
background: #2695dc;
transition: all .3s;
border-radius: 10px;
}
#detectionMode-manual{
color:#4fb153;
}
#detectionMode-input:checked ~ #detectionMode-label::before {
left: 34px;
}
#detectionMode-input:checked ~ #detectionMode-label::after {
width: 100%;
}
#detectionMode-input:checked ~ #detectionMode-auto {
color: #2695dc;
}
#detectionMode-input:checked ~ #detectionMode-manual {
color: #929292;
}
#blockUser-label {
display: inline-block;
width: 50px;
height: 16px;
border-radius: 16px;
background: #929292;
border: 1px solid #eee;
cursor: pointer;
position: relative;
overflow: hidden;
margin: 0 8px 0 8px;
vertical-align: text-bottom;
}
#blockUser-label::after {
display: block;
content: '';
width: 0;
height: 100%;
background: #4fb153;
transition: all .3s;
border-radius: 10px;
}
#blockUser-input:checked ~ #blockUser-label::before {
left: 34px;
}
#blockUser-input:checked ~ #blockUser-label::after {
width: 100%;
}
#blockUser-input:checked ~ #blockUser-manual {
color: #4fb153;
}
#reg-ruler:hover{
color: #81afc5;
}
#reg-ruler:active{
color: #cc6d89;
}
#detect-page{
height: 5px;
width: 100px;
}
#offset-page{
padding-left: 20px;
}
</style>
`;
const ScriptBody_STR:string = `
<div id='Script-Body'>
<div class='script-like'>
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<path d="M857.28 344.992h-264.832c12.576-44.256 18.944-83.584 18.944-118.208 0-78.56-71.808-153.792-140.544-143.808-60.608 8.8-89.536 59.904-89.536 125.536v59.296c0 76.064-58.208 140.928-132.224 148.064l-117.728-0.192A67.36 67.36 0 0 0 64 483.04V872c0 37.216 30.144 67.36 67.36 67.36h652.192a102.72 102.72 0 0 0 100.928-83.584l73.728-388.96a102.72 102.72 0 0 0-100.928-121.824zM128 872V483.04c0-1.856 1.504-3.36 3.36-3.36H208v395.68H131.36A3.36 3.36 0 0 1 128 872z m767.328-417.088l-73.728 388.96a38.72 38.72 0 0 1-38.048 31.488H272V476.864a213.312 213.312 0 0 0 173.312-209.088V208.512c0-37.568 12.064-58.912 34.72-62.176 27.04-3.936 67.36 38.336 67.36 80.48 0 37.312-9.504 84-28.864 139.712a32 32 0 0 0 30.24 42.496h308.512a38.72 38.72 0 0 1 38.048 45.888z" fill="#459cdd"></path>
</svg>
</div>
<div class='script-hide'>
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<path d="M593.949942 770.425747c2.908236-4.233418 4.614088-9.380648 4.614088-14.892175s-1.705851-10.658757-4.614088-14.922874L431.084621 577.00041c-10.32209-10.324136-10.32209-27.042913 0-37.381375l158.601204-159.117974c5.376451-4.843308 8.771781-11.818163 8.771781-19.61371 0-14.602579-11.83249-26.433022-26.434046-26.433022-5.953595 0-11.420097 1.979074-15.835663 5.298679l-5.300726 5.299703L375.020744 520.936533c-20.650319 20.647249-20.650319 54.114478 0 74.763774l177.556928 177.590698 1.811252 1.794879c4.690836 4.264117 10.903328 6.884804 17.740036 6.884804C581.18829 781.968641 589.183382 777.399579 593.949942 770.425747z" fill="#009688"></path>
</svg>
</div>
<div class='script-main'>
<div class="topnav">
<div class="topnav-option topnav-active" index=1 id="tag-btn">成分标签</div>
<div class="topnav-option" id="comment-btn" index=2>评论屏蔽</div>
<div class="topnav-option" id="setting-btn" index=0>脚本设置</div>
</div>
<div class="scriptBar setting-bar" style="display:none;">
<div class="inputBar">
<input type="button" class="tagbar-btn" id="export-tag" value="导出配置" title="导出标签配置到剪切板" style="float:left; margin:0;">
<input type="button" class="tagbar-btn" id="import-tag" value="导入配置" title="导入配置到油猴存储 请先将配置粘贴到下方并确认无误,再点击本按键 导入配置后请刷新界面以应用配置" style="float:right; margin:0;">
</div>
<textarea id="import-area" placeholder="请在此处粘贴配置后点击【导入配置】"></textarea>
<label class="set-label" title="用户标签检测内容(可多选)">检测选项
<label for="detect-repost" title="检测用户转发的动态内容(建议开启)" style="margin-left:20px">转发动态
<input type="checkbox" id="detect-repost" style="margin-left:5px;height:11px">
</label>
<label for="detect-concerns" title="检测用户关注列表" style="margin-left:20px">关注列表
<input type="checkbox" id="detect-concerns" style="margin-left:5px;height:11px">
</label>
<label for="detect-medal" title="检测用户的粉丝勋章 开启后用户标签末尾出现【勋章】标签, 点击【勋章】展开勋章栏显示所有勋章 鼠标放上显示对应Up主,点击可跳转 点击【勋章】或空白处收起" style="margin-left:72px">
粉丝勋章<input type="checkbox" id="detect-medal" style="margin-left:8px;height:11px">
</label>
</label>
<label class="set-label" for="detect-page" title="检测用户动态和关注列表页数 越大加载时间越长">检测页数<span id="offset-page">1</span><input type="range" id="detect-page" value=1 max=10 min=1 step=1 style="margin-left:50px;height:11px"></label>
<label class="set-label" for="tagClass-hide" title="不显示标签分类,建议开启 出现标签样式错误时请开启此项">标签不显示分类<input type="checkbox" id="tagClass-hide" style="margin-left:50px;height:11px"></label>
<label class="set-label" for="tag-merge" title="相同类型标签合并,只显示一个标签分类 可能影响标签样式,建议同时打开【标签不显示分类】">同类型标签合并<input type="checkbox" id="tag-merge" style="margin-left:50px;height:11px"></label>
<label class="set-label" for="link-delete" title="去除 评论区评论关键词蓝色点击跳转">去除关键词跳转<input type="checkbox" id="link-delete" style="margin-left:50px;height:11px"></label>
<label class="set-label" for="close-comment" title="动态评论末尾添加【收起评论】按键">动态添加收起评论<input type="checkbox" id="close-comment" style="margin-left:38px;height:11px"></label>
<label class="set-label" for="dynamic-btn" title="动态页面添加【批量点赞】按键">动态页批量点赞<input type="checkbox" id="dynamic-btn" style="margin-left:50px;height:11px"></label>
</div>
<div class="scriptBar tag-bar">
<div class="inputBar">
<div id="detectionMode">
<input type="checkbox" id="detectionMode-input">
<span id="detectionMode-manual" title="手动点击‘检测’以检测用户标签 请求量较少,比较安全">手动检测</span>
<label for="detectionMode-input" id="detectionMode-label"></label>
<span id="detectionMode-auto" title="自动检测所有评论用户标签 请求量较大,存在封号风险">自动检测</span>
</div>
<label class="tagbar-label" for="input-tagname" title="标签的分类,比如游戏、Vtuber、主播、UP主等 用来识别标签类型,尽量短一些">标签分类</label><input type="text" id="input-tagname" index=0 class="input-tag" autocomplete="off">
<label class="tagbar-label" for="input-tagtext" title="标签具体显示的内容,以区别每个标签">标签内容</label><input type="text" id="input-tagtext" index=1 class="input-tag" autocomplete="off">
<label class="tagbar-label" for="input-tagreg" title="匹配用户标签的关键词,使用 & 和 | 分隔,使用 ( ) 组合 多关键词任一匹配:王者荣耀或王者 -> 王者荣耀|王者 多关键词同时匹配:王者荣耀与吃鸡 -> 王者荣耀&吃鸡 多关键词组合匹配:(王者|王者荣耀)&(吃鸡|和平精英) 合并标签时填写 [子标签内容][子标签内容] 如[王者][原神] 注意:面板中合并标签需在所有子标签之后">标签规则</label><input type="text" id="input-tagreg" index=2 class="input-tag" autocomplete="off">
<label class="tagbar-label" for="input-tagcolor" title="标签文字颜色,可在面板中预览">标签颜色</label><input type="color" name="" id="input-tagcolor">
<label class="tagbar-label" style="margin: 0 18px 0 10px ;" for="tag-hide" title="屏蔽该标签用户评论">屏蔽评论<input type="checkbox" id="tag-hide" style="margin-left:9px;height:11px"></label>
<input type="button" class="tagbar-btn" id="add-tag" value="+" style="width:30px">
</div>
<div class="tagbar-taglist"></div>
</div>
<div class="scriptBar comment-bar" style="display:none;">
<div class="inputBar">
<label class="set-label" title="点击开启指定屏蔽功能(可多选) 在对应页面生效">屏蔽选项
<label for="block-video" title="【主页】按规则屏蔽主页推荐视频" style="margin-left:20px">主页推荐
<input type="checkbox" id="block-video" style="margin-left:5px;height:11px">
</label>
<label for="block-dynamic" title="【动态、空间页】按规则屏蔽用户动态内容" style="margin-left:20px">用户动态
<input type="checkbox" id="block-dynamic" style="margin-left:5px;height:11px">
</label>
<label for="block-comment" title="【视频页】按规则屏蔽用户评论" style="margin-left:72px">
评论内容<input type="checkbox" id="block-comment" style="margin-left:8px;height:11px">
</label>
<label for="block-user" title="【动态、视频页】需先打开 “评论内容” 选项 点击 “屏蔽” 按键以手动屏蔽用户 同时添加用户id到黑名单" style="margin-left:20px">
用户屏蔽<input type="checkbox" id="block-user" style="margin-left:8px;height:11px">
</label>
</label>
<label class="tagbar-label" for="input-comment-reg" id="reg-ruler" title="正则表达式屏蔽规则 可屏蔽首页视频推荐,用户动态,用户评论 不了解正则表达式?按Alt点击跳转学习">屏蔽规则</label><input type="text" id="input-comment-reg" autocomplete="off" style="width:64%;">
<input type="button" class="tagbar-btn" id="add-comment-reg" style="float:right; margin:2px 0 5px 0; width:18px;" value="+">
</div>
<div class="tagbar-commentlist"></div>
</div>
</div>
</div>`;
const ScriptBody:HTMLDivElement = elmGetter.create(ScriptBody_STR);
const ScriptStyle:HTMLStyleElement = elmGetter.create(ScriptStyle_STR);
const Head = document.head || document.querySelector('head') as HTMLHeadElement;
const Body = document.body || document.querySelector('body') as HTMLBodyElement;
Head.appendChild(ScriptStyle);
Head.appendChild(Style_tagClassHide);
Body.appendChild(ScriptBody);
const scriptHide = ScriptBody.querySelector('.script-hide') as HTMLDivElement;
const scriptMain = ScriptBody.querySelector('.script-main') as HTMLDivElement;
const topNav = ScriptBody.querySelectorAll('.topnav-option') as NodeListOf<HTMLDivElement>;
const scriptBar = ScriptBody.querySelectorAll('.scriptBar') as NodeListOf<HTMLDivElement>;
const inputFields = ScriptBody.querySelectorAll('.input-tag') as NodeListOf<HTMLInputElement>;
let tagClass_hide = ScriptBody.querySelector('#tagClass-hide') as HTMLInputElement;
let tag_merge = ScriptBody.querySelector('#tag-merge') as HTMLInputElement;
let detect_repost = ScriptBody.querySelector('#detect-repost') as HTMLInputElement;
let detect_concerns = ScriptBody.querySelector('#detect-concerns') as HTMLInputElement;
let detect_medal = ScriptBody.querySelector('#detect-medal') as HTMLInputElement;
let detection_mode = ScriptBody.querySelector('#detectionMode-input') as HTMLInputElement;
let detect_page = ScriptBody.querySelector('#detect-page') as HTMLInputElement;
let offset_page = ScriptBody.querySelector('#offset-page') as HTMLSpanElement;
let link_delete = ScriptBody.querySelector('#link-delete') as HTMLInputElement;
let close_comment = ScriptBody.querySelector('#close-comment') as HTMLInputElement;
let import_area = ScriptBody.querySelector('#import-area') as HTMLInputElement;
let tag_name = ScriptBody.querySelector('#input-tagname') as HTMLInputElement;
let tag_text = ScriptBody.querySelector('#input-tagtext') as HTMLInputElement;
let tag_reg = ScriptBody.querySelector('#input-tagreg') as HTMLInputElement;
let tag_color = ScriptBody.querySelector('#input-tagcolor') as HTMLInputElement;
let add_tag = ScriptBody.querySelector('#add-tag') as HTMLInputElement;
let import_tag = ScriptBody.querySelector('#import-tag') as HTMLInputElement;
let export_tag = ScriptBody.querySelector('#export-tag') as HTMLInputElement;
let taglist = ScriptBody.querySelector('.tagbar-taglist') as HTMLDivElement;
let tag_hide = ScriptBody.querySelector('#tag-hide') as HTMLInputElement;
let add_comment = ScriptBody.querySelector('#add-comment-reg') as HTMLInputElement;
let comment_reg = ScriptBody.querySelector('#input-comment-reg') as HTMLInputElement;
let commentlist = ScriptBody.querySelector('.tagbar-commentlist') as HTMLDivElement;
let dynamic_btn = ScriptBody.querySelector('#dynamic-btn') as HTMLInputElement;
let script_like = ScriptBody.querySelector('.script-like') as HTMLDivElement;
let reg_ruler = ScriptBody.querySelector('#reg-ruler') as HTMLLabelElement;
let block_user = ScriptBody.querySelector('#block-user') as HTMLInputElement;
let block_comment = ScriptBody.querySelector('#block-comment') as HTMLInputElement;
let block_dynamic = ScriptBody.querySelector('#block-dynamic') as HTMLInputElement;
let block_video = ScriptBody.querySelector('#block-video') as HTMLInputElement;
// 输入框上下切换
inputFields.forEach(e=>{e.onkeyup=(event)=>{
let index = Number((event.target as HTMLInputElement)?.getAttribute('index'));
if(['Enter', 'ArrowDown'].includes(event.key)){
index = index == 2 ? 0 : index + 1;
}else if(event.key=='ArrowUp'){
index = index == 0 ? 2 : index - 1;
}
inputFields[index].focus();
}});
// 脚本展开
scriptHide.onclick = () => {
if (scriptMain.style.display === 'block') {
scriptMain.style.display = 'none';
scriptHide.classList.remove('tagbar-active');
} else {
scriptMain.style.display = 'block';
scriptHide.classList.add('tagbar-active');
}
};
// 界面切换
topNav.forEach(btn => {
btn.onclick = () =>{
topNav.forEach(i => {i.classList.remove('topnav-active')});
btn.classList.add('topnav-active');
scriptBar.forEach(i => {i.style.display = 'none'});
scriptBar[Number(btn.getAttribute('index'))].style.display = 'flex'; // 设置 scriptBar 的 display 为 flex 而非 block
}
});
// 点击 ”屏蔽规则“ 跳转正则页面
reg_ruler.onclick = (event) =>{
event.altKey && window.open('https://gitee.com/thinkyoung/learn_regex');
}
// 屏蔽用户
block_user.onclick = () =>{
BlockOption.User = block_user.checked;
GM_setValue('BlockOption', BlockOption);
}
// 屏蔽主页
block_video.onclick = () =>{
BlockOption.Video = block_video.checked;
GM_setValue('BlockOption', BlockOption);
if(block_video.checked && Page === 'Main'){
mainPageBlock();
}
}
// 屏蔽动态
block_dynamic.onclick = ()=>{
BlockOption.Dynamic = block_dynamic.checked;
GM_setValue('BlockOption', BlockOption);
if(block_dynamic.checked && Page === 'Dynamic'){
dynamicPageBlock();
}
}
// 屏蔽评论
block_comment.onclick = ()=>{
BlockOption.Comment = block_comment.checked;
GM_setValue('BlockOption', BlockOption);
}
// 标签检测模式选择(true:自动检测,false:手动检测)
detection_mode.onclick = ()=>{
AutoDetect = detection_mode.checked;
GM_setValue('AutoDetect',AutoDetect);
}
// 动态页面增加点赞按键
dynamic_btn.onclick = ()=>{
script_like.style.display = dynamic_btn.checked? 'block': 'none';
GM_setValue('DynamicLike',dynamic_btn.checked);
};
script_like.onclick = dynamicBatchLike;
// 隐藏标签分类
tagClass_hide.onclick = ()=>{
Style_tagClassHide.innerHTML = tagClassHide[String(tagClass_hide.checked)];
GM_setValue('TagClassHide', tagClass_hide.checked);
};
// 检测选项
detect_repost.onclick = ()=>{
DetectOption.Repost = detect_repost.checked;
GM_setValue('DetectOption',DetectOption);
}
detect_concerns.onclick = ()=>{
DetectOption.Concerns = detect_concerns.checked;
GM_setValue('DetectOption',DetectOption);
}
detect_medal.onclick = () =>{
DetectOption.Medal = detect_medal.checked;
GM_setValue('DetectOption',DetectOption);
}
// 检测精度
detect_page.onchange = () =>{
offset_page.innerText = detect_page.value
maxOffset = Number(detect_page.value)
GM_setValue('MaxDetectPage', maxOffset);
}
// 标签合并
tag_merge.onclick = ()=>{
tagMerge = tag_merge.checked;
GM_setValue('TagMerge',tagMerge);
}
// 去除跳转
link_delete.onclick = ()=>{ GM_setValue('NoJump', link_delete.checked)}
// 收起评论
close_comment.onclick = ()=>{
closeComment();
GM_setValue('CloseComment', close_comment.checked)
}
// 获取用户输入
add_tag.onclick = () => {
if (tag_name.value && tag_text.value && tag_reg.value) {
if(!/[\n\r"'{}、]/.test(tag_reg.value)){
addTag({
tag: tag_name.value,
text: tag_text.value,
reg: tag_reg.value,
color: tag_color.value,
hide: tag_hide.checked
});
tag_name.value = '';
tag_text.value = '';
tag_reg.value = '';
tag_hide.checked = false;
}else{
alert(`标签规则不应该包含‘ “ 、" ' { } \\n \\r等字符`);
}
} else {
alert('请将标签信息补充完整');
}
}
// 添加屏蔽正则
add_comment.onclick = () => {
if (comment_reg.value) {
addKeyWord(comment_reg.value);
comment_reg.value = '';
} else {
alert('请将关键词正则信息补充完整');
}
}
// 导出配置项到剪切板
function exportDataToClipboard(){
let exportData:{[key:string]:string|{}} = {};
let key_storage:Array<string> = GM_listValues();
key_storage.forEach(i=>{
exportData[i] = GM_getValue(i,null);
})
GM_setClipboard(JSON.stringify(exportData));
alert('已导出标签数据到剪切板!');
}
// 导入配置项到油猴
function importDataToTemperMonkey(){
if(import_area.value){
try{
let importData = JSON.parse(import_area.value);
Object.keys(importData).forEach(i=>{GM_setValue(i,importData[i])});
}catch(e){
alert('导入配置出错,请检查配置项');
return;
}
import_area.value = '';
configInit();
}else{
alert('配置为空!请先在输入框粘贴配置并检查无误后点击【导入配置】');
}
}
export_tag.onclick = exportDataToClipboard;
import_tag.onclick = importDataToTemperMonkey;
function addKeyWord(reg_text:string){
if (!keyword.includes(reg_text)) {
let new_tag = insertTag(commentlist, reg_text);
let keyword_index:number = Object.keys(temp_keyword).length;
temp_keyword[keyword_index] = reg_text;
keyword.push(reg_text);
GM_setValue('Keyword', keyword);
//移除标签
function deleteTag(){
commentlist.removeChild(new_tag);
delete temp_keyword[keyword_index];
keyword = [];
Object.keys(temp_keyword).map((key) => keyword.push(temp_keyword[key]));
GM_setValue('Keyword', keyword);
};
(new_tag.children[0] as HTMLDivElement).onclick = deleteTag;
(new_tag.children[1] as HTMLDivElement).ondblclick = () => {
comment_reg.value = reg_text;
deleteTag();
}
}
}
// 添加并保存标签
function addTag(tag_dic:{tag:string,text:string,reg:string,color:string,hide:boolean}){
// console.log(tag_dic)
let new_tag = insertTag(taglist, tag_dic);
let tag_index:number = Object.keys(tag).length;
tag[tag_index] = tag_dic;
tagList.push(tag, tag_index);
//移除标签
function deleteTag(){
taglist.removeChild(new_tag);
delete tag[tag_index]
let tag_temp = {...tag} // 深拷贝 tag
tag = {}; // 清除 tag
Object.values(tag_temp).forEach((value,i)=>{tag[i] = value}); // 重新赋值给 tag
tagList.pop(tag);
};
(new_tag.children[0] as HTMLDivElement).onclick = deleteTag;
(new_tag.children[1] as HTMLDivElement).ondblclick = () => {
tag_name.value = tag_dic.tag;
tag_text.value = tag_dic.text;
tag_reg.value = tag_dic.reg;
tag_color.value = tag_dic.color;
tag_hide.checked = tag_dic.hide;
deleteTag();
}
}
// 插入标签
function insertTag(parentNode:HTMLDivElement, tagInfo:string|{tag:string,text:string,reg:string,color:string,hide:boolean}){
let title = '';
let text = '';
let color = '#1d1d1dbd';
let border = 'none';
if(typeof(tagInfo)==='object'){ // 标签
if(childTagReg.test(tagInfo.reg)){
border = 'solid 1px #4fc3f7';
title = `分类:${tagInfo.tag} (合并标签) 子标签:${tagInfo.reg} 隐藏评论:${tagInfo.hide} 请放在待合并标签后`;
}else{
title =`分类:${tagInfo.tag} 规则:${tagInfo.reg} 隐藏评论:${tagInfo.hide}`;
}
text = tagInfo.text;
color = tagInfo.color
}else{
text = tagInfo; // 关键词
}
let new_tag = elmGetter.create(`<div class="tags" style="color:${color}; width:${measureTextWidth("12px", text) + 8}px; border:${border}">
<div class="delete-tag">x</div><p class="tag-info" title="${title}">${text}</p></div>`);
parentNode.appendChild(new_tag);
return new_tag; // 返回插入的标签节点
}
// 计算文本字符串像素宽度
function measureTextWidth(fontSize:string, text:string){
let fontFamily = 'PingFang SC, HarmonyOS_Regular, Helvetica Neue, Microsoft YaHei, sans-serif';
let canvas = document.createElement('canvas');
let context = <CanvasRenderingContext2D>canvas.getContext('2d');
context.font = `${fontSize} ${fontFamily}`;
let result = context.measureText(text);
return result.width>18 ? Math.ceil(result.width) : 18;
}
// 标签
class Tag {
child_tag:Array<string>;
tag_class:string;
text:string;
tag_id:string;
reg:RegExp;