forked from Zhanli-Li/Auto-Tutor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutor_email_system.html
More file actions
1259 lines (1131 loc) · 54.7 KB
/
tutor_email_system.html
File metadata and controls
1259 lines (1131 loc) · 54.7 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>智能导师套磁邮件系统</title>
<!-- 引入EmailJS库用于邮件发送 -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@emailjs/browser@3/dist/email.min.js"></script>
<!-- 引入 PDF.js 用于在浏览器中解析简历PDF -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.14.305/pdf.min.js"></script>
<script>
(function() {
try {
const pdfjsLib = window['pdfjs-dist/build/pdf'];
if (pdfjsLib && pdfjsLib.GlobalWorkerOptions) {
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.14.305/pdf.worker.min.js';
}
} catch (e) {
console.warn('PDF.js 初始化失败:', e);
}
})();
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 15px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.1em;
opacity: 0.9;
}
.main-content {
padding: 40px;
}
.section {
margin-bottom: 40px;
padding: 30px;
border: 2px solid #f0f0f0;
border-radius: 10px;
background: #fafafa;
}
.section h2 {
color: #333;
margin-bottom: 20px;
font-size: 1.5em;
border-bottom: 3px solid #4facfe;
padding-bottom: 10px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #555;
}
.form-group input,
.form-group textarea,
.form-group select {
width: 100%;
padding: 12px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
outline: none;
border-color: #4facfe;
}
.form-group textarea {
resize: vertical;
min-height: 120px;
}
.file-input {
position: relative;
display: inline-block;
cursor: pointer;
width: 100%;
}
.file-input input[type=file] {
position: absolute;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.file-input-label {
display: block;
padding: 12px;
border: 2px dashed #4facfe;
border-radius: 8px;
text-align: center;
background: #f8f9ff;
color: #4facfe;
font-weight: 600;
transition: all 0.3s;
}
.file-input:hover .file-input-label {
background: #4facfe;
color: white;
}
.tutor-entry {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
margin-bottom: 15px;
background: white;
}
.tutor-entry h3 {
color: #4facfe;
margin-bottom: 15px;
}
.btn {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
color: white;
border: none;
padding: 12px 30px;
border-radius: 25px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
transition: transform 0.3s, box-shadow 0.3s;
margin: 5px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(79, 172, 254, 0.3);
}
.btn-secondary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.btn-danger {
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
}
.btn-success {
background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
font-size: 18px;
padding: 15px 40px;
margin-top: 20px;
}
.progress-container {
display: none;
margin-top: 20px;
}
.progress-bar {
width: 100%;
height: 20px;
background: #f0f0f0;
border-radius: 10px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
width: 0%;
transition: width 0.3s;
}
.status-message {
margin-top: 10px;
padding: 10px;
border-radius: 5px;
display: none;
}
.status-success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status-error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.status-info {
background: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 768px) {
.grid {
grid-template-columns: 1fr;
}
.main-content {
padding: 20px;
}
.header h1 {
font-size: 2em;
}
}
.required {
color: #ff4757;
}
.tooltip {
position: relative;
display: inline-block;
cursor: help;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -100px;
opacity: 0;
transition: opacity 0.3s;
font-size: 12px;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎓 智能导师套磁邮件系统</h1>
<p>智能生成个性化套磁邮件,助力学术申请之路</p>
<div style="background: rgba(255,255,255,0.1); padding: 15px; margin-top: 15px; border-radius: 8px; font-size: 0.9em;">
<strong>📧 使用说明:</strong>本系统使用Node.js后端服务发送邮件。请确保:<br>
1. 已启动后端服务器 (node email_server.js)<br>
2. 使邮箱授权码而非登录密码<br>
3. 在邮箱设置中开启SMTP服务
</div>
</div>
<div class="main-content">
<form id="emailForm">
<!-- 用户信息配置 -->
<div class="section">
<h2>📧 邮箱配置</h2>
<div class="grid">
<div class="form-group">
<label for="senderEmail">发件邮箱 <span class="required">*</span></label>
<input type="email" id="senderEmail" name="senderEmail" required placeholder="your.email@example.com">
</div>
<div class="form-group">
<label for="senderPassword">邮箱密码/授权码 <span class="required">*</span></label>
<input type="password" id="senderPassword" name="senderPassword" required placeholder="邮箱密码或应用专用密码">
</div>
</div>
<div class="grid">
<div class="form-group">
<label for="smtpServer">SMTP服务器</label>
<input type="text" id="smtpServer" name="smtpServer" placeholder="smtp.gmail.com (自动检测)">
</div>
<div class="form-group">
<label for="smtpPort">SMTP端口</label>
<input type="number" id="smtpPort" name="smtpPort" placeholder="587 (自动检测)">
</div>
<div class="form-group">
<label for="proxyPort">代理端口(可选)</label>
<input type="number" id="proxyPort" name="proxyPort" placeholder="7890" min="1" max="65535">
</div>
</div>
</div>
<!-- LLM配置 -->
<div class="section">
<h2>🤖 LLM配置</h2>
<div class="grid">
<div class="form-group">
<label for="llmProvider">API 供应商</label>
<select id="llmProvider" name="llmProvider">
<option value="openai">OpenAI</option>
<option value="gemini">Google Gemini</option>
</select>
</div>
<div class="form-group">
<label for="llmBaseUrl">LLM Base URL <span class="required">*</span></label>
<input type="url" id="llmBaseUrl" name="llmBaseUrl" required placeholder="https://api.openai.com/v1">
</div>
<div class="form-group">
<label for="llmApiKey">API Key <span class="required">*</span></label>
<input type="password" id="llmApiKey" name="llmApiKey" required placeholder="sk-...">
</div>
</div>
<div class="form-group">
<label for="llmModel">模型名称</label>
<input type="text" id="llmModel" name="llmModel" placeholder="gpt-3.5-turbo">
</div>
</div>
<!-- 申请者信息 -->
<div class="section">
<h2>👤 申请者信息</h2>
<div class="grid">
<div class="form-group">
<label for="applicantName">姓名 <span class="required">*</span></label>
<input type="text" id="applicantName" name="applicantName" required placeholder="张三">
</div>
<div class="form-group">
<label for="applicantSchool">学校 <span class="required">*</span></label>
<input type="text" id="applicantSchool" name="applicantSchool" required placeholder="某某大学">
</div>
</div>
<div class="grid">
<div class="form-group">
<label for="applicantCollege">学院</label>
<input type="text" id="applicantCollege" name="applicantCollege" placeholder="计算机学院">
</div>
<div class="form-group">
<label for="applicantMajor">专业</label>
<input type="text" id="applicantMajor" name="applicantMajor" placeholder="计算机科学与技术">
</div>
</div>
<div class="grid">
<div class="form-group">
<label for="enrollYear">入学年份 <span class="required">*</span></label>
<input type="number" id="enrollYear" name="enrollYear" required placeholder="2021" min="1990" max="2100" step="1">
</div>
<div></div>
</div>
</div>
<!-- 申请信息 -->
<div class="section">
<h2>📝 申请信息</h2>
<div class="grid">
<div class="form-group">
<label for="applicationType">申请目的 <span class="required">*</span></label>
<select id="applicationType" name="applicationType" required>
<option value="">请选择申请目的</option>
<option value="保研">保研</option>
<option value="实习">实习</option>
<option value="访问学生">访问学生</option>
<option value="博士申请">博士申请</option>
<option value="硕士申请">硕士申请</option>
<option value="博士后">博士后</option>
<option value="其他">其他(自定义)</option>
</select>
<input type="text" id="customApplicationType" name="customApplicationType" placeholder="请输入自定义申请目的" style="display:none; margin-top:8px;" />
</div>
<div class="form-group">
<label for="resumeFile">简历PDF <span class="required">*</span></label>
<div class="file-input">
<input type="file" id="resumeFile" name="resumeFile" accept=".pdf" required>
<label for="resumeFile" class="file-input-label">
📄 点击上传简历PDF文件
</label>
</div>
</div>
</div>
<div class="grid">
<div class="form-group">
<label for="transcriptFile">成绩单PDF(可选)</label>
<div class="file-input">
<input type="file" id="transcriptFile" name="transcriptFile" accept=".pdf">
<label for="transcriptFile" class="file-input-label">
📄 点击上传成绩单PDF文件(可选)
</label>
</div>
</div>
<div class="form-group">
<label for="additionalPdfs">附加PDF(可选,可多选)</label>
<div class="file-input">
<input type="file" id="additionalPdfs" name="additionalPdfs" accept=".pdf" multiple>
<label for="additionalPdfs" class="file-input-label">
📎 选择要一并发送的其他PDF(仅文件名会进入提示词)
</label>
</div>
</div>
</div>
<div class="grid">
<div class="form-group">
<label for="emailLanguage">邮件语言</label>
<select id="emailLanguage" name="emailLanguage">
<option value="zh">中文</option>
<option value="en">English</option>
</select>
</div>
<div class="form-group">
<label for="emailStyle">语言风格提示(可选)</label>
<textarea id="emailStyle" name="emailStyle" placeholder="例如:语气自然、简洁有礼;先表达对导师研究的理解,再说明自身经历匹配与可贡献点;避免夸张辞藻;整体控制在 180-260 字。"></textarea>
</div>
</div>
<div></div>
</div>
</div>
<!-- 导师信息 -->
<div class="section">
<h2>👨🏫 导师信息</h2>
<div id="tutorList">
<div class="tutor-entry">
<h3>导师 1</h3>
<div class="form-group">
<label>导师邮箱 <span class="required">*</span></label>
<input type="email" name="tutorEmail[]" required placeholder="professor@university.edu">
</div>
<div class="form-group">
<label>导师姓名</label>
<input type="text" name="tutorName[]" placeholder="教授姓名">
</div>
<div class="form-group">
<label>个人主页网址</label>
<input type="url" name="tutorWebsite[]" placeholder="https://university.edu/~professor">
</div>
<div class="form-group">
<label>个人介绍文本</label>
<textarea name="tutorBio[]" placeholder="导师的研究方向、学术背景等信息..."></textarea>
</div>
<button type="button" class="btn btn-danger" onclick="removeTutor(this)" style="display: none;">删除导师</button>
</div>
</div>
<button type="button" class="btn btn-secondary" onclick="addTutor()">➕ 添加导师</button>
<button type="button" class="btn btn-secondary" onclick="document.getElementById('batchUpload').click()">📁 批量上传</button>
<input type="file" id="batchUpload" accept=".csv,.json" style="display: none;" onchange="handleBatchUpload(this)">
</div>
<!-- 发送按钮 -->
<div style="display:flex; justify-content:center; align-items:center; gap:16px; flex-wrap:wrap;">
<button type="submit" class="btn btn-success">🚀 生成并发送邮件</button>
<label style="display:flex; align-items:center; gap:8px;">
<input type="checkbox" id="reviewBeforeSend" name="reviewBeforeSend">
发送前逐封复核(可编辑)
</label>
</div>
<!-- 进度显示 -->
<div class="progress-container" id="progressContainer">
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
<div id="progressText" style="text-align: center; margin-top: 10px;">准备中...</div>
</div>
<!-- 状态消息 -->
<div id="statusMessage" class="status-message"></div>
</form>
</div>
</div>
<script>
let tutorCount = 1;
// 函数:保存表单数据到 localStorage
const STORAGE_KEY = 'intelligentTutorFormData';
function saveData() {
const formData = {};
// 筛选出需要保存的输入元素 (排除文件)
document.querySelectorAll('#emailForm input, #emailForm textarea, #emailForm select').forEach(el => {
if (el.type !== 'file' && el.id) {
if (el.type === 'checkbox') {
formData[el.id] = el.checked;
} else {
formData[el.id] = el.value;
}
}
});
// 特别处理动态添加的导师信息
const tutors = [];
document.querySelectorAll('#tutorList .tutor-entry').forEach(entry => {
const tutor = {
email: entry.querySelector('input[name="tutorEmail[]"]').value,
name: entry.querySelector('input[name="tutorName[]"]').value,
website: entry.querySelector('input[name="tutorWebsite[]"]').value,
bio: entry.querySelector('textarea[name="tutorBio[]"]').value
};
tutors.push(tutor);
});
formData.tutors = tutors;
localStorage.setItem(STORAGE_KEY, JSON.stringify(formData));
}
// 函数:从 localStorage 加载并填充表单数据
function loadData() {
const savedData = localStorage.getItem(STORAGE_KEY);
if (!savedData) return;
const formData = JSON.parse(savedData);
// 填充普通输入框
Object.keys(formData).forEach(key => {
// 排除导师信息,它将被单独处理
if (key === 'tutors') return;
const el = document.getElementById(key);
if (el) {
if (el.type === 'checkbox') {
el.checked = formData[key];
} else {
el.value = formData[key];
}
}
});
// 触发一次 change 事件以确保UI同步 (例如 "其他" 选项)
document.getElementById('applicationType').dispatchEvent(new Event('change'));
// 填充动态导师信息
if (formData.tutors && formData.tutors.length > 0) {
document.getElementById('tutorList').innerHTML = ''; // 清空默认的
tutorCount = 0;
formData.tutors.forEach(tutorData => {
addTutorFromData(tutorData);
});
}
}
// 添加导师
function addTutor() {
tutorCount++;
const tutorList = document.getElementById('tutorList');
const newTutor = document.createElement('div');
newTutor.className = 'tutor-entry';
newTutor.innerHTML = `
<h3>导师 ${tutorCount}</h3>
<div class="form-group">
<label>导师邮箱 <span class="required">*</span></label>
<input type="email" name="tutorEmail[]" required placeholder="professor@university.edu">
</div>
<div class="form-group">
<label>导师姓名</label>
<input type="text" name="tutorName[]" placeholder="教授姓名">
</div>
<div class="form-group">
<label>个人主页网址</label>
<input type="url" name="tutorWebsite[]" placeholder="https://university.edu/~professor">
</div>
<div class="form-group">
<label>个人介绍文本</label>
<textarea name="tutorBio[]" placeholder="导师的研究方向、学术背景等信息..."></textarea>
</div>
<button type="button" class="btn btn-danger" onclick="removeTutor(this)">删除导师</button>
`;
tutorList.appendChild(newTutor);
updateDeleteButtons();
}
// 删除导师
function removeTutor(button) {
button.parentElement.remove();
updateTutorNumbers();
updateDeleteButtons();
saveData()
}
// 更新导师编号
function updateTutorNumbers() {
const tutors = document.querySelectorAll('.tutor-entry h3');
tutors.forEach((h3, index) => {
h3.textContent = `导师 ${index + 1}`;
});
tutorCount = tutors.length;
}
// 更新删除按钮显示
function updateDeleteButtons() {
const deleteButtons = document.querySelectorAll('.tutor-entry .btn-danger');
deleteButtons.forEach(button => {
button.style.display = deleteButtons.length > 1 ? 'inline-block' : 'none';
});
}
// 处理批量上传
function handleBatchUpload(input) {
const file = input.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
let data;
if (file.name.endsWith('.json')) {
data = JSON.parse(e.target.result);
} else if (file.name.endsWith('.csv')) {
data = parseCSV(e.target.result);
}
// 清空现有导师列表
document.getElementById('tutorList').innerHTML = '';
tutorCount = 0;
// 添加批量导师
data.forEach(tutor => {
addTutorFromData(tutor);
});
saveData();
showStatus('批量导师信息上传成功!', 'success');
} catch (error) {
showStatus('文件格式错误,请检查文件内容', 'error');
}
};
reader.readAsText(file);
}
// 从数据添加导师
function addTutorFromData(tutorData) {
tutorCount++;
const tutorList = document.getElementById('tutorList');
const newTutor = document.createElement('div');
newTutor.className = 'tutor-entry';
newTutor.innerHTML = `
<h3>导师 ${tutorCount}</h3>
<div class="form-group">
<label>导师邮箱 <span class="required">*</span></label>
<input type="email" name="tutorEmail[]" required placeholder="professor@university.edu" value="${tutorData.email || ''}">
</div>
<div class="form-group">
<label>导师姓名</label>
<input type="text" name="tutorName[]" placeholder="教授姓名" value="${tutorData.name || ''}">
</div>
<div class="form-group">
<label>个人主页网址</label>
<input type="url" name="tutorWebsite[]" placeholder="https://university.edu/~professor" value="${tutorData.website || ''}">
</div>
<div class="form-group">
<label>个人介绍文本</label>
<textarea name="tutorBio[]" placeholder="导师的研究方向、学术背景等信息...">${tutorData.bio || ''}</textarea>
</div>
<button type="button" class="btn btn-danger" onclick="removeTutor(this)">删除导师</button>
`;
tutorList.appendChild(newTutor);
updateDeleteButtons();
}
// 解析CSV
function parseCSV(text) {
const lines = text.split('\n');
const headers = lines[0].split(',').map(h => h.trim());
const data = [];
for (let i = 1; i < lines.length; i++) {
if (lines[i].trim()) {
const values = lines[i].split(',').map(v => v.trim());
const obj = {};
headers.forEach((header, index) => {
obj[header] = values[index] || '';
});
data.push(obj);
}
}
return data;
}
// 显示状态消息
function showStatus(message, type) {
const statusDiv = document.getElementById('statusMessage');
statusDiv.textContent = message;
statusDiv.className = `status-message status-${type}`;
statusDiv.style.display = 'block';
setTimeout(() => {
statusDiv.style.display = 'none';
}, 5000);
}
// 更新进度
function updateProgress(percent, text) {
document.getElementById('progressFill').style.width = percent + '%';
document.getElementById('progressText').textContent = text;
}
// 使用 PDF.js 解析上传的简历PDF为纯文本
async function extractResumeText(file) {
try {
const arrayBuffer = await file.arrayBuffer();
const pdfjsLib = window['pdfjs-dist/build/pdf'];
if (!pdfjsLib) throw new Error('PDF.js 未加载');
const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise;
let fullText = '';
for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
const page = await pdf.getPage(pageNum);
const content = await page.getTextContent();
const strings = content.items.map(item => item.str);
fullText += strings.join(' ') + '\n';
}
// 规范化空白,避免过长提示词
return fullText.replace(/\s+/g, ' ').trim();
} catch (err) {
console.warn('简历解析失败:', err);
return '';
}
}
// 自动检测SMTP设置
function detectSMTPSettings(email) {
const domain = email.split('@')[1];
const smtpSettings = {
'gmail.com': { server: 'smtp.gmail.com', port: 587 },
'outlook.com': { server: 'smtp-mail.outlook.com', port: 587 },
'hotmail.com': { server: 'smtp-mail.outlook.com', port: 587 },
'yahoo.com': { server: 'smtp.mail.yahoo.com', port: 587 },
'163.com': { server: 'smtp.163.com', port: 587 },
'126.com': { server: 'smtp.126.com', port: 587 },
'qq.com': { server: 'smtp.qq.com', port: 587 }
};
if (smtpSettings[domain]) {
document.getElementById('smtpServer').value = smtpSettings[domain].server;
document.getElementById('smtpPort').value = smtpSettings[domain].port;
}
}
// 邮箱输入时自动检测SMTP
document.getElementById('senderEmail').addEventListener('blur', function() {
if (this.value) {
detectSMTPSettings(this.value);
}
});
// 文件上传显示
document.getElementById('resumeFile').addEventListener('change', function() {
const label = this.nextElementSibling;
if (this.files.length > 0) {
label.textContent = `✅ ${this.files[0].name}`;
label.style.background = '#d4edda';
label.style.color = '#155724';
}
});
// 申请目的:显示/隐藏自定义输入
document.getElementById('applicationType').addEventListener('change', function() {
const custom = document.getElementById('customApplicationType');
if (this.value === '其他') {
custom.style.display = '';
} else {
custom.style.display = 'none';
custom.value = '';
}
});
// 成绩单上传显示
document.getElementById('transcriptFile').addEventListener('change', function() {
const label = this.nextElementSibling;
if (this.files.length > 0) {
label.textContent = `✅ ${this.files[0].name}`;
label.style.background = '#d4edda';
label.style.color = '#155724';
} else {
label.textContent = '📄 点击上传成绩单PDF文件(可选)';
label.style.background = '';
label.style.color = '';
}
});
// 附加PDF上传显示
document.getElementById('additionalPdfs').addEventListener('change', function() {
const label = this.nextElementSibling;
if (this.files.length > 0) {
label.textContent = `✅ 已选择 ${this.files.length} 个PDF附件`;
label.style.background = '#d4edda';
label.style.color = '#155724';
} else {
label.textContent = '📎 选择要一并发送的其他PDF(仅文件名会进入提示词)';
label.style.background = '';
label.style.color = '';
}
});
// 表单提交处理
document.getElementById('emailForm').addEventListener('submit', async function(e) {
e.preventDefault();
// 显示进度条
document.getElementById('progressContainer').style.display = 'block';
updateProgress(0, '准备发送邮件...');
try {
// 收集表单数据
const formData = new FormData(this);
const tutors = collectTutorData();
const reviewEnabled = document.getElementById('reviewBeforeSend').checked;
const language = (formData.get('emailLanguage') || 'zh');
if (tutors.length === 0) {
throw new Error('请至少添加一位导师信息');
}
// 验证每个导师至少有邮箱和(主页或介绍)
for (let tutor of tutors) {
if (!tutor.email) {
throw new Error('所有导师都必须提供邮箱地址');
}
if (!tutor.website && !tutor.bio) {
throw new Error('每位导师必须提供个人主页网址或个人介绍文本');
}
}
// 收集申请者基本信息(供提示词与发件人名称使用)
const applicantInfo = {
name: (formData.get('applicantName') || '').trim(),
school: (formData.get('applicantSchool') || '').trim(),
college: (formData.get('applicantCollege') || '').trim(),
major: (formData.get('applicantMajor') || '').trim(),
enrollYear: (formData.get('enrollYear') || '').trim()
};
// 严格主题格式需要姓名、学校与入学年份
if (!applicantInfo.name || !applicantInfo.school || !applicantInfo.enrollYear) {
throw new Error('请填写姓名、学校和入学年份(四位年份),用于生成严格主题');
}
// 解析上传的简历PDF文本,并限制输入长度
updateProgress(10, '正在解析简历PDF...');
const resumeFileInput = document.getElementById('resumeFile');
const resumeFile = resumeFileInput && resumeFileInput.files ? resumeFileInput.files[0] : null;
let resumeText = '';
if (resumeFile) {
resumeText = await extractResumeText(resumeFile);
}
const resumeTextLimited = (resumeText || '').slice(0, 4000); // 避免提示词过长
// 解析成绩单PDF文本,并限制输入长度(可选)
updateProgress(15, '正在解析成绩单PDF...');
const transcriptInput = document.getElementById('transcriptFile');
const transcriptFile = transcriptInput && transcriptInput.files ? transcriptInput.files[0] : null;
let transcriptText = '';
if (transcriptFile) {
transcriptText = await extractResumeText(transcriptFile);
}
const transcriptTextLimited = (transcriptText || '').slice(0, 4000);
// 收集附加PDF的文件名(仅文件名进入提示词)
const additionalInput = document.getElementById('additionalPdfs');
const additionalFiles = additionalInput && additionalInput.files ? Array.from(additionalInput.files) : [];
const additionalPdfNames = additionalFiles.map(f => f.name);
updateProgress(20, '正在生成个性化邮件...');
// 计算申请目的(支持自定义)
const selectedType = formData.get('applicationType') || '';
const customType = (document.getElementById('customApplicationType').value || '').trim();
const applicationTypeUsed = customType || selectedType;
const pendingEmails = [];
// 为每个导师生成邮件
for (let i = 0; i < tutors.length; i++) {
const tutor = tutors[i];
updateProgress(20 + (i / tutors.length) * 60, `正在为 ${tutor.name || tutor.email} 生成邮件...`);
// 获取导师信息
let tutorInfo = tutor.bio || '';
if (tutor.website) {
try {
tutorInfo += await fetchWebsiteContent(tutor.website);
} catch (error) {
console.warn('无法获取网页内容:', error);
}
}
// 调用LLM生成邮件(加入简历、成绩单解析文本和附加PDF文件名)
const emailContent = await generateEmail({
tutorInfo: tutorInfo,
tutorName: tutor.name,
applicationType: applicationTypeUsed,
emailStyle: formData.get('emailStyle'),
llmProvider: formData.get('llmProvider'),
llmBaseUrl: formData.get('llmBaseUrl'),
llmApiKey: formData.get('llmApiKey'),
llmModel: formData.get('llmModel') || 'gpt-3.5-turbo',
resumeText: resumeTextLimited,
transcriptText: transcriptTextLimited,
additionalPdfNames: additionalPdfNames,
applicant: applicantInfo,
language: language
});
// 发送邮件(强制使用规范主题:类型:年份(入学时间)- 姓名 - 学校)
const typeMap = { '访问学生': '访问', '保研': '保研', '实习': '实习' };
const typeText = typeMap[applicationTypeUsed] || applicationTypeUsed;
const subjectStrict = `${typeText}:${applicantInfo.enrollYear}(入学时间)- ${applicantInfo.name} - ${applicantInfo.school}`;
const draft = {
to: tutor.email,
subject: subjectStrict,
body: emailContent.body,
senderEmail: formData.get('senderEmail'),
senderPassword: formData.get('senderPassword'),
smtpServer: formData.get('smtpServer'),
smtpPort: formData.get('smtpPort'),
proxyPort: formData.get('proxyPort'),
resumeFile: formData.get('resumeFile'),
transcriptFile: formData.get('transcriptFile'),
additionalPdfs: additionalFiles,
senderName: applicantInfo.name || '申请者',
tutorName: tutor.name || '',
emailLanguage: language
};
if (reviewEnabled) {
pendingEmails.push(draft);
} else {
await sendEmail(draft);
}
}
if (reviewEnabled) {
renderReviewList(pendingEmails);
updateProgress(85, '请逐封复核并可编辑,确认后发送');
showStatus('请在下方复核每封邮件的主题与正文,确认无误后点击“确认并发送全部”。', 'info');
return; // 等用户确认后再发送
}
updateProgress(100, '所有邮件发送完成!');
showStatus(`成功向 ${tutors.length} 位导师发送了个性化套磁邮件!`, 'success');
} catch (error) {
console.error('发送失败:', error);
showStatus('发送失败: ' + error.message, 'error');
updateProgress(0, '发送失败');
}
// 3秒后隐藏进度条
setTimeout(() => {
document.getElementById('progressContainer').style.display = 'none';
}, 3000);
});
// 渲染复核列表并绑定发送
function renderReviewList(pendingEmails) {
const section = document.getElementById('reviewSection');
const list = document.getElementById('reviewList');
list.innerHTML = '';
section.style.display = 'block';