-
Notifications
You must be signed in to change notification settings - Fork 0
/
excel_processing_with_gpt_v1.1.html
816 lines (683 loc) · 25.5 KB
/
excel_processing_with_gpt_v1.1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel Processing with GPT</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@latest/dist/handsontable.full.min.css">
<script src="https://cdn.jsdelivr.net/npm/hyperformula@latest/dist/hyperformula.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/handsontable@latest/dist/handsontable.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
/* 或者根据需要设置其他值 */
}
/* Handsontable 的容器 */
#hot {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
border: 1px solid #E0E0E0;
/* overflow: auto; */
/* 添加滚动条 */
/* min-height: 300px; */
/* 设置一个合理的最小高度 */
}
/* 单元格 */
.handsontable td {
background: #FFFFFF;
/* 白色背景 */
color: #212121;
/* 深灰色文本 */
font-family: 'Roboto', sans-serif;
/* Material Design 字体 */
font-size: 16px;
/* 调整字体大小 */
padding: 10px;
/* 增加填充以扩大单元格 */
word-wrap: break-word;
/* 长单词也能换行 */
}
/* 悬停效果 */
.handsontable td:hover {
background: #EEEEEE;
/* 当鼠标悬停时的背景色 */
}
/* 工具栏按钮 */
.mdl-button {
color: #757575;
/* 按钮文字颜色 */
background-color: #FFFFFF;
/* 白色背景 */
margin-bottom: 10px;
/* 在按钮之间添加垂直间距 */
}
/* 表格输入框 */
.handsontable input {
font-family: 'Roboto', sans-serif;
}
.container {
display: flex;
height: 100vh;
/* 视口高度 */
}
.left-column {
width: 70%;
height: 100vh;
/* 视口高度 */
overflow-y: auto;
/* 内部滚动 */
}
.right-column {
width: 30%;
/* 右列的样式 */
display: flex;
flex-direction: column;
align-items: start;
/* 确保按钮靠左对齐 */
padding: 10px;
/* 在右侧列周围添加留白 */
position: sticky;
/* 固定位置 */
top: 0;
/* 顶部对齐 */
}
h5 {
margin-top: 20px;
/* 在标题顶部添加间距 */
margin-bottom: 10px;
/* 在标题底部添加间距 */
}
.modal {
display: none;
/* 弹窗的基础样式 */
}
.mdl-dialog {
display: block;
/* 或者使用 flex, 根据您的需要 */
position: fixed;
/* 使用固定定位 */
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #FFFFFF;
/* 使用变换来确保完全居中 */
/* 其他样式根据需要添加 */
}
.buttons-container {
display: flex;
/* 启用flex布局 */
flex-direction: row;
/* 按行排列 */
justify-content: space-between;
/* 在元素间平均分配可用空间 */
align-items: center;
/* 垂直居中对齐 */
width: 100%;
/* 容器宽度填满父元素 */
}
/* STOP GPT 按钮的特殊样式 */
.stop-gpt {
animation: pulseRed 2s infinite;
background-color: rgba(235, 61, 61, 0.687);
/* 偏红的颜色 */
}
/* 动画效果 */
@keyframes pulseRed {
0% {
transform: scale(1);
background-color: rgba(235, 61, 61, 0.687);
}
50% {
transform: scale(1.1);
background-color: darkred;
}
100% {
transform: scale(1);
background-color: rgba(235, 61, 61, 0.687);
}
}
.personal-info {
background-color: #f2f2f2;
padding: 20px;
text-align: center;
margin-top: 50px;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<body>
<div class="container">
<div class="left-column">
<!-- 左侧列内容 -->
<!-- 文件操作 -->
<div class="buttons-container">
<div>
<label class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--file"
for="upload">
<input type="file" id="upload" style="display: none;">
Upload File
</label>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="newTable">
New Table
</button>
</div>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored"
id="toggleGPT">
Start GPT
</button>
</div>
<div id="hot"></div>
</div>
<div class="right-column">
<!-- 表格操作 -->
<h5 style="margin-left: 10px;">表格操作</h5>
<div style="margin: 10px;">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="markCell">
Mark Cell
</button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="unmarkCell">
Unmark Cell
</button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="clearMarks">
Clear Marks
</button>
<!-- 设置列宽的按钮 -->
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="setColumnWidth">
Set Column Width
</button>
</div>
<hr>
<!-- GPT回复模式 -->
<h5 style="margin-left: 10px;">GPT 回复模式</h5>
<div style="margin: 10px;">
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-overwrite">
<input type="radio" id="option-overwrite" class="mdl-radio__button" name="options" value="overwrite">
<span class="mdl-radio__label">覆盖原有的 Prompt 的 cell</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-append">
<input type="radio" id="option-append" class="mdl-radio__button" name="options" value="append">
<span class="mdl-radio__label">在 prompt cell 的右侧 cell 填入内容</span>
</label>
</div>
<hr>
<!-- 设置 -->
<h5 style="margin-left: 10px;">设置</h5>
<div style="margin: 10px;">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="settings">
Settings
</button>
</div>
<hr>
<!-- 导出 -->
<h5 style="margin-left: 10px;">导出</h5>
<div style="margin: 10px;">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="exportExcel">
Export to Excel
</button>
</div>
</div>
</div>
<!-- 弹窗内容 -->
<div id="uploadNewTableModal" class="modal">
<!-- 弹窗的具体内容 -->
<label class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--file" for="upload">
<input type="file" id="upload" style="display: none;">
Upload File
</label>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="newTable">
New Table
</button>
</div>
<!-- 设置模态框样式 -->
<div id="settingsModal" class="mdl-dialog" style="display:none;">
<div class="mdl-dialog__content">
<div>
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="apiUrl">
<label class="mdl-textfield__label" for="apiUrl">API URL:</label>
</div>
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="apiKey">
<label class="mdl-textfield__label" for="apiKey">API Key:</label>
</div>
</div>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button" id="saveSettings">Save Settings</button>
</div>
</div>
<!-- API 设置警告弹窗 -->
<div id="apiSettingsWarningModal" class="mdl-dialog">
<h4 class="mdl-dialog__title">API Settings Required</h4>
<div class="mdl-dialog__content">
<p>
Please enter a valid API URL and API Key to proceed.
</p>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button close" id="close-api-warning">Close</button>
</div>
</div>
<!-- 个人信息栏 -->
<div class="personal-info">
<h4>联系 fundaymaker</h4>
<p>有任何问题或建议,请通过以下方式联系我:</p>
<p>邮箱: <a href="mailto:coues.fang.10@gmail.com">coues.fang.10@gmail.com</a></p>
</div>
<script>
// 为弹窗添加关闭功能的代码
// Processing queue for marked cells
var processingQueue = [];
// 新增全局变量来跟踪GPT状态
var isGPTStarted = false;
var stopProcessing = false;
// Global variable to store the current selection
var currentSelection = null;
// TODO: finish logic of mode selection
var responseMode = 0;//0 means cover origin prompt
var apiUrl = "";
var apiKey = "";
// Initialize Handsontable
var hotElement = document.querySelector('#hot');
var hotElementContainer = hotElement.parentNode;
function markedCellRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
// Ensure processingQueue is defined and is an array
if (Array.isArray(processingQueue) && processingQueue.some(cell => cell.row === row && cell.col === col)) {
td.style.background = '#FFD700'; // Example: gold background for marked cells
} else {
td.style.background = ''; // Reset background
}
}
var hotSettings = {
licenseKey: 'non-commercial-and-evaluation',
data: Handsontable.helper.createSpreadsheetData(6, 10),
rowHeaders: true,
colHeaders: true,
contextMenu: true,
manualRowResize: true,
manualColumnResize: true,
manualRowMove: true,
manualColumnMove: true,
filters: true,
dropdownMenu: true,
// 禁用自动行大小调整
autoRowSize: false,
// 设置固定的行高
rowHeights: 23, // 或你需要的具体数值
cells: function (row, col, prop) {
const cellProperties = {};
cellProperties.renderer = markedCellRenderer; // Use the custom renderer for all cells
return cellProperties;
},
// ...其他设置...
width: '100%',
stretchH: 'all', // 这个设置会使列宽自动调整以填满整个容器宽度
// Integrate HyperFormula
formulas: {
engine: HyperFormula
},
wordWrap: false,
trimWhitespace: true
};
var hot = new Handsontable(hotElement, hotSettings);
hot.updateSettings({
cells: function (row, col) {
var cellProperties = {};
cellProperties.renderer = markedCellRenderer; // Use the custom renderer for all cells
return cellProperties;
}
});
// Add an event listener to store the selection
hot.addHook('afterSelection', function (r1, c1, r2, c2) {
currentSelection = [r1, c1, r2, c2];
});
hot.addHook('afterOnCellMouseDown', function (event, coords, TD) {
if (event.target.className.includes('colHeader')) {
// 如果点击的是列头,存储整列的选择
currentSelection = [0, coords.col, hot.countRows() - 1, coords.col];
} else if (event.target.className.includes('rowHeader')) {
// 如果点击的是行头,存储整行的选择
currentSelection = [coords.row, 0, coords.row, hot.countCols() - 1];
} else {
// 如果点击的是单元格,存储单元格的选择
currentSelection = [coords.row, coords.col, coords.row, coords.col];
}
});
// 修改的startGPT和stopGPT函数
function toggleGPT() {
if (isGPTStarted) {
// 停止GPT逻辑
console.log('GPT Stopped');
isGPTStarted = false;
stopGPT()
} else {
// 启动GPT逻辑
console.log('GPT Started');
isGPTStarted = true;
startGPT()
}
updateGPTButton();
}
// 更新按钮文本的函数
function updateGPTButton() {
var button = document.getElementById('toggleGPT');
if (isGPTStarted) {
button.textContent = 'Stop GPT';
button.classList.add('stop-gpt'); // 添加特殊类以改变样式
} else {
button.textContent = 'Start GPT';
button.classList.remove('stop-gpt'); // 移除特殊类
}
}
// 处理文件上传和读取为表格的函数
function handleFileUpload(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, { type: 'binary' });
var firstSheetName = workbook.SheetNames[0];
var worksheet = workbook.Sheets[firstSheetName];
var newData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
// 加载数据到表格
hot.loadData(newData);
// 更新表格设置以限制列宽
updateTableColumnWidths(newData[0].length);
};
reader.readAsBinaryString(file);
}
// 更新表格列宽的函数
function updateTableColumnWidths(numberOfColumns) {
var maxColumnWidth = 200; // 设置最大列宽(例如200像素)
var columnSettings = [];
for (var i = 0; i < numberOfColumns; i++) {
columnSettings.push({ width: maxColumnWidth });
}
hot.updateSettings({
columns: columnSettings
});
}
// Function to create a new table
function createNewTable() {
hot.loadData(Handsontable.helper.createSpreadsheetData(6, 10));
}
// Function to normalize selection range
function normalizeSelection(range) {
var startRow = Math.min(range[0], range[2]);
var endRow = Math.max(range[0], range[2]);
var startCol = Math.min(range[1], range[3]);
var endCol = Math.max(range[1], range[3]);
return [startRow, startCol, endRow, endCol];
}
// Function to mark cells using the stored selection
function markCells() {
if (currentSelection) {
var range = normalizeSelection(currentSelection);
for (var row = range[0]; row <= range[2]; row++) {
for (var col = range[1]; col <= range[3]; col++) {
processingQueue.push({ row: row, col: col });
hot.setCellMeta(row, col, 'renderer', markedCellRenderer);
}
}
hot.render();
// Optionally, restore the selection here if needed
hot.selectCells([currentSelection]);
console.log(processingQueue)
}
}
// Function to unmark cells using the stored selection
function unmarkCells() {
if (currentSelection) {
var range = normalizeSelection(currentSelection);
for (var row = range[0]; row <= range[2]; row++) {
for (var col = range[1]; col <= range[3]; col++) {
processingQueue = processingQueue.filter(function (cell) {
return !(cell.row === row && cell.col === col);
});
hot.setCellMeta(row, col, 'renderer', null);
}
}
hot.render();
// Optionally, restore the selection here if needed
hot.selectCells([currentSelection]);
}
}
// Function to clear all marks
function clearMarks() {
processingQueue.forEach(function (cell) {
hot.setCellMeta(cell.row, cell.col, 'renderer', null);
});
processingQueue = [];
hot.render();
}
// Function to export table to Excel
function exportToExcel() {
// Export to Excel logic here
// Function to export table to Excel, including formulas
function exportToExcelWithFormulas() {
// 获取包含公式的原始数据
var data = hot.getSourceData();
// 创建一个新的工作簿
var workbook = XLSX.utils.book_new();
// 将数据转换为 Excel 可接受的格式
var aoa_data = data.map(row => {
return row.map(cell => {
// 检查单元格是否包含公式
if (typeof cell === 'string' && cell.startsWith('=')) {
// Excel 公式以等号开始
return { f: cell.slice(1) }; // 去除等号,并将其标记为公式
}
return cell;
});
});
// 创建一个工作表
var worksheet = XLSX.utils.aoa_to_sheet(aoa_data);
// 将工作表添加到工作簿
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
// 设置要导出的文件名
var fileName = "exported_table_with_formulas.xlsx";
// 导出工作簿(即下载 Excel 文件)
XLSX.writeFile(workbook, fileName);
}
// 将此函数添加到事件监听器中,以便在点击导出按钮时调用
document.getElementById('exportExcel').addEventListener('click', exportToExcelWithFormulas);
}
async function startGPT() {
var isAvailable = await checkAPIAvailability(apiUrl, apiKey);
if (isAvailable) {
// 继续你的逻辑
} else {
console.log("API is not available. Please check your URL and API key.");
showAPISettingsWarning(); // 显示弹窗
return;
}
// 将处理队列按照行和列进行排序
processingQueue.sort(function (a, b) {
if (a.row === b.row) {
return a.col - b.col;
}
return a.row - b.row;
});
// Reset stopProcessing flag
stopProcessing = false;
// 使用 while 循环遍历处理processingQueue
while (processingQueue.length > 0 && !stopProcessing) {
var cell = processingQueue.shift(); // 使用 shift() 而不是索引来取得并移除队列中的第一个元素
// 获取单元格的内容
var content = hot.getDataAtCell(cell.row, cell.col);
console.log(content);
try {
// 调用GPT并获取返回值(等待异步操作完成)
var result = await callGPT(content);
// 根据responseMode设置单元格的内容
var responseMode = getResponseMode();
if (responseMode === 'overwrite') {
hot.setDataAtCell(cell.row, cell.col, result);
} else if (responseMode === 'append') {
hot.setDataAtCell(cell.row, cell.col + 1, result);
}
} catch (error) {
console.error('Error calling GPT:', error);
// 可以在这里处理错误,例如中断处理或者记录错误等
}
// 如果我们收到了停止处理的信号,就跳出循环
if (stopProcessing) {
break;
}
}
// 处理完成后,自动更新状态
isGPTStarted = false;
updateGPTButton();
}
function checkAPIAvailability(apiUrl, apiKey) {
if (apiKey === "" && apiUrl === "") {
return false;
}
else {
return true;
}
}
function showAPISettingsWarning() {
var dialog = document.getElementById('apiSettingsWarningModal');
dialog.style.display = 'block';
}
function hideAPISettingsWarning() {
var dialog = document.getElementById('apiSettingsWarningModal');
dialog.style.display = 'none';
}
function setAllColumnWidths() {
var newWidth = prompt("Enter the new width for all columns:", "100");
if (newWidth != null) {
var numberOfColumns = hot.countCols();
var columnSettings = [];
for (var i = 0; i < numberOfColumns; i++) {
columnSettings.push({ width: parseInt(newWidth) });
}
hot.updateSettings({
columns: columnSettings
});
}
}
function getResponseMode() {
if (document.getElementById('option-overwrite').checked) {
return 'overwrite';
} else if (document.getElementById('option-append').checked) {
return 'append';
}
return 'overwrite'; // 默认模式
}
// Function to stop GPT processing
function stopGPT() {
// 设置标志以停止处理
stopProcessing = true;
}
// Function to open settings modal
function openSettings() {
document.getElementById('settingsModal').style.display = 'block';
};
function saveSettings() {
apiUrl = document.getElementById('apiUrl').value;
apiKey = document.getElementById('apiKey').value;
// Set cookies to expire in 7 days
let date = new Date();
date.setTime(date.getTime() + (5 * 24 * 60 * 60 * 1000));
let expires = "; expires=" + date.toUTCString();
// Save the settings in cookies
document.cookie = "apiUrl=" + apiUrl + expires + "; path=/";
document.cookie = "apiKey=" + apiKey + expires + "; path=/";
document.getElementById('settingsModal').style.display = 'none';
};
window.onload = function () {
console.log("hhhhh");
document.getElementById('option-overwrite').checked = true; // 设置默认选项为“覆盖原有的 Prompt 的 cell”
document.getElementById('apiSettingsWarningModal').style.display = 'none';
let cookieApiUrl = getCookie("apiUrl");
let cookieApiKey = getCookie("apiKey");
console.log(cookieApiKey);
console.log(cookieApiUrl)
if (cookieApiUrl) {
apiUrl = cookieApiUrl;
document.getElementById('apiUrl').value = apiUrl;
}
if (cookieApiKey) {
apiKey = cookieApiKey;
document.getElementById('apiKey').value = apiKey;
}
};
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
async function callGPT(content) {
console.log("call GPT");
try {
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
model: "gpt-4-1106-preview",
messages: [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": content
}
]
})
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log(data);
let parsedResponse = data.choices[0].message.content;
let extractedResponse = parsedResponse;
console.log(extractedResponse);
return extractedResponse;
} catch (error) {
console.error('Error:', error);
}
};
// Event listeners
// 页面加载时更新按钮文本
document.addEventListener('DOMContentLoaded', function () {
updateGPTButton();
});
//document.getElementById('upload').addEventListener('click', handleFileUpload);
document.getElementById('upload').addEventListener('change', handleFileUpload);
document.getElementById('close-api-warning').addEventListener('click', hideAPISettingsWarning);
document.getElementById('newTable').addEventListener('click', createNewTable);
document.getElementById('markCell').addEventListener('click', markCells);
document.getElementById('unmarkCell').addEventListener('click', unmarkCells);
document.getElementById('clearMarks').addEventListener('click', clearMarks);
document.getElementById('exportExcel').addEventListener('click', exportToExcel);
// 修改事件监听器
document.getElementById('toggleGPT').addEventListener('click', toggleGPT);
document.getElementById('settings').addEventListener('click', openSettings);
document.getElementById('saveSettings').addEventListener('click', saveSettings);
document.getElementById('setColumnWidth').addEventListener('click', setAllColumnWidths);
</script>
</body>
</html>