-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.src.html
1063 lines (920 loc) · 37.9 KB
/
index.src.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<!--COC Log Painter @Fengyu Modified by Suhui-->
<!-- Version 2.1 01/31/2016 LAX -->
<!-- Version 2.2 09/17/2016 -->
<!-- Version 2.3 02/17/2017 -->
<!-- Copyright 2017-2019, hina.moe -->
<!-- Version 2.4 02/12/2018 优化界面 修正部分错误 更新依赖by溯洄-->
<!-- Version 2.5 02/12/2018 修正部分错误 更新依赖 添加论坛分享by溯洄-->
<!-- Version 2.6 06/05/2021 新增直接下载功能by溯洄-->
<!-- Copyright 2018-2021, kokona.tech -->
<!--
MIT License
Copyright (c) 2017-2019 风羽 hina.moe
Copyright (c) 2018-2021 溯洄 kokona.tech
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<head>
<title>QQ跑团记录着色器</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<meta name="Description" content="QQ跑团记录着色器">
<meta name="theme-color" content="#D1EAF7"/>
<!-- jQuery CDN-->
<script src="https://unpkg.zhimg.com/[email protected]/dist/jquery.min.js"></script>
<!-- bootstrap CDN-->
<script src="https://unpkg.zhimg.com/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link href="https://unpkg.zhimg.com/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- 调色盘插件 https://tovic.github.io/color-picker/ -->
<link href="color-picker.min.css" rel="stylesheet">
<script src="color-picker.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/index.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>
<link rel="shortcut icon" href="favicon.ico"/>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-124322134-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-124322134-3');
</script>
<script data-ad-client="ca-pub-6328033898902108" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<style>
body {
background-color: #D1EAF7;
transition: background-color 1.5s ease;
}
#div_page { margin: 50px; }
#div_nav { margin: 10px; }
#div_names {
margin-bottom: 20px;
margin-left: 50px;
margin-right: 50px;
margin-top: 20px;
}
.button_player {
text-align: left;
width: 100%;
}
#textarea_log_input {
height: 300px;
text-align: left;
}
#div_log_output {
float: left;
width: 100%;
}
#textarea_log_output {
height: 300px;
width: 100%;
}
.button_filter, .button_controller {
height: 50px;
width: 155px;
}
#div_log_view {
background-color: #D1EAF7;
float: left;
overflow: auto;
width: 100%;
}
.div_center { text-align: center; }
.div_italic { font-style: italic; }
#div_button { margin: 10px; }
.input_name {
background: transparent;
border: 0;
height: 34px;
width: inherit
}
</style>
</head>
<body>
<!--[if lt IE 10]>
<div id="div_browser_warning" style="background-color: #979797">
<h2 style="color: white; text-align: center; margin: 10px 0 10px 0; padding: 15px">你的浏览器已严重过时, 请升级到新版本IE或使用Chrome浏览器</h2>
</div>
<![endif]-->
<div id="div_nav">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="favicon.ico" width="30" height="30" alt="">
</a>
<a class="navbar-brand" href="#">Dice! Logpainter</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="https://kokona.tech">Dice! 主站</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/w4123/logpainter">本项目GitHub</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/w4123/trpglogger">跑团记录器</a
</li>
</ul>
</div>
</nav>
</div>
<div id="div_page">
<div>
<div class="div_center">
<h3 id="header_title">QQ跑团记录着色器</h3><h5 id="header_version">v2.6 by 风羽(溯洄改)</h5>
</div>
<div class="div_italic">
<a href="http://aligo.github.io/log-colourer.js">前辈的mirc版传送门</a><br>
<a id="specialMode1" href="javascript:void(0);">艾德琳的文本着色器</a>
<a id="defaultMode" href="javascript:void(0);">QQ跑团记录着色器</a>
</div>
<h6>将QQ聊天记录的【文本】复制到下面这个文本框中,然后点击按钮【Analyze】</h6>
</div>
<div>
<textarea class="form-control" id="textarea_log_input"></textarea>
</div>
<div id="div_button" class="div_center">
<div>
<button class="button_filter btn btn-info" id="button_log_command" style="margin-bottom: 2px">指令过滤 On</button>
<button class="button_filter btn btn-info" id="button_log_other" style="margin-bottom: 2px">(开头内容过滤 On</button>
<button class="button_filter btn btn-info" id="button_log_pic_text" style="margin-bottom: 2px"> [图片]过滤 On</button>
<button class="button_filter btn btn-info" id="button_log_time" style="margin-bottom: 2px"> 显示时间 On</button>
<button class="button_filter btn btn-info" id="button_log_nname" style="margin-bottom: 2px"> 人名头衔过滤 On</button>
</div>
<br/>
<div>
<button class="button_controller btn btn-success" id="button_log_analyze" style="margin-bottom: 2px">Analyze</button>
<button class="button_controller btn btn-warning" id="button_log_clear" style="margin-bottom: 2px">清除输入</button>
<button class="button_controller btn btn-success" id="button_palette" style="margin-bottom: 2px; display: none">使用调色盘</button>
<button class="button_controller btn btn-success" id="button_share" style="margin-bottom: 2px; display: none">分享到Dice!论坛</button>
<button class="button_controller btn btn-info" id="button_download_txt" style="margin-bottom: 2px; display: none">下载为txt文档</button>
<button class="button_controller btn btn-info" id="button_download_docx" style="margin-bottom: 2px; display: none">下载为docx文档</button>
</div>
</div>
<br/>
<div class="div_center">
</div>
<div id="div_names">
</div>
<div id="div_log">
<h6>复制预览部分内容可得TXT文本(双击以选中所有文本),输出部分为论坛用代码</h6>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation" style="background-color: #f6ffbe; border-radius: 5px; width: 50%;">
<a class="nav-link active show" href="#div_log_view" aria-controls="div_log_view" role="tab" data-toggle="tab">预览</a>
</li>
<li class="nav-item" role="presentation" style="background-color: #f6ffbe; border-radius: 5px; width: 50%;">
<a class="nav-link" href="#div_log_output" aria-controls="div_log_output" role="tab" data-toggle="tab">输出</a>
</li>
</ul>
<div class="tab-content" style="display: flex">
<div role="tabpanel" class="tab-pane fade active show" id="div_log_view" style="background-color: white">
</div>
<div role="tabpanel" class="tab-pane fade" id="div_log_output">
<textarea class="form-control" id="textarea_log_output"></textarea>
</div>
</div>
</div>
</div>
<script id="html_player_grid" type="html/template">
<div class="col-sm-2">
<input type="text" class="font-control input_name" name="&id" value="&name" placeholder="删除消息请点右边开关">
</div>
<div class="col-sm-2" style="min-width: 150px">
&select
</div>
<div class="col-sm-1" style="min-width: 80px">
<button style="text-align: center" type="button" class="btn btn-success button_player" name="&id">On</button>
</div>
<div class="col-sm-1">
</div>
</script>
<div class="container-fluid div_center">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- LogPainter -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328033898902108"
data-ad-slot="7844798489"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<div class="div_footer">
<!--采用container-fluid,使得整个页尾的宽度为100%,并设置它的背景色-->
<footer class="container-fluid foot-wrap">
<p style="text-align: center; margin-top: 20px; color: #878B91;">
原作者:风羽 Copyright ©2017-2019 hina.moe
<br/>
修改: 溯洄 Copyright ©2018-2021 kokona.tech
</p>
</footer>
</div>
<script>
(function ($, w, d) {
function getQueryVariable(variable)
{
var query = w.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){ return pair[1];}
}
return false;
}
function switchToSpecialMode1() {
$("body").css("background-color", "#f0e4f7");
$("#div_log_view").css("background-color", "#ffffff");
$("#header_title").fadeOut("fast",
function() {
$("#header_title").text("艾德琳的文本着色器");
$("#header_title").fadeIn();
});
$("#header_version").fadeOut("slow",
function() {
$("#header_version").text("v1.2 by 风羽(溯洄改)");
$("#header_version").fadeIn();
});
$("#specialMode1").hide();
$("#defaultMode").show();
formatMode = 1;
paletteMode = true;
$("#button_palette").text('使用论坛颜色');
$("#div_log_view").css("background-color", "#ffffff");
nameList = [];
logList = [];
$("html,body").animate({ scrollTop: 1 }, "fast");
$("#div_log").fadeOut("fast");
$("#button_palette").hide();
$("#button_share").hide();
$("#button_download_txt").hide();
$("#button_download_docx").hide();
$("#div_names").html("");
}
function switchToDefaultMode() {
$("body").css("background-color", "#D1EAF7");
$("#div_log_view").css("background-color", "");
$("#header_title").fadeOut("fast",
function() {
$("#header_title").text("QQ跑团记录着色器");
$("#header_title").fadeIn();
});
$("#header_version").fadeOut("slow",
function() {
$("#header_version").text("v2.6 by 风羽(溯洄改)");
$("#header_version").fadeIn();
});
$("#defaultMode").hide();
$("#specialMode1").show();
formatMode = 0;
paletteMode = false;
$("#button_palette").text('使用调色盘');
$("#div_log_view").css("background-color", "");
nameList = [];
logList = [];
$("html,body").animate({ scrollTop: 1 }, "fast");
$("#div_log").fadeOut("fast");
$("#button_palette").hide();
$("#button_share").hide();
$("#button_download_txt").hide();
$("#button_download_docx").hide();
$("#div_names").html("");
}
$("#specialMode1").click(function() {
switchToSpecialMode1();
});
$("#defaultMode").click(function() {
switchToDefaultMode();
});
$("#button_download_txt").click(function() {
saveAs(new Blob([txtData]), "download.txt");
});
$("#button_download_docx").click(function() {
const doc = new docx.Document({
sections: [
{
children: docxParagraphs
}
]
});
docx.Packer.toBlob(doc).then((blob) => {
saveAs(blob, "download.docx");
});
});
$(d).ready(function() {
$("#div_log").hide();
$("#button_palette").hide();
$("#button_share").hide();
$("#button_download_txt").hide();
$("#button_download_docx").hide();
$("#defaultMode").hide();
var s3_url = getQueryVariable("s3");
if (s3_url) {
$.ajax({
url: "https://dicelogger.s3-accelerate.amazonaws.com/" + s3_url,
tryCount : 0,
retryLimit : 3,
success: function (result) {
$("#textarea_log_input").val(result);
$("#button_log_analyze").click();
},
error : function(xhr, textStatus, errorThrown) {
if (textStatus === 'timeout') {
this.tryCount++;
if (this.tryCount <= this.retryLimit) {
//try again
$.ajax(this);
return;
}
return;
}
else
{
$("#textarea_log_input").val("获取跑团日志失败! 请刷新重试!");
}
}
});
}
else {
var input = $("#textarea_log_input").val();
if (input !== "") {
$("#button_log_analyze").click();
}
}
});
$("#button_log_command").click(function() {
commandFilter = !commandFilter;
if (!commandFilter) {
$(this).removeClass('btn-info');
$(this).text('指令过滤 Off');
$(this).addClass('btn-warning');
} else {
$(this).addClass('btn-info');
$(this).text('指令过滤 On');
$(this).removeClass('btn-warning');
}
});
$("#button_log_other").click(function() {
otherFilter = !otherFilter;
if (!otherFilter) {
$(this).removeClass('btn-info');
$(this).text('(开头内容过滤 Off');
$(this).addClass('btn-warning');
} else {
$(this).addClass('btn-info');
$(this).text('(开头内容过滤 On');
$(this).removeClass('btn-warning');
}
});
$("#button_log_pic_text").click(function() {
picTextFilter = !picTextFilter;
if (!picTextFilter) {
$(this).removeClass('btn-info');
$(this).text('[图片]过滤 Off');
$(this).addClass('btn-warning');
} else {
$(this).addClass('btn-info');
$(this).text('[图片]过滤 On');
$(this).removeClass('btn-warning');
}
});
$("#button_log_time").click(function() {
timeSwitch = !timeSwitch;
if (!timeSwitch) {
$(this).removeClass('btn-info');
$(this).text('显示时间 Off');
$(this).addClass('btn-warning');
} else {
$(this).addClass('btn-info');
$(this).text('显示时间 On');
$(this).removeClass('btn-warning');
}
});
$("#button_log_nname").click(function() {
nnameSwitch = !nnameSwitch;
if (!nnameSwitch) {
$(this).removeClass('btn-info');
$(this).text('人名头衔过滤 Off');
$(this).addClass('btn-warning');
} else {
$(this).addClass('btn-info');
$(this).text('人名头衔过滤 On');
$(this).removeClass('btn-warning');
}
});
$("#button_log_clear").click(function() {
$("html,body").animate({ scrollTop: 1 }, "fast");
nameList = [];
logList = [];
$("#div_log").fadeOut("fast");
$("#button_palette").hide();
$("#button_share").hide();
$("#button_download_txt").hide();
$("#button_download_docx").hide();
$("#textarea_log_input").val("");
$("#div_names").html("");
});
$("#div_log_view").dblclick(function() {
selectDivText(this.id);
});
$("#textarea_log_output").click(function() {
$(this).select();
});
function selectDivText(containerid) {
var range;
range = document.createRange();
range.selectNode(document.getElementById(containerid));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
$("#button_palette").click(function() {
paletteMode = !paletteMode;
getPlayerGrids(); //重新绘制颜色区
if (paletteMode) {
$(this).text('使用论坛颜色');
$("#div_log_view").css("background-color", "#ffffff");
$("#button_share").hide();
} else {
$(this).text('使用调色盘');
$("#div_log_view").css("background-color", "");
$("#button_share").fadeTo("slow", 0.7);
paintLog();
}
});
$("#button_share").click(function() {
s = $("#textarea_log_output").val();
if (!paletteMode && s)
{
window.open("https://forum.kokona.tech/composer?title=%E8%B7%91%E5%9B%A2%E8%AE%B0%E5%BD%95%E5%88%86%E4%BA%AB&tag=water&content=" + encodeURIComponent(s));
}
});
//Closure Variables
//Player Index
var nameList = [];
//Log Lines
var logList = [];
//Configuration
//Color Index
var colorList =
"red;green;pink;orange;purple;black;blue;yellow;beige;brown;teal;navy;maroon;limegreen;white;fuchsia;silver"
.split(';');
var colorNameList = "红色;绿色;粉红;橘色;紫色;黑色;蓝色;黄色;米色;棕色;蓝绿;深蓝;紫红;莱姆;白色;桃红;灰色".split(';');
//Default color of time
var timeColor = "silver";
var commandFilter = true;
var otherFilter = true;
var picTextFilter = true;
var timeSwitch = true;
var paletteMode = false;
var nnameSwitch = true;
////Format Mode Dictionary
// 0 QQ聊天记录
// 1 艾德琳的文本
var formatMode = 0;
var docxParagraphs = [];
var txtData = "";
//TODO_IF_NEEDED it can be extended to more colors a player so that name and content can be separated clearly
function Player(name, colorIndex) {
this.name = name;
this.color = colorList[colorIndex];
this.valid = true;
}
function Line(time, player, content) {
this.time = time;
this.player = player;
this.content = content;
}
function hasPlayer(name) {
for (var j = 0; j < nameList.length; j++) {
if (nameList[j].name == name) {
return true;
}
}
return false;
}
function addPlayer(name, colorIndex) {
nameList[nameList.length] = new Player(name, colorIndex);
}
function getPlayer(name) {
for (var j = 0; j < nameList.length; j++) {
if (nameList[j].name == name) {
return nameList[j];
}
}
return null;
}
function getSelectsHTML(id) {
var selectID = "select_" + id;
var html = "";
html += '<select name ="' + id + '" id ="' + selectID + '" class="form-control">';
for (var i = 0; i < colorNameList.length; i++) {
html += '<option value="' +
colorList[i] +
'" style="background-color:' +
colorList[i] +
';">' +
colorNameList[i] +
'</option>';
}
html += '</select>';
return html;
}
function getPaletteHTML(id) {
var paletteID = "palette_" + id;
var html = "<input class = \"form-control palette\" name = \"" +
id +
'" id ="' +
paletteID +
"\" type=\"text\">";
return html;
}
function registerPaletteAction() {
$(".palette").each(function() {
var palette = this;
var picker = new w.CP(palette);
//Change color
picker.on("change",
function(color) {
var colorStr = '#' + color;
this.source.value = colorStr;
$(this.source).css("background-color", colorStr);
changeColor(this.source.name, colorStr);
});
$(this).click(function() {
$(this).select();
});
$(this).change(function() {
picker.set(w.CP.parse($(this).val()));
});
});
$(".input_name").change(function() {
var newName = $(this).val();
var id = parseInt($(this).attr("name"));
nameList[id].name = newName;
paintLog();
});
}
function registerColorSelectorAction() {
$("select").change(function() {
var color = $(this).val();
var id = parseInt($(this).attr("name"));
$(this).css("background-color", color);
changeColor(id, color);
});
$(".input_name").change(function() {
var newName = $(this).val();
var id = parseInt($(this).attr("name"));
nameList[id].name = newName;
paintLog();
});
//Update select s' colors
selectInit();
}
function getPlayerCell(id, name) {
var html;
//Using template
if (paletteMode) {
//调色盘模式
html = $("#html_player_grid").html().replace(/&name/g, name)
.replace(/&id/g, id).replace('&select', getPaletteHTML(id));
} else {
//默认 论坛颜色选择
html = $("#html_player_grid").html().replace(/&name/g, name)
.replace(/&id/g, id).replace('&select', getSelectsHTML(id));
}
return html;
}
function getPlayerGrids() {
//2 players 1 line
var html = '<div class="div_center div_italic" style="color:red"><p>出现的PC名字 (点击可以修改)</p><br></div>';
var i;
for (i = 0; i < nameList.length; i++) {
if (i % 2 == 0) {
html += '<div class="row">';
}
html += getPlayerCell(i, nameList[i].name);
if (i % 2 == 1) {
html += '</div>';
}
}
if (i % 2 == 0) {
html += '</div>';
}
$("#div_names").html(html);
//初始化所有调色盘后,绑定事件
if (paletteMode) {
registerPaletteAction();
} else {
registerColorSelectorAction();
}
$("#button_palette").fadeTo("slow", 0.7);
$("#button_share").fadeTo("slow", 0.7);
$("#button_download_txt").fadeTo("slow", 1);
$("#button_download_docx").fadeTo("slow", 1);
$(".button_player").click(function() {
var id = parseInt($(this).attr("name"));
var switchNow = changeSwitch(id);
if (!switchNow) {
$(this).removeClass('btn-success');
$(this).text('Off');
$(this).addClass('btn-default');
} else {
$(this).addClass('btn-success');
$(this).text('On');
$(this).removeClass('btn-default');
}
});
}
function selectInit() {
for (var i = 0; i < nameList.length; i++) {
var selectID = "#select_" + i;
var color = colorList[i];
nameList[i].color = color;
$(selectID).val(color);
$(selectID).css("background-color", color);
}
}
function changeSwitch(playerID) {
nameList[playerID].valid = !nameList[playerID].valid;
paintLog();
return nameList[playerID].valid;
}
function changeColor(playerID, color) {
nameList[playerID].color = color;
//Update it
if (nameList[playerID].valid) {
paintLog();
}
}
/////////////////////////////////////////////////////////////////
//特殊模式1
function parseInputSpecialMode1() {
//Initialize
nameList = [];
logList = [];
$("#div_names").html("");
$("#div_log").hide();
var data = $("#textarea_log_input").val();
var reg = /(.+?)[::](.*)/; // 2016-01-03 \d{2}:\d{2}:\d{2}/g name
var lines = data.split("\n");
var name;
var time = "";
var colorIndex = 0;
var content;
addPlayer("旁白", 0);
for (var i = 0; i < lines.length; i++) {
//if(lines[i].length == 0){continue;}
var res = lines[i].match(reg);
var log;
if (res != null) {
name = res[1].trim();
content = res[2];
if (name != "") {
if (!hasPlayer(name)) {
addPlayer(name, colorIndex);
colorIndex++;
}
}
log = new Line(time, getPlayer(name), content);
logList[logList.length] = log;
} else {
log = new Line(time, getPlayer("旁白"), lines[i]);
logList[logList.length] = log;
}
}
return nameList.length;
}
function paintLogSpecialMode1() {
var output = "";
var outputHTML = "";
for (var i = 0; i < logList.length; i++) {
var playerColor = logList[i].player.color;
var playerName = logList[i].player.name;
var content = logList[i].content;
//该模式下,点人名的开关会把它的话变成旁白,用于纠正错误匹配。无法移去人物对话。
if (logList[i].player.valid == false && playerName != "旁白") {
playerName = "";
playerColor = getPlayer("旁白").color;
content = logList[i].player.name + ":" + logList[i].content;
}
if (playerName == "旁白") {
playerName = "";
} else if (playerName != "") {
playerName += ":";
}
output += ("[color=" + playerColor + "]" + "" + playerName);
output += content;
output += "[/color]\n";
outputHTML += ("<span style=\"color:" + playerColor + ";\">" + "" + playerName);
outputHTML += content;
outputHTML += "</span><br>";
}
if (paletteMode) {
output = "调色盘模式下的颜色不兼容论坛代码,请双击全选预览中的文字,复制粘贴到Word中保存";
}
$("#textarea_log_output").val(output);
$("#div_log_view").html(outputHTML);
}
///////////////////////////////////////////////
//QQ聊天记录识别
function parseInput() {
//Initialize
nameList = [];
logList = [];
$("#div_names").html("");
$("#div_log").hide();
var data = $("#textarea_log_input").val();
var regHeader =
/\d{4}(?:-|\/)\d{1,2}(?:-|\/)\d{1,2} (\d{1,2}:\d{2}:\d{2}) (AM|PM)? ?([^\(]*)/; // 2016-01-03 \d{2}:\d{2}:\d{2}/g name
var regHeader2 = /(.*?)(\([0-9]+\))? +\d{4}(?:-|\/)\d{1,2}(?:-|\/)\d{1,2} +(\d{1,2}:\d{2}:\d{2}).*/; // name 2016-01-03 12:35:30
var regHeader3 = /(.*?)(\([0-9]+\))? +(\d{1,2}:\d{2}:\d{2}).*/; // \d{2}:\d{2}:\d{2}/
var regDiscard =
/^([\.。!!][rR]|[/\.、。!!][mM][eE]|[\.。!!][hH][eE][lL][pP]|[\.。!!][lL][oO][gG]|[\.。!!][wW]|[\.。!!][sS][cC]|[\.。!!][eE][nN]|[\.。!!][sS][eE][tT]|[\.。!!][sS][tT]|[\.。!!][cC][oO][cC]|[\.。!!][dD][nN][dD]|[\.。!!][tTlL][iI]|[\.。!!][jJ][rR][rR][pP]|[\.。!!][rR][uU][lL][eE][sS]|[\.。!!][nN]|[\.。!!][bB][oO][tT]|[\.。!!][oO][bB]|[\.。!!][wW][eE][lL][cC][oO][mM][eE]).*/;
var regOther = /^(\(|().*/;
var regPicText = /\[图片\]/;
var lines = data.split("\n");
var name = "";
var time = "";
var colorIndex = 0;
for (var i = 0; i < lines.length; i++) {
if (lines[i].length == 0) {
continue;
}
//Recognize message header
var res = lines[i].match(regHeader);
var res2 = lines[i].match(regHeader2);
var res3 = lines[i].match(regHeader3);
//Deal with new name
if (res != null || res2 != null || res3 != null) {
if (res != null) {
name = res[3].trim();
time = res[1];
} else if (res2 != null) {
name = res2[1].trim();
time = res2[3];
} else if (res3 != null) {
name = res3[1].trim();
time = res3[3];
}
//----------------NEW NAME
if (nnameSwitch && name.indexOf('【') == 0 && name.indexOf('】') != -1) {
name = name.substr(name.indexOf('】') + 1);
}
//----------------------------------------------
if (name != "" && name != "系统消息") {
if (!hasPlayer(name)) {
addPlayer(name, colorIndex);
colorIndex++;
}
}
} else {
if (name == "") {
continue;
} //Discard messages that come without headers
if (name == "系统消息") {
continue;
}
//Discard 系统消息
//Deal with message content
if (commandFilter) {
var discard = lines[i].match(regDiscard);
if (discard != null) {
continue;
}
}
if (otherFilter) {
var other = lines[i].match(regOther);
if (other != null) {
continue;
}
}
if (picTextFilter) {
lines[i] = lines[i].replace(regPicText, "");
if (lines[i].length == 0) {
continue;
}
}
//Fix time length to 8
if (time.length != 8) {
time = ' ' + time;
}
var log = new Line(time, getPlayer(name), lines[i]);
logList[logList.length] = log;
}
}
return nameList.length;
}
function paintLogDefault() {
docxParagraphs = [];
txtData = "";
var output = "";
var outputHTML = "";
for (var i = 0; i < logList.length; i++) {
//Skip invalid names
if (logList[i].player.valid == false) {
continue;
}
var playerColor = logList[i].player.color;
//HTML中 <a>会被默认为tag
var name = logList[i].player.name;
if (timeSwitch) {
output += ("[color=" + timeColor + "]" + logList[i].time + "[/color] ");
}
output += ("[color=" + playerColor + "]" + "<" + logList[i].player.name + "> ");
output += logList[i].content;
output += "[/color]\n";
if (timeSwitch) {
outputHTML += ("<span style=\"color:" + timeColor + ";\">" + logList[i].time + "</span> ");
}
outputHTML += ("<span style=\"color:" + playerColor + ";\">" + "<" + name + "> ");
outputHTML += logList[i].content;
outputHTML += "</span><br>";
// docx
var textRuns = []
if (timeSwitch)
{
textRuns.push(
new docx.TextRun(
{
text: logList[i].time + " ",
color: timeColor
}
)
)
}
textRuns.push(
new docx.TextRun(
{
text: "<" + logList[i].player.name + "> " + logList[i].content,
color: playerColor
}
)
)
docxParagraphs.push(new docx.Paragraph(
{
children: textRuns
}
))