-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdanmu_diff_main.js
More file actions
2883 lines (2547 loc) · 117 KB
/
danmu_diff_main.js
File metadata and controls
2883 lines (2547 loc) · 117 KB
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 [哔哩哔哩直播]---弹幕反诈与防河蟹
// @version 3.7.1
// @description 本脚本会提示你在直播间发送的弹幕是否被秒删,被什么秒删,有助于用户规避河蟹词,避免看似发了弹幕结果主播根本看不到,不被发送成功的谎言所欺骗!
// @author Asuna
// @icon https://www.bilibili.com/favicon.ico
// @license GPL 3.0
// @match *://live.bilibili.com/1*
// @match *://live.bilibili.com/2*
// @match *://live.bilibili.com/3*
// @match *://live.bilibili.com/4*
// @match *://live.bilibili.com/5*
// @match *://live.bilibili.com/6*
// @match *://live.bilibili.com/7*
// @match *://live.bilibili.com/8*
// @match *://live.bilibili.com/9*
// @match *://live.bilibili.com/blanc/1*
// @match *://live.bilibili.com/blanc/2*
// @match *://live.bilibili.com/blanc/3*
// @match *://live.bilibili.com/blanc/4*
// @match *://live.bilibili.com/blanc/5*
// @match *://live.bilibili.com/blanc/6*
// @match *://live.bilibili.com/blanc/7*
// @match *://live.bilibili.com/blanc/8*
// @match *://live.bilibili.com/blanc/9*
// @run-at document-start
// @grant unsafeWindow
// @require https://cdn.jsdelivr.net/npm/segmentit@2.0.3/dist/umd/segmentit.min.js
// @namespace https://greasyfork.org/users/1390050
// @downloadURL https://update.greasyfork.org/scripts/516801/%E5%93%94%E5%93%A9%E5%93%94%E5%93%A9%E7%9B%B4%E6%92%AD%E5%BC%B9%E5%B9%95%E5%8F%8D%E8%AF%88%E4%BF%AE%E6%94%B9%E7%89%88.user.js
// @updateURL https://update.greasyfork.org/scripts/516801/%E5%93%94%E5%93%A9%E5%93%94%E5%93%A9%E7%9B%B4%E6%92%AD%E5%BC%B9%E5%B9%95%E5%8F%8D%E8%AF%88%E4%BF%AE%E6%94%B9%E7%89%88.meta.js
// ==/UserScript==
(function() {
'use strict';
//全局配置选项
const globalConfig = {
// 高级功能开关:true=启用所有功能,false=仅基础检测
advancedFeaturesEnabled: true,
// 脚本配置
msgTime: 7000, // 脚本加载消息计时器
exp: 1, // 弹幕同屏发送次数,默认为1
successSend: true, // 发送成功的回调开关,如不需要启用则填写false
// 弹幕样式配置
banColorSystem: "#90EE90", // 系统屏蔽弹幕颜色
banColorUser: "deepskyblue", // 主播屏蔽弹幕颜色
successColor: "DarkCyan", // 成功颜色
errorColor: "Crimson", // 错误颜色
// 弹幕显示位置
dmLeft: '-16%', // 默认固定从左侧开始滚动的位置
dmTop: '50%', // 弹幕距离顶部的位置,如果想要随机可以替换为:${Math.random() * 100}%
dmFontSize: '36px', // 弹幕字号
// 弹幕提示消息
banSystemMsg: "发送失败:你的弹幕被系统秒删,修改关键词后重新发吧",
banUserMsg: "发送失败:你的弹幕被主播删除,看来主播不喜欢某些关键词",
successLoadMsg: "弹幕反诈与防河蟹脚本加载完毕!",
successMsg: "恭喜,你的弹幕正常显示!",
errorMsg: "[弹幕反诈] use window mode (your userscript extensions not support unsafeWindow)",
errorSendMsg: "发送失败:捕获到的未知错误,详情请检查控制台输出日志!"
};
// 敏感词管理器初始化配置
// 此处的所有配置仅限高级功能生效,如关闭了高级选项请忽略
const sensitiveWordsConfig = {
// 默认配置参数,仅在初始化时有效,初始化配置修改此处
defaultConfig: {
// 是否启用敏感词检测
enabled: true,
// 是否区分大小写
caseSensitive: false,
// 是否启用模糊匹配
fuzzyMatch: true,
// 是否启用分词器测试
enableSegmentationTest: false,
// 是否默认显示弹幕记录板
showLogBoxByDefault: true,
// 弹幕记录板容量限制
logBoxCapacity: 50,
// 默认导出格式:'txt' 或 'csv'
exportFormat: 'csv',
// 敏感词库最大容量限制
maxWordsCapacity: 1000,
// 默认敏感词列表
words: [
'敏感', '违规', '不当', '禁止', '限制', '屏蔽', '过滤',
'政治', '色情', '暴力', '赌博', '毒品', '诈骗', '传销', '邪教',
'反动', '分裂', '恐怖', '极端', '仇恨', '歧视', '侮辱', '诽谤'
]
},
// 敏感词高亮样式
highlightStyle: {
backgroundColor: '#ffeb3b',
color: '#d32f2f',
fontWeight: 'bold',
padding: '1px 2px',
borderRadius: '2px',
textShadow: '0 0 2px rgba(255, 0, 0, 0.3)'
},
// 当前运行时配置(用户自定义,会从本地存储中更新,修改默认参数请勿修改此处)
words: [],
enabled: true,
caseSensitive: false,
fuzzyMatch: true,
enableSegmentationTest: false,
showLogBoxByDefault: true,
logBoxCapacity: 50,
exportFormat: 'csv'
};
// 控制台样式化输出工具
const consoleStyle = {
// 成功类型:绿色渐变
success: function(message) {
console.log(
`%c✅ ${message}`,
'color: #fff; background: linear-gradient(270deg, #986fee, #8695e6, #68b7dd, #18d7d3); padding: 8px 15px; border-radius: 0 15px 0 15px; font-weight: bold;'
);
},
// 错误类型:红色渐变
error: function(message) {
console.log(
`%c❌ ${message}`,
'color: #fff; background: linear-gradient(270deg, #ff6b6b, #ff8e8e, #ffa5a5); padding: 8px 15px; border-radius: 0 15px 0 15px; font-weight: bold;'
);
},
// 警告类型:橙色渐变
warning: function(message) {
console.log(
`%c⚠️ ${message}`,
'color: #fff; background: linear-gradient(270deg, #ff9800, #ffb84d, #ffcc80); padding: 8px 15px; border-radius: 0 15px 0 15px; font-weight: bold;'
);
},
// 信息类型:蓝色渐变
info: function(message) {
console.log(
`%cℹ️ ${message}`,
'color: #fff; background: linear-gradient(270deg, #2196f3, #64b5f6, #90caf9); padding: 8px 15px; border-radius: 0 15px 0 15px; font-weight: bold;'
);
}
};
// Segmentit分词器测试功能
let segmentit = null;
let segmentitLoaded = false;
// 初始化segmentit分词器
function initSegmentit() {
if (segmentitLoaded) return;
try {
// 检查segmentit是否可用
if (typeof Segmentit !== 'undefined' && Segmentit.Segment && Segmentit.useDefault) {
segmentit = Segmentit.useDefault(new Segmentit.Segment());
segmentitLoaded = true;
consoleStyle.success("Segmentit分词器初始化完成");
} else {
consoleStyle.error("Segmentit分词器未加载");
}
} catch (error) {
console.error("初始化Segmentit分词器时出错:", error);
}
}
// 确保分词器可用的函数
function ensureSegmentitReady() {
if (!segmentitLoaded) {
initSegmentit();
}
return segmentitLoaded && segmentit && segmentit.doSegment;
}
function testSegmentitSegmentation(text) {
if (!text) return;
// 检查是否启用了分词器测试,如未启用则不执行分词输出
if (!sensitiveWordsConfig.enableSegmentationTest) {
return;
}
try {
// 检查segmentit是否可用
if (segmentitLoaded && segmentit && segmentit.doSegment) {
const segments = segmentit.doSegment(text);
// 提取分词结果
const words = segments.map(item => item.w);
console.log("=== Segmentit分词测试 ===");
console.log("弹幕内容:", text);
console.log("分词结果:", words);
console.log("分词数量:", words.length);
console.log("详细结果:", segments);
console.log("========================");
return words;
} else {
console.log("=== Segmentit分词测试 ===");
console.log("弹幕内容:", text);
console.log("segmentit分词器未就绪,使用简单分词:", text.split(''));
console.log("========================");
return text.split('');
}
} catch (error) {
console.error("segmentit分词测试出错:", error);
console.log("=== Segmentit分词测试 ===");
console.log("弹幕内容:", text);
console.log("分词失败,使用简单分词:", text.split(''));
console.log("========================");
return text.split('');
}
}
// 重置所有选项到默认配置
function resetToDefaultConfig() {
sensitiveWordsConfig.enabled = sensitiveWordsConfig.defaultConfig.enabled;
sensitiveWordsConfig.caseSensitive = sensitiveWordsConfig.defaultConfig.caseSensitive;
sensitiveWordsConfig.fuzzyMatch = sensitiveWordsConfig.defaultConfig.fuzzyMatch;
sensitiveWordsConfig.enableSegmentationTest = sensitiveWordsConfig.defaultConfig.enableSegmentationTest;
sensitiveWordsConfig.showLogBoxByDefault = sensitiveWordsConfig.defaultConfig.showLogBoxByDefault;
sensitiveWordsConfig.logBoxCapacity = sensitiveWordsConfig.defaultConfig.logBoxCapacity;
sensitiveWordsConfig.exportFormat = sensitiveWordsConfig.defaultConfig.exportFormat;
sensitiveWordsConfig.words = [...sensitiveWordsConfig.defaultConfig.words];
}
// 敏感词管理器
const sensitiveWordManager = {
// 获取敏感词列表
getWords() {
const saved = localStorage.getItem('danmu_sensitive_words');
if (saved) {
try {
const config = JSON.parse(saved);
return config.words || sensitiveWordsConfig.defaultConfig.words;
} catch (e) {
consoleStyle.warning('解析本地敏感词配置失败,使用系统默认配置');
return sensitiveWordsConfig.defaultConfig.words;
}
}
// 如果localStorage中没有数据,返回初始初始化的词汇配置
return sensitiveWordsConfig.defaultConfig.words;
},
// 保存敏感词列表
saveWords(words) {
const config = {
words: words,
enabled: sensitiveWordsConfig.enabled,
caseSensitive: sensitiveWordsConfig.caseSensitive,
fuzzyMatch: sensitiveWordsConfig.fuzzyMatch,
enableSegmentationTest: sensitiveWordsConfig.enableSegmentationTest,
showLogBoxByDefault: sensitiveWordsConfig.showLogBoxByDefault,
logBoxCapacity: sensitiveWordsConfig.logBoxCapacity,
exportFormat: sensitiveWordsConfig.exportFormat
};
localStorage.setItem('danmu_sensitive_words', JSON.stringify(config));
},
// 添加敏感词
addWord(word) {
const words = this.getWords();
const maxCapacity = sensitiveWordsConfig.defaultConfig.maxWordsCapacity;
// 检查是否已存在
if (words.includes(word)) {
return false;
}
// 检查容量限制并打印到控制台日志
if (words.length >= maxCapacity) {
consoleStyle.warning(`敏感词库已达到最大容量限制 (${maxCapacity}个),无法添加更多敏感词`);
return false;
}
words.push(word);
this.saveWords(words);
return true;
},
// 删除敏感词
removeWord(word) {
const words = this.getWords();
const index = words.indexOf(word);
if (index > -1) {
words.splice(index, 1);
this.saveWords(words);
return true;
}
return false;
},
// 检测敏感词
detectSensitiveWords(text) {
if (!globalConfig.advancedFeaturesEnabled) return [];
if (!sensitiveWordsConfig.enabled || !text) return [];
if (text.length > 80) return []; // 忽略超长文本扫描,弹幕最多一次性发40字,不能一次发这么多出来
const words = this.getWords();
if (words.length === 0) return []; // 空词库保护,跳过扫描
const detectedWords = [];
const textToCheck = sensitiveWordsConfig.caseSensitive ? text : text.toLowerCase();
if (sensitiveWordsConfig.fuzzyMatch) {
// 模糊匹配:检查是否包含敏感词,处理重叠情况
words.forEach(word => {
const wordToCheck = sensitiveWordsConfig.caseSensitive ? word : word.toLowerCase();
let searchIndex = 0;
// 查找所有匹配的位置,限制检测数量最多为8个
while (searchIndex < textToCheck.length && detectedWords.length < 8) {
const foundIndex = textToCheck.indexOf(wordToCheck, searchIndex);
if (foundIndex === -1) break;
detectedWords.push({
word: word,
originalWord: word,
startIndex: foundIndex,
endIndex: foundIndex + wordToCheck.length
});
searchIndex = foundIndex + 1;
}
});
// 去重:移除重叠的检测结果,保留较长的敏感词
const filteredWords = this.removeOverlappingDetections(detectedWords);
detectedWords.length = 0; // 清空原数组
detectedWords.push(...filteredWords); // 添加过滤后的结果
} else {
// 精确匹配:使用分词器进行分词后精确匹配
if (ensureSegmentitReady()) {
try {
const segments = segmentit.doSegment(text);
console.log("精确匹配模式 - 分词结果:", segments.map(s => s.w));
// 对每个敏感词检查是否在分词结果中
words.forEach(word => {
const wordToCheck = sensitiveWordsConfig.caseSensitive ? word : word.toLowerCase();
segments.forEach((segment, index) => {
const segmentToCheck = sensitiveWordsConfig.caseSensitive ? segment.w : segment.w.toLowerCase();
// 精确匹配:分词结果必须完全等于敏感词
if (segmentToCheck === wordToCheck) {
console.log(`精确匹配检测到敏感词: "${word}" 在分词: "${segment.w}"`);
detectedWords.push({
word: word,
originalWord: word,
segment: segment.w,
segmentIndex: index,
startIndex: text.indexOf(segment.w),
endIndex: text.indexOf(segment.w) + segment.w.length
});
}
});
});
} catch (error) {
console.error("精确匹配分词出错:", error);
}
} else {
consoleStyle.error("分词器未就绪,精确匹配功能不可用");
}
}
return detectedWords;
},
// 移除重叠的检测结果,保留较长的敏感词
removeOverlappingDetections(detectedWords) {
if (detectedWords.length <= 1) return [...detectedWords];
// 按开始位置排序
detectedWords.sort((a, b) => a.startIndex - b.startIndex);
const result = [detectedWords[0]]; // 直接添加第一个
for (let i = 1; i < detectedWords.length; i++) {
const current = detectedWords[i];
const last = result[result.length - 1];
// 检查是否重叠
if (current.startIndex >= last.endIndex) {
// 不重叠:直接添加
result.push(current);
} else {
// 重叠:保留较长的
if (current.endIndex - current.startIndex > last.endIndex - last.startIndex) {
result[result.length - 1] = current;
}
}
}
return result;
},
// 高亮敏感词
highlightSensitiveWords(text, detectedWords = null) {
const words = detectedWords || this.detectSensitiveWords(text);
if (words.length === 0) return text;
// 按位置排序,从后往前替换避免位置偏移
words.sort((a, b) => b.startIndex - a.startIndex);
let highlightedText = text;
words.forEach(item => {
const before = highlightedText.substring(0, item.startIndex);
const sensitive = highlightedText.substring(item.startIndex, item.endIndex);
const after = highlightedText.substring(item.endIndex);
const highlightSpan = `<span style="background-color: ${sensitiveWordsConfig.highlightStyle.backgroundColor}; color: ${sensitiveWordsConfig.highlightStyle.color}; font-weight: ${sensitiveWordsConfig.highlightStyle.fontWeight}; padding: ${sensitiveWordsConfig.highlightStyle.padding}; border-radius: ${sensitiveWordsConfig.highlightStyle.borderRadius}; text-shadow: ${sensitiveWordsConfig.highlightStyle.textShadow};">${sensitive}</span>`;
highlightedText = before + highlightSpan + after;
});
return highlightedText;
}
};
// 创建浮动文本框用于记录被拦截的弹幕
function createDanmuLogBox() {
// 防止重复创建:检查是否已经存在记录板
const existingLogBox = document.getElementById('danmu-log-box');
if (existingLogBox) {
// 如果记录板已存在,直接返回现有实例
return existingLogBox;
}
// 检查页面环境:确保 document.body 存在(页面已加载)
if (!document.body) {
consoleStyle.warning('页面未加载完成,延迟创建记录板');
// 如果 body 不存在,延迟创建
setTimeout(() => {
if (document.body && !document.getElementById('danmu-log-box')) {
createDanmuLogBox();
}
}, 500);
return null;
}
// 检查是否存在 #live-player 元素,这是真实直播间的标识
// 如果不存在,说明可能是活动页(外层页面),不创建记录板
const livePlayerDiv = document.getElementById('live-player');
if (!livePlayerDiv) {
// 检查是否在 iframe 中
try {
// 如果在 iframe 中且顶层窗口也有 live-player,说明是嵌套场景
// 此时只在 iframe 内的真实直播间创建记录板
if (window.self !== window.top) {
// 在 iframe 中,但没有 live-player,说明不是真实直播间,不创建
consoleStyle.info('检测到 iframe 嵌套,但当前页面不是真实直播间,跳过创建记录板');
return null;
} else {
// 不在 iframe 中,但没有 live-player,可能是活动页,不创建
consoleStyle.info('当前页面没有 live-player 元素,跳过创建记录板(可能是活动页)');
return null;
}
} catch (e) {
// 跨域限制,无法访问 window.top,保守处理:不创建
consoleStyle.warning('无法判断页面环境,跳过创建记录板');
return null;
}
}
const logBox = document.createElement('div');
logBox.id = 'danmu-log-box';
logBox.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
width: 320px;
height: 250px;
background: rgba(0, 0, 0, 0.8);
color: white;
border: 2px solid #00a1d6;
border-radius: 12px;
padding: 15px;
font-size: 12px;
z-index: 10000;
font-family: 'Microsoft YaHei', sans-serif;
overflow: hidden;
resize: both;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 添加标题栏
const titleBar = document.createElement('div');
titleBar.style.cssText = `
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
padding-bottom: 8px;
border-bottom: 2px solid #00a1d6;
background: linear-gradient(90deg, rgba(0, 161, 214, 0.1), transparent);
border-radius: 8px 8px 0 0;
padding: 8px 12px;
margin: -15px -15px 10px -15px;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
const title = document.createElement('span');
title.textContent = '弹幕记录板';
title.style.cssText = `
font-weight: bold;
font-size: 14px;
color: #00a1d6;
text-shadow: 0 0 8px rgba(0, 161, 214, 0.5);
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
const clearBtn = document.createElement('button');
clearBtn.textContent = '清空';
clearBtn.style.cssText = `
background: linear-gradient(135deg, #ff6b6b, #e53e3e);
color: white;
border: none;
border-radius: 6px;
padding: 4px 8px;
font-size: 10px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 2px 6px rgba(255, 107, 107, 0.3);
transition: all 0.2s ease;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 清空按钮悬停效果
clearBtn.onmouseenter = () => {
clearBtn.style.transform = 'scale(1.05)';
clearBtn.style.boxShadow = '0 4px 8px rgba(255, 107, 107, 0.4)';
};
clearBtn.onmouseleave = () => {
clearBtn.style.transform = 'scale(1)';
clearBtn.style.boxShadow = '0 2px 6px rgba(255, 107, 107, 0.3)';
};
const saveBtn = document.createElement('button');
saveBtn.textContent = '保存';
saveBtn.style.cssText = `
background: linear-gradient(135deg, #4CAF50, #45a049);
color: white;
border: none;
border-radius: 6px;
padding: 4px 8px;
font-size: 10px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 2px 6px rgba(76, 175, 80, 0.3);
transition: all 0.2s ease;
margin-left: 5px;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 保存按钮悬停效果
saveBtn.onmouseenter = () => {
saveBtn.style.transform = 'scale(1.05)';
saveBtn.style.boxShadow = '0 4px 8px rgba(76, 175, 80, 0.4)';
};
saveBtn.onmouseleave = () => {
saveBtn.style.transform = 'scale(1)';
saveBtn.style.boxShadow = '0 2px 6px rgba(76, 175, 80, 0.3)';
};
const sensitiveBtn = document.createElement('button');
sensitiveBtn.textContent = '敏感词';
sensitiveBtn.style.cssText = `
background: linear-gradient(135deg, #ff9800, #f57c00);
color: white;
border: none;
border-radius: 6px;
padding: 4px 8px;
font-size: 10px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 2px 6px rgba(255, 152, 0, 0.3);
transition: all 0.2s ease;
margin-left: 5px;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 敏感词按钮悬停效果
sensitiveBtn.onmouseenter = () => {
sensitiveBtn.style.transform = 'scale(1.05)';
sensitiveBtn.style.boxShadow = '0 4px 8px rgba(255, 152, 0, 0.4)';
};
sensitiveBtn.onmouseleave = () => {
sensitiveBtn.style.transform = 'scale(1)';
sensitiveBtn.style.boxShadow = '0 2px 6px rgba(255, 152, 0, 0.3)';
};
const closeBtn = document.createElement('button');
closeBtn.textContent = '×';
closeBtn.style.cssText = `
background: linear-gradient(135deg, #666, #555);
color: white;
border: none;
border-radius: 6px;
padding: 4px 8px;
font-size: 12px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 2px 6px rgba(102, 102, 102, 0.3);
transition: all 0.2s ease;
margin-left: 5px;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 关闭按钮悬停效果
closeBtn.onmouseenter = () => {
closeBtn.style.transform = 'scale(1.05)';
closeBtn.style.boxShadow = '0 4px 8px rgba(102, 102, 102, 0.4)';
};
closeBtn.onmouseleave = () => {
closeBtn.style.transform = 'scale(1)';
closeBtn.style.boxShadow = '0 2px 6px rgba(102, 102, 102, 0.3)';
};
titleBar.appendChild(title);
titleBar.appendChild(clearBtn);
titleBar.appendChild(saveBtn);
titleBar.appendChild(sensitiveBtn);
titleBar.appendChild(closeBtn);
// 添加内容区域
const contentArea = document.createElement('div');
contentArea.id = 'danmu-log-content';
contentArea.style.cssText = `
height: calc(100% - 40px);
overflow-y: auto;
word-wrap: break-word;
background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
border-radius: 8px;
padding: 10px;
border: 1px solid rgba(0, 161, 214, 0.2);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
user-select: text;
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
`;
// 添加自定义滚动条样式
const scrollbarStyle = document.createElement('style');
scrollbarStyle.textContent = `
#danmu-log-content::-webkit-scrollbar {
width: 8px;
}
#danmu-log-content::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.1);
border-radius: 4px;
margin: 2px;
}
#danmu-log-content::-webkit-scrollbar-thumb {
background: linear-gradient(135deg, #00a1d6, #0088cc);
border-radius: 4px;
border: 1px solid rgba(0, 161, 214, 0.3);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
#danmu-log-content::-webkit-scrollbar-thumb:hover {
background: linear-gradient(135deg, #0088cc, #006699);
box-shadow: 0 0 8px rgba(0, 161, 214, 0.4);
transform: scale(1.1);
}
#danmu-log-content::-webkit-scrollbar-thumb:active {
background: linear-gradient(135deg, #006699, #004466);
}
#danmu-log-content::-webkit-scrollbar-corner {
background: transparent;
}
/* Firefox 滚动条样式 */
#danmu-log-content {
scrollbar-width: thin;
scrollbar-color: #00a1d6 rgba(0, 0, 0, 0.1);
}
`;
document.head.appendChild(scrollbarStyle);
logBox.appendChild(titleBar);
logBox.appendChild(contentArea);
document.body.appendChild(logBox);
// 更新保存按钮文本显示当前导出格式
updateSaveButtonText();
// 绑定事件
clearBtn.onclick = () => {
// 检查是否有记录
if (contentArea.children.length === 0) {
showNotification('没有记录可清空!', 'warning', 2000);
return;
}
// 二级确认
if (confirm('确定要清空所有弹幕记录吗?\n\n此操作不可撤销!')) {
contentArea.innerHTML = '';
showNotification('弹幕记录已清空!', 'success', 2000);
}
};
saveBtn.onclick = () => {
saveDanmuLogs(contentArea, saveBtn);
};
sensitiveBtn.onclick = () => {
showSensitiveWordManager();
};
closeBtn.onclick = () => {
logBox.style.display = 'none';
// 添加重新打开功能
logBox.setAttribute('data-closed', 'true');
};
// 添加拖拽功能 - 优化版本
let isDragging = false;
let currentX;
let currentY;
let initialX;
let initialY;
let xOffset = 0;
let yOffset = 0;
let dragThrottleTimer = null;
titleBar.addEventListener('mousedown', dragStart);
document.addEventListener('mousemove', drag);
document.addEventListener('mouseup', dragEnd);
function dragStart(e) {
initialX = e.clientX - xOffset;
initialY = e.clientY - yOffset;
if (e.target === titleBar || titleBar.contains(e.target)) {
isDragging = true;
// 启用硬件加速
logBox.style.willChange = 'transform';
}
}
function drag(e) {
if (isDragging) {
// 使用requestAnimationFrame节流,避免频繁DOM更新
if (dragThrottleTimer) return;
dragThrottleTimer = requestAnimationFrame(() => {
e.preventDefault();
currentX = e.clientX - initialX;
currentY = e.clientY - initialY;
xOffset = currentX;
yOffset = currentY;
// 使用transform3d启用硬件加速
logBox.style.transform = `translate3d(${currentX}px, ${currentY}px, 0)`;
dragThrottleTimer = null;
});
}
}
function dragEnd(e) {
initialX = currentX;
initialY = currentY;
isDragging = false;
// 清理节流定时器
if (dragThrottleTimer) {
cancelAnimationFrame(dragThrottleTimer);
dragThrottleTimer = null;
}
// 禁用硬件加速以节省资源
logBox.style.willChange = 'auto';
}
return logBox;
}
// 配置选项UI管理
const configUI = {
enableCheckbox: null,
caseCheckbox: null,
fuzzyCheckbox: null,
showLogBoxCheckbox: null,
segmentationCheckbox: null,
capacityInput: null,
exportFormatSelect: null,
// 初始化配置选项UI
init(enableCheckbox, caseCheckbox, fuzzyCheckbox, showLogBoxCheckbox, segmentationCheckbox, capacityInput, exportFormatSelect) {
this.enableCheckbox = enableCheckbox;
this.caseCheckbox = caseCheckbox;
this.fuzzyCheckbox = fuzzyCheckbox;
this.showLogBoxCheckbox = showLogBoxCheckbox;
this.segmentationCheckbox = segmentationCheckbox;
this.capacityInput = capacityInput;
this.exportFormatSelect = exportFormatSelect;
},
// 重置配置选项UI到默认状态
resetToDefault() {
if (this.enableCheckbox) this.enableCheckbox.checked = sensitiveWordsConfig.defaultConfig.enabled;
if (this.caseCheckbox) this.caseCheckbox.checked = sensitiveWordsConfig.defaultConfig.caseSensitive;
if (this.fuzzyCheckbox) this.fuzzyCheckbox.checked = sensitiveWordsConfig.defaultConfig.fuzzyMatch;
if (this.showLogBoxCheckbox) this.showLogBoxCheckbox.checked = sensitiveWordsConfig.defaultConfig.showLogBoxByDefault;
if (this.segmentationCheckbox) this.segmentationCheckbox.checked = sensitiveWordsConfig.defaultConfig.enableSegmentationTest;
if (this.capacityInput) this.capacityInput.value = sensitiveWordsConfig.defaultConfig.logBoxCapacity;
if (this.exportFormatSelect) this.exportFormatSelect.value = sensitiveWordsConfig.defaultConfig.exportFormat;
}
};
// 敏感词管理界面
function showSensitiveWordManager() {
// 检查是否已经存在管理界面
let managerModal = document.getElementById('sensitive-word-manager');
if (managerModal) {
managerModal.style.display = 'block';
// 每次打开时清空输入框
const addInput = managerModal.querySelector('input[type="text"]');
if (addInput) {
addInput.value = '';
}
return;
}
// 创建模态框
managerModal = document.createElement('div');
managerModal.id = 'sensitive-word-manager';
managerModal.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 20000;
display: flex;
justify-content: center;
align-items: center;
`;
// 创建管理面板
const panel = document.createElement('div');
panel.style.cssText = `
background: linear-gradient(135deg, #2c2c2c, #1a1a1a);
border: 2px solid #00a1d6;
border-radius: 12px;
padding: 20px;
width: 500px;
max-height: 95vh;
overflow-y: auto;
color: white;
font-family: 'Microsoft YaHei', sans-serif;
position: relative;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
backdrop-filter: blur(10px);
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 添加自定义勾选框样式
const checkboxStyle = document.createElement('style');
checkboxStyle.textContent = `
#sensitive-word-manager input[type="checkbox"] {
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
width: 18px;
height: 18px;
border: 2px solid rgba(0, 161, 214, 0.6);
border-radius: 4px;
background: linear-gradient(135deg, #333, #2a2a2a);
cursor: pointer;
position: relative;
transition: all 0.3s ease;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}
#sensitive-word-manager input[type="checkbox"]:hover {
border-color: #00a1d6;
box-shadow: 0 0 8px rgba(0, 161, 214, 0.3), inset 0 2px 4px rgba(0, 0, 0, 0.3);
transform: scale(1.05);
}
#sensitive-word-manager input[type="checkbox"]:checked {
background: linear-gradient(135deg, #00a1d6, #0088cc);
border-color: #00a1d6;
box-shadow: 0 0 12px rgba(0, 161, 214, 0.5), inset 0 2px 4px rgba(0, 0, 0, 0.2);
}
#sensitive-word-manager input[type="checkbox"]:checked::after {
content: '✓';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 12px;
font-weight: bold;
text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}
#sensitive-word-manager input[type="checkbox"]:focus {
outline: none;
box-shadow: 0 0 0 3px rgba(0, 161, 214, 0.3), inset 0 2px 4px rgba(0, 0, 0, 0.3);
}
#sensitive-word-manager label {
cursor: pointer;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
transition: color 0.2s ease;
}
#sensitive-word-manager label:hover {
color: #00a1d6;
}
`;
document.head.appendChild(checkboxStyle);
// 标题栏
const titleBar = document.createElement('div');
titleBar.style.cssText = `
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #00a1d6;
cursor: move;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
background: linear-gradient(90deg, rgba(0, 161, 214, 0.1), transparent);
border-radius: 8px 8px 0 0;
padding: 10px 15px;
margin: -20px -20px 15px -20px;
`;
const title = document.createElement('h3');
title.textContent = '敏感词管理';
title.style.margin = '0';
const closeBtn = document.createElement('button');
closeBtn.textContent = '×';
closeBtn.style.cssText = `
background: linear-gradient(135deg, #ff6b6b, #e53e3e);
color: white;
border: none;
border-radius: 6px;
padding: 8px 12px;
font-size: 16px;
cursor: pointer;
box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
transition: all 0.2s ease;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
`;
// 添加悬停效果
closeBtn.onmouseenter = () => {
closeBtn.style.transform = 'scale(1.05)';
closeBtn.style.boxShadow = '0 4px 12px rgba(255, 107, 107, 0.5)';
};
closeBtn.onmouseleave = () => {
closeBtn.style.transform = 'scale(1)';
closeBtn.style.boxShadow = '0 2px 8px rgba(255, 107, 107, 0.3)';
};