-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
977 lines (871 loc) · 58.6 KB
/
index.html
File metadata and controls
977 lines (871 loc) · 58.6 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
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>辯論計時器</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#5D5CDE',
affirmative: '#4CAF50',
negative: '#F44336'
}
}
}
}
</script>
</head>
<body class="min-h-screen bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 transition-colors duration-200">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<h1 class="text-3xl font-bold text-center mb-8 text-primary">辯論計時器</h1>
<!-- 設置頁面 -->
<div id="setupPage" class="mb-6">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
<h2 class="text-xl font-bold mb-4">辯論設置</h2>
<div class="mb-4">
<label for="debateTopic" class="block text-sm font-medium mb-1">辯論題目</label>
<input type="text" id="debateTopic" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary dark:bg-gray-700 dark:border-gray-600 text-base" placeholder="請輸入辯論題目...">
</div>
<div class="grid md:grid-cols-2 gap-4 mb-4">
<div>
<label for="affirmativeTeam" class="block text-sm font-medium mb-1">正方隊伍名稱</label>
<input type="text" id="affirmativeTeam" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary dark:bg-gray-700 dark:border-gray-600 text-base" placeholder="正方" value="正方">
</div>
<div>
<label for="negativeTeam" class="block text-sm font-medium mb-1">反方隊伍名稱</label>
<input type="text" id="negativeTeam" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary dark:bg-gray-700 dark:border-gray-600 text-base" placeholder="反方" value="反方">
</div>
</div>
</div>
<div id="standardRoundsSetup" class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
<h2 class="text-xl font-bold mb-4">賽程設置</h2>
<div id="rounds" class="space-y-4 mb-4">
<!-- 賽程項目會動態添加在這裡 -->
</div>
<button id="addRound" class="px-4 py-2 bg-primary text-white rounded-md hover:bg-opacity-90 transition-colors">
添加環節
</button>
</div>
<div class="text-center">
<button id="startDebate" class="px-6 py-3 bg-primary text-white rounded-md hover:bg-opacity-90 transition-colors text-lg font-semibold">
開始辯論
</button>
</div>
</div>
<!-- 計時頁面 -->
<div id="timerPage" class="hidden">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6 text-center">
<h2 id="currentTopic" class="text-xl font-bold mb-4 break-words"></h2>
<!-- Standard Timer Display -->
<div id="standardTimerDisplay">
<div id="currentRoundInfo" class="text-lg font-semibold mb-2"></div>
<div id="currentSpeaker" class="text-3xl font-bold mb-2"></div>
<div class="mb-8">
<div id="timer" class="text-6xl font-bold mb-2">00:00</div>
<div id="progressBar" class="w-full h-4 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
<div id="progress" class="h-full bg-primary transition-all duration-1000" style="width: 100%"></div>
</div>
</div>
</div>
<!-- Free Debate Timer Display -->
<div id="freeDebateTimerDisplay" class="hidden">
<div class="grid grid-cols-2 gap-4 mb-6">
<div>
<h3 id="affirmativeTimerHeader" class="text-xl font-semibold mb-2 text-affirmative">正方</h3>
<div id="affirmativeTimer" class="text-5xl font-bold mb-2">00:00</div>
<div id="affirmativeProgressBar" class="w-full h-4 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
<div id="affirmativeProgress" class="h-full bg-affirmative transition-all duration-1000" style="width: 100%"></div>
</div>
</div>
<div>
<h3 id="negativeTimerHeader" class="text-xl font-semibold mb-2 text-negative">反方</h3>
<div id="negativeTimer" class="text-5xl font-bold mb-2">00:00</div>
<div id="negativeProgressBar" class="w-full h-4 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
<div id="negativeProgress" class="h-full bg-negative transition-all duration-1000" style="width: 100%"></div>
</div>
</div>
</div>
<div id="currentFreeSpeaker" class="text-3xl font-bold mb-2"></div>
</div>
<div class="flex flex-wrap justify-center gap-3">
<button id="startPauseTimer" class="px-4 py-2 bg-primary text-white rounded-md hover:bg-opacity-90 transition-colors font-semibold">
開始
</button>
<button id="resetTimer" class="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-opacity-90 transition-colors font-semibold">
重設
</button>
<!-- The functionality of nextRound button will change in free debate -->
<button id="nextRound" class="px-4 py-2 bg-primary text-white rounded-md hover:bg-opacity-90 transition-colors font-semibold">
下一環節
</button>
<button id="previousRound" class="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-opacity-90 transition-colors font-semibold">
上一環節
</button>
<button id="backToSetup" class="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-opacity-90 transition-colors font-semibold">
返回設置
</button>
</div>
</div>
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<h3 class="text-lg font-semibold mb-2">辯論流程</h3>
<div id="scheduleOverview" class="space-y-2">
<!-- 這裡將顯示完整賽程 -->
</div>
</div>
</div>
</div>
<script>
// 偵測深色模式
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
if (event.matches) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
});
// 初始化賽程數據
let rounds = [
{ name: "正方一辯立論", team: "正方", minutes: 3, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "反方一辯立論", team: "反方", minutes: 3, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "正方二辯質詢", team: "正方", minutes: 2, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "反方二辯質詢", team: "反方", minutes: 2, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "正方三辯小結", team: "正方", minutes: 2, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "反方三辯小結", team: "反方", minutes: 2, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "自由辯論", team: "自由辯論", minutes: 0, seconds: 0, affFreeMinutes: 4, affFreeSeconds: 0, negFreeMinutes: 4, negFreeSeconds: 0 }, // Example Free Debate Round
{ name: "反方四辯總結", team: "反方", minutes: 3, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 },
{ name: "正方四辯總結", team: "正方", minutes: 3, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 }
];
// 計時相關變量
let currentRoundIndex = 0;
let timerInterval = null;
let remainingSeconds = 0; // Used for standard rounds
let totalSeconds = 0; // Used for standard rounds
let isTimerRunning = false;
let alarmSound = new Audio("data:audio/wav;base64,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qJrx4KOQjahZxWbcZgztj2c49nKmkId44S71j0c8eV9yDK6uPRzx5X18eDvjvQ6yKo9ZSS6l//8elePK/Lf//IInrOF/FvDoADYAGBMGb7FtErm5MXMlmPAJQVgWta7Zx2go+8xJ0UiCb8LHHdftWyLJE0QIAIsI+UbXu67dZMjmgDGCGl1H+vpF4NSDckSIkk7Vd+sxEhBQMRU8j/12UIRhzSaUdQ+rQU5kGeFxm+hb1oh6pWWmv3uvmReDl0UnvtapVaIzo1jZbf/pD6ElLqSX+rUmOQNpJFa/r+sa4e/pBlAABoAAAAA3CUgShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=");
// 新增自由辯論計時相關變量
let affirmativeFreeSecondsTotal = 0; // Total free debate time for affirmative
let negativeFreeSecondsTotal = 0; // Total free debate time for negative
let remainingAffirmativeSeconds = 0;
let remainingNegativeSeconds = 0;
let activeFreeTimer = 'affirmative'; // 'affirmative' or 'negative'
// 頁面加載時
document.addEventListener('DOMContentLoaded', function() {
updateRoundsDisplay();
// 添加新環節按鈕事件
document.getElementById('addRound').addEventListener('click', function() {
// Add new round with default standard values
rounds.push({ name: "", team: "正方", minutes: 2, seconds: 0, affFreeMinutes: 0, affFreeSeconds: 0, negFreeMinutes: 0, negFreeSeconds: 0 });
updateRoundsDisplay();
});
// 開始辯論按鈕事件
document.getElementById('startDebate').addEventListener('click', function() {
const topic = document.getElementById('debateTopic').value.trim();
if (!topic) {
alert('請輸入辯論題目!');
return;
}
if (rounds.length === 0) {
alert('請添加至少一個辯論環節!');
return;
}
// Basic validation for round names
for (let i = 0; i < rounds.length; i++) {
if (!rounds[i].name.trim()) {
alert(`第 ${i + 1} 個環節缺少名稱,請填寫完整!`);
return;
}
// Validation for free debate times if round type is free debate
if (rounds[i].team === '自由辯論') {
const affMinutes = rounds[i].affFreeMinutes;
const affSeconds = rounds[i].affFreeSeconds;
const negMinutes = rounds[i].negFreeMinutes;
const negSeconds = rounds[i].negFreeSeconds;
if ((affMinutes * 60 + affSeconds <= 0) || (negMinutes * 60 + negSeconds <= 0)) {
alert(`第 ${i + 1} 個自由辯論環節需要設置有效的正反方時間!`);
return;
}
}
}
// 切換到計時頁面
document.getElementById('setupPage').classList.add('hidden');
document.getElementById('timerPage').classList.remove('hidden');
// Scroll to top
window.scrollTo(0, 0);
// 顯示辯論題目
document.getElementById('currentTopic').textContent = topic;
currentRoundIndex = 0; // Start from the first round
startNextRound(); // Start the first round
});
// 計時器控制按鈕事件
document.getElementById('startPauseTimer').addEventListener('click', toggleTimer);
document.getElementById('resetTimer').addEventListener('click', resetTimer);
// nextRound button listener - now simply moves to the next round
document.getElementById('nextRound').addEventListener('click', function() {
stopTimer();
if (currentRoundIndex < rounds.length - 1) {
currentRoundIndex++;
startNextRound();
} else {
alert('辯論已結束!');
// Optionally return to setup or show a 'Debate Finished' message
document.getElementById('timerPage').classList.add('hidden');
document.getElementById('setupPage').classList.remove('hidden');
}
});
document.getElementById('backToSetup').addEventListener('click', function() {
stopTimer();
document.getElementById('timerPage').classList.add('hidden');
document.getElementById('setupPage').classList.remove('hidden');
});
// Add spacebar event listener for free debate mode within a round
document.addEventListener('keydown', function(event) {
if (event.code === 'Space' && !event.repeat && isTimerRunning) {
const currentRound = rounds[currentRoundIndex];
if (currentRound && currentRound.team === '自由辯論') {
event.preventDefault(); // Prevent scrolling
switchFreeTimer();
}
}
// Add 'S' key listener for free debate switching
if (event.code === 'KeyS' && !event.repeat) {
const currentRound = rounds[currentRoundIndex];
if (currentRound && currentRound.team === '自由辯論') {
event.preventDefault(); // Prevent scrolling
switchFreeTimer();
}
}
});
// 上一環節按鈕事件
document.getElementById('previousRound').addEventListener('click', function() {
stopTimer(); // Stop the current timer
if (currentRoundIndex > 0) {
currentRoundIndex--; // Go to the previous round index
startNextRound(); // Start the previous round
} else {
alert('已是第一個環節!'); // Alert if already at the first round
}
});
});
// Add this function to handle drag and drop for rounds
function setupDragAndDrop() {
const roundsContainer = document.getElementById('rounds');
let draggedItem = null;
// Add event listeners for drag and drop
roundsContainer.addEventListener('dragstart', function(e) {
if (e.target.closest('.round-item')) {
draggedItem = e.target.closest('.round-item');
e.dataTransfer.setData('text/plain', draggedItem.dataset.index);
setTimeout(() => {
draggedItem.style.opacity = '0.5';
}, 0);
}
});
roundsContainer.addEventListener('dragend', function() {
if (draggedItem) {
draggedItem.style.opacity = '1';
draggedItem = null;
}
});
roundsContainer.addEventListener('dragover', function(e) {
e.preventDefault();
const afterElement = getDragAfterElement(roundsContainer, e.clientY);
if (afterElement) {
roundsContainer.insertBefore(draggedItem, afterElement);
} else {
roundsContainer.appendChild(draggedItem);
}
});
roundsContainer.addEventListener('drop', function(e) {
e.preventDefault();
if (draggedItem) {
const fromIndex = parseInt(e.dataTransfer.getData('text/plain'));
const toIndex = Array.from(roundsContainer.children).indexOf(draggedItem);
if (fromIndex !== toIndex) {
const [movedRound] = rounds.splice(fromIndex, 1);
rounds.splice(toIndex, 0, movedRound);
updateRoundsDisplay();
}
}
});
// Helper function to determine where to place the dragged item
function getDragAfterElement(container, y) {
const draggableElements = [...container.querySelectorAll('.round-item:not(.dragging)')];
return draggableElements.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) {
return { offset: offset, element: child };
} else {
return closest;
}
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
}
// Modify the updateRoundsDisplay function to add draggable attributes
function updateRoundsDisplay() {
const roundsContainer = document.getElementById('rounds');
roundsContainer.innerHTML = '';
rounds.forEach((round, index) => {
const roundElement = document.createElement('div');
roundElement.className = 'p-4 border rounded-md dark:border-gray-700 relative round-item';
roundElement.draggable = true;
roundElement.dataset.index = index;
// Base HTML structure for standard round
let roundHtml = `
<div class="absolute top-2 right-2">
<button class="delete-round text-red-500 hover:text-red-700" data-index="${index}">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div class="grid grid-cols-1 md:grid-cols-4 gap-3">
<div class="md:col-span-2">
<label class="block text-sm font-medium mb-1">環節名稱</label>
<input type="text" class="round-name w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary dark:bg-gray-700 dark:border-gray-600 text-base"
value="${round.name}" placeholder="例如:正方一辯立論" data-index="${index}">
</div>
<div>
<label class="block text-sm font-medium mb-1">方向</label>
<select class="round-team w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary dark:bg-gray-700 dark:border-gray-600 text-base" data-index="${index}">
<option value="正方" ${round.team === '正方' ? 'selected' : ''}>正方</option>
<option value="反方" ${round.team === '反方' ? 'selected' : ''}>反方</option>
<option value="自由辯論" ${round.team === '自由辯論' ? 'selected' : ''}>自由辯論</option>
<option value="無時間環節" ${round.team === '無時間環節' ? 'selected' : ''}>無時間環節</option>
</select>
</div>
`;
// Conditional time inputs based on round type
if (round.team !== '自由辯論' && round.team !== '無時間環節') {
roundHtml += `
<div>
<label class="block text-sm font-medium mb-1">時間</label>
<div class="p-0.5 bg-gradient-to-r from-gray-700 to-gray-700 rounded-md">
<div class="flex bg-white dark:bg-gray-800 rounded-md overflow-hidden">
<input type="number" class="round-minutes w-full px-3 py-1 focus:outline-none text-base dark:text-gray-200 dark:bg-gray-800"
value="${round.minutes}" min="0" max="59" data-index="${index}">
<span class="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-base flex items-center justify-center text-gray-700 dark:text-gray-300">分</span>
<input type="number" class="round-seconds w-full px-3 py-1 focus:outline-none text-base dark:text-gray-200 dark:bg-gray-800"
value="${round.seconds}" min="0" max="59" data-index="${index}">
<span class="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-base flex items-center justify-center text-gray-700 dark:text-gray-300 rounded-r-md">秒</span>
</div>
</div>
</div>
`;
} else if (round.team === '自由辯論') {
roundHtml += `
<div class="md:col-span-3 grid md:grid-cols-2 gap-3">
<div>
<label class="block text-sm font-medium mb-1">正方時間</label>
<div class="p-0.5 bg-gradient-to-r from-gray-700 to-gray-700 rounded-md">
<div class="flex bg-white dark:bg-gray-800 rounded-md overflow-hidden">
<input type="number" class="round-aff-free-minutes w-full px-3 py-1 focus:outline-none text-base dark:text-gray-200 dark:bg-gray-800"
value="${round.affFreeMinutes}" min="0" max="59" data-index="${index}">
<span class="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-base flex items-center justify-center text-gray-700 dark:text-gray-300">分</span>
<input type="number" class="round-aff-free-seconds w-full px-3 py-1 focus:outline-none text-base dark:text-gray-200 dark:bg-gray-800"
value="${round.affFreeSeconds}" min="0" max="59" data-index="${index}">
<span class="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-base flex items-center justify-center text-gray-700 dark:text-gray-300 rounded-r-md">秒</span>
</div>
</div>
</div>
<div>
<label class="block text-sm font-medium mb-1">反方時間</label>
<div class="p-0.5 bg-gradient-to-r from-gray-700 to-gray-700 rounded-md">
<div class="flex bg-white dark:bg-gray-800 rounded-md overflow-hidden">
<input type="number" class="round-neg-free-minutes w-full px-3 py-1 focus:outline-none text-base dark:text-gray-200 dark:bg-gray-800"
value="${round.negFreeMinutes}" min="0" max="59" data-index="${index}">
<span class="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-base flex items-center justify-center text-gray-700 dark:text-gray-300">分</span>
<input type="number" class="round-neg-free-seconds w-full px-3 py-1 focus:outline-none text-base dark:text-gray-200 dark:bg-gray-800"
value="${round.negFreeSeconds}" min="0" max="59" data-index="${index}">
<span class="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-base flex items-center justify-center text-gray-700 dark:text-gray-300 rounded-r-md">秒</span>
</div>
</div>
</div>
</div>
`;
}
roundHtml += `</div>`; // Close the grid div
roundElement.innerHTML = roundHtml;
roundsContainer.appendChild(roundElement);
});
// Add event listeners for dynamically created elements
document.querySelectorAll('.round-name').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].name = this.value;
// Auto-detect direction based on keywords
if (this.value.includes('正方')) {
rounds[index].team = '正方';
document.querySelector(`.round-team[data-index="${index}"]`).value = '正方';
} else if (this.value.includes('反方')) {
rounds[index].team = '反方';
document.querySelector(`.round-team[data-index="${index}"]`).value = '反方';
}
});
});
document.querySelectorAll('.round-team').forEach(select => {
select.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].team = this.value;
// Re-render rounds display to show/hide appropriate time inputs
updateRoundsDisplay();
});
});
document.querySelectorAll('.round-minutes').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].minutes = parseInt(this.value) || 0;
});
});
document.querySelectorAll('.round-seconds').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].seconds = parseInt(this.value) || 0;
});
});
// Add listeners for new free debate time inputs
document.querySelectorAll('.round-aff-free-minutes').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].affFreeMinutes = parseInt(this.value) || 0;
});
});
document.querySelectorAll('.round-aff-free-seconds').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].affFreeSeconds = parseInt(this.value) || 0;
});
});
document.querySelectorAll('.round-neg-free-minutes').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].negFreeMinutes = parseInt(this.value) || 0;
});
});
document.querySelectorAll('.round-neg-free-seconds').forEach(input => {
input.addEventListener('change', function() {
const index = parseInt(this.dataset.index);
rounds[index].negFreeSeconds = parseInt(this.value) || 0;
});
});
document.querySelectorAll('.delete-round').forEach(button => {
button.addEventListener('click', function() {
const index = parseInt(this.dataset.index);
if (rounds.length > 1) {
rounds.splice(index, 1);
updateRoundsDisplay();
} else {
alert('至少需要保留一個環節!');
}
});
});
// Initialize drag and drop
setupDragAndDrop();
}
// Update schedule overview display (remains largely the same)
function updateScheduleOverview() {
const scheduleOverview = document.getElementById('scheduleOverview');
scheduleOverview.innerHTML = '';
rounds.forEach((round, index) => {
const item = document.createElement('div');
// Apply highlighting and padding to the outer item div
item.className = `p-2 ${index === currentRoundIndex ? 'bg-primary bg-opacity-20 font-bold rounded' : ''}`;
let timeDisplay = '';
let teamColor = '';
if (round.team === '自由辯論') {
// Display total free debate time for overview
const affMinutes = round.affFreeMinutes.toString().padStart(2, '0');
const affSeconds = round.affFreeSeconds.toString().padStart(2, '0');
const negMinutes = round.negFreeMinutes.toString().padStart(2, '0');
const negSeconds = round.negFreeSeconds.toString().padStart(2, '0');
timeDisplay = `正 ${affMinutes}:${affSeconds} / 反 ${negMinutes}:${negSeconds}`;
teamColor = 'primary'; // Neutral color for overview
} else if (round.team === '無時間環節') {
timeDisplay = '無時間';
teamColor = 'gray-500'; // Neutral color for no-time rounds
}
else {
// Standard round time display
const minutes = round.minutes.toString().padStart(2, '0');
const seconds = round.seconds.toString().padStart(2, '0');
timeDisplay = `${minutes}:${seconds}`;
teamColor = round.team === '正方' ? 'affirmative' : 'negative';
}
// Use Flexbox for internal layout
item.innerHTML = `
<div class="flex justify-between items-center">
<div class="flex items-center">
<span class="inline-block w-4 h-4 rounded-full bg-${teamColor} mr-2"></span> <!-- Reduced size slightly for better fit -->
<span>${round.name}</span>
</div>
<span>${timeDisplay}</span>
</div>
`;
scheduleOverview.appendChild(item);
});
}
// Start the current round based on its type
function startNextRound() {
if (currentRoundIndex >= rounds.length) {
alert('辯論已結束!');
// Optionally return to setup or show a 'Debate Finished' message
document.getElementById('timerPage').classList.add('hidden');
document.getElementById('setupPage').classList.remove('hidden');
return;
}
const currentRound = rounds[currentRoundIndex];
document.getElementById('currentRoundInfo').textContent = `第 ${currentRoundIndex + 1} 環節:${currentRound.name}`;
document.getElementById('currentSpeaker').textContent = ''; // Clear standard speaker display initially
document.getElementById('currentFreeSpeaker').textContent = ''; // Clear free speaker display initially
// Ensure timer display is reset
document.getElementById('timer').textContent = '00:00';
document.getElementById('affirmativeTimer').textContent = '00:00';
document.getElementById('negativeTimer').textContent = '00:00';
// Update schedule overview to highlight current round
updateScheduleOverview();
if (currentRound.team === '自由辯論') {
// Switch to Free Debate Display
document.getElementById('standardTimerDisplay').classList.add('hidden');
document.getElementById('freeDebateTimerDisplay').classList.remove('hidden');
document.getElementById('scheduleOverview').parentElement.classList.remove('hidden'); // Schedule overview remains visible
// Ensure timer buttons are visible
document.getElementById('startPauseTimer').classList.remove('hidden');
document.getElementById('resetTimer').classList.remove('hidden');
// Initialize Free Debate Timers
affirmativeFreeSecondsTotal = currentRound.affFreeMinutes * 60 + currentRound.affFreeSeconds;
negativeFreeSecondsTotal = currentRound.negFreeMinutes * 60 + currentRound.negFreeSeconds;
remainingAffirmativeSeconds = affirmativeFreeSecondsTotal;
remainingNegativeSeconds = negativeFreeSecondsTotal;
activeFreeTimer = 'affirmative'; // Default to affirmative starts free debate
updateFreeTimerDisplay();
updateFreeSpeakerDisplay(); // Show initial speaker
} else if (currentRound.team === '無時間環節') {
// Hide both timer displays
document.getElementById('standardTimerDisplay').classList.add('hidden');
document.getElementById('freeDebateTimerDisplay').classList.add('hidden');
document.getElementById('scheduleOverview').parentElement.classList.remove('hidden'); // Schedule overview remains visible
// Optionally hide timer buttons
document.getElementById('startPauseTimer').classList.add('hidden');
document.getElementById('resetTimer').classList.add('hidden');
// Display round info without timer
document.getElementById('currentSpeaker').textContent = currentRound.name;
document.getElementById('currentSpeaker').className = 'text-3xl font-bold mb-2'; // Reset color
} else {
// Switch to Standard Timer Display
document.getElementById('standardTimerDisplay').classList.remove('hidden');
document.getElementById('freeDebateTimerDisplay').classList.add('hidden');
document.getElementById('scheduleOverview').parentElement.classList.remove('hidden'); // Schedule overview remains visible
// Ensure timer buttons are visible
document.getElementById('startPauseTimer').classList.remove('hidden');
document.getElementById('resetTimer').classList.remove('hidden');
// Initialize Standard Timer
totalSeconds = currentRound.minutes * 60 + currentRound.seconds;
remainingSeconds = totalSeconds;
// Set initial speaker for standard round
const teamName = currentRound.team === '正方' ?
document.getElementById('affirmativeTeam').value :
document.getElementById('negativeTeam').value;
const teamColor = currentRound.team === '正方' ? 'affirmative' : 'negative';
const speaker = document.getElementById('currentSpeaker');
speaker.textContent = teamName;
speaker.className = `text-3xl font-bold mb-2 text-${teamColor}`;
updateStandardTimerDisplay();
}
// Reset timer state to paused
isTimerRunning = false;
// Update button text only if it's a timed round
if (currentRound.team !== '無時間環節') {
document.getElementById('startPauseTimer').textContent = '開始';
}
}
// Update timer display (Handles both modes internally)
function updateTimerDisplay() {
const currentRound = rounds[currentRoundIndex];
if (!currentRound) return; // Should not happen if called correctly
if (currentRound.team === '自由辯論') {
updateFreeTimerDisplay();
} else {
updateStandardTimerDisplay();
}
}
// Update standard timer display
function updateStandardTimerDisplay() {
const minutes = Math.floor(remainingSeconds / 60);
const seconds = remainingSeconds % 60;
document.getElementById('timer').textContent =
`${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Update progress bar
const progress = document.getElementById('progress');
const progressPercent = (remainingSeconds / totalSeconds) * 100;
progress.style.width = `${progressPercent}%`;
const teamColor = rounds[currentRoundIndex].team === '正方' ? 'affirmative' : 'negative';
progress.className = `h-full bg-${teamColor} transition-all duration-1000`; // Update color based on team
// Time warning color change
const timerElement = document.getElementById('timer');
timerElement.className = 'text-6xl font-bold mb-2'; // Reset color
if (remainingSeconds <= 30 && remainingSeconds > 10) {
timerElement.classList.add('text-yellow-500');
} else if (remainingSeconds <= 10) {
timerElement.classList.add('text-red-500');
}
}
// Update free debate timer display
function updateFreeTimerDisplay() {
const affMinutes = Math.floor(remainingAffirmativeSeconds / 60);
const affSeconds = remainingAffirmativeSeconds % 60;
document.getElementById('affirmativeTimer').textContent =
`${affMinutes.toString().padStart(2, '0')}:${affSeconds.toString().padStart(2, '0')}`;
const negMinutes = Math.floor(remainingNegativeSeconds / 60);
const negSeconds = remainingNegativeSeconds % 60;
document.getElementById('negativeTimer').textContent =
`${negMinutes.toString().padStart(2, '0')}:${negSeconds.toString().padStart(2, '0')}`;
// Update progress bar (Free Debate)
const affProgressPercent = (remainingAffirmativeSeconds / affirmativeFreeSecondsTotal) * 100;
document.getElementById('affirmativeProgress').style.width = `${affProgressPercent}%`;
document.getElementById('affirmativeProgress').className = `h-full bg-affirmative transition-all duration-1000`;
const negProgressPercent = (remainingNegativeSeconds / negativeFreeSecondsTotal) * 100;
document.getElementById('negativeProgress').style.width = `${negProgressPercent}%`;
document.getElementById('negativeProgress').className = `h-full bg-negative transition-all duration-1000`;
// Time warning color change (Free Debate)
const affTimerElement = document.getElementById('affirmativeTimer');
const negTimerElement = document.getElementById('negativeTimer');
// Reset colors first
affTimerElement.className = 'text-5xl font-bold mb-2';
negTimerElement.className = 'text-5xl font-bold mb-2';
if (activeFreeTimer === 'affirmative') {
if (remainingAffirmativeSeconds <= 30 && remainingAffirmativeSeconds > 10) {
affTimerElement.classList.add('text-yellow-500');
} else if (remainingAffirmativeSeconds <= 10) {
affTimerElement.classList.add('text-red-500');
}
// Highlight active timer display (optional - could add a class to a parent div)
document.getElementById('affirmativeTimerHeader').classList.add('underline');
document.getElementById('negativeTimerHeader').classList.remove('underline');
} else { // activeFreeTimer === 'negative'
if (remainingNegativeSeconds <= 30 && remainingNegativeSeconds > 10) {
negTimerElement.classList.add('text-yellow-500');
} else if (remainingNegativeSeconds <= 10) {
negTimerElement.classList.add('text-red-500');
}
// Highlight active timer display (optional)
document.getElementById('negativeTimerHeader').classList.add('underline');
document.getElementById('affirmativeTimerHeader').classList.remove('underline');
}
}
// Update free debate speaker display
function updateFreeSpeakerDisplay() {
const speakerElement = document.getElementById('currentFreeSpeaker');
if (activeFreeTimer === 'affirmative') {
speakerElement.textContent = document.getElementById('affirmativeTeam').value;
speakerElement.className = 'text-3xl font-bold mb-2 text-affirmative';
} else { // activeFreeTimer === 'negative'
speakerElement.textContent = document.getElementById('negativeTeam').value;
speakerElement.className = 'text-3xl font-bold mb-2 text-negative';
}
// Hide standard speaker display
document.getElementById('currentSpeaker').textContent = '';
}
// Start/Pause timer (Handles both modes internally)
function toggleTimer() {
const currentRound = rounds[currentRoundIndex];
if (currentRound.team === '無時間環節') {
return; // Do nothing if it's a no-time round
}
if (isTimerRunning) {
stopTimer();
document.getElementById('startPauseTimer').textContent = '開始';
} else {
// Prevent starting if times are zero, especially for free debate
if (currentRound.team === '自由辯論' && remainingAffirmativeSeconds <= 0 && remainingNegativeSeconds <= 0) {
alert('自由辯論時間已用盡!');
return;
}
if (currentRound.team !== '自由辯論' && remainingSeconds <= 0) {
alert('該環節時間已結束!');
return;
}
startTimer();
document.getElementById('startPauseTimer').textContent = '暫停';
}
isTimerRunning = !isTimerRunning;
}
// Start timer interval
function startTimer() {
if (timerInterval) clearInterval(timerInterval);
timerInterval = setInterval(function() {
const currentRound = rounds[currentRoundIndex];
if (currentRound.team === '自由辯論') {
if (activeFreeTimer === 'affirmative') {
if (remainingAffirmativeSeconds > 0) {
remainingAffirmativeSeconds--;
updateFreeTimerDisplay();
// 時間警告音效
if (remainingAffirmativeSeconds === 30 || remainingAffirmativeSeconds === 10 || remainingAffirmativeSeconds === 0) {
alarmSound.play();
}
if (remainingAffirmativeSeconds === 0 && remainingNegativeSeconds === 0) {
// Both timers finished
stopTimer();
alarmSound.play(); // Final alert
document.getElementById('startPauseTimer').textContent = '開始';
isTimerRunning = false;
document.getElementById('currentFreeSpeaker').textContent = '辯論結束'; // Indicate end
} else if (remainingAffirmativeSeconds === 0) {
// Affirmative time is out, but negative still has time
// Auto-switch to negative when affirmative time runs out
switchFreeTimer();
// Keep timer running if it was running
if (isTimerRunning) {
startTimer();
}
}
}
} else { // activeFreeTimer === 'negative'
if (remainingNegativeSeconds > 0) {
remainingNegativeSeconds--;
updateFreeTimerDisplay();
// 時間警告音效
if (remainingNegativeSeconds === 30 || remainingNegativeSeconds === 10 || remainingNegativeSeconds === 0) {
alarmSound.play();
}
if (remainingNegativeSeconds === 0 && remainingAffirmativeSeconds === 0) {
// Both timers finished
stopTimer();
alarmSound.play(); // Final alert
document.getElementById('startPauseTimer').textContent = '開始';
isTimerRunning = false;
document.getElementById('currentFreeSpeaker').textContent = '辯論結束'; // Indicate end
} else if (remainingNegativeSeconds === 0) {
// Negative time is out, but affirmative still has time
// Auto-switch to affirmative when negative time runs out
switchFreeTimer();
// Keep timer running if it was running
if (isTimerRunning) {
startTimer();
}
}
}
}
} else { // standard mode
if (remainingSeconds > 0) {
remainingSeconds--;
updateStandardTimerDisplay();
// 時間警告音效
if (remainingSeconds === 30 || remainingSeconds === 10 || remainingSeconds === 0) {
alarmSound.play();
}
} else {
stopTimer();
alarmSound.play();
document.getElementById('startPauseTimer').textContent = '開始';
isTimerRunning = false;
// Optionally advance to the next round automatically
// document.getElementById('nextRound').click();
}
}
}, 1000);
}
// Stop timer interval
function stopTimer() {
if (timerInterval) {
clearInterval(timerInterval);
timerInterval = null;
}
}
// Reset timer (Resets based on current round type)
function resetTimer() {
stopTimer();
isTimerRunning = false;
document.getElementById('startPauseTimer').textContent = '開始';
const currentRound = rounds[currentRoundIndex];
if (currentRound.team === '無時間環節') {
// No timer to reset for no-time rounds
// Ensure timer displays are hidden
document.getElementById('standardTimerDisplay').classList.add('hidden');
document.getElementById('freeDebateTimerDisplay').classList.add('hidden');
// Ensure timer buttons are hidden
document.getElementById('startPauseTimer').classList.add('hidden');
document.getElementById('resetTimer').classList.add('hidden');
// Update speaker display for no-time round
document.getElementById('currentSpeaker').textContent = currentRound.name;
document.getElementById('currentSpeaker').className = 'text-3xl font-bold mb-2'; // Reset color
document.getElementById('currentFreeSpeaker').textContent = ''; // Clear free speaker display
return; // Exit the function
}
if (currentRound.team === '自由辯論') {
affirmativeFreeSecondsTotal = currentRound.affFreeMinutes * 60 + currentRound.affFreeSeconds;
negativeFreeSecondsTotal = currentRound.negFreeMinutes * 60 + currentRound.negFreeSeconds;
remainingAffirmativeSeconds = affirmativeFreeSecondsTotal;
remainingNegativeSeconds = negativeFreeSecondsTotal;
activeFreeTimer = 'affirmative'; // Reset active timer to affirmative
updateFreeTimerDisplay();
updateFreeSpeakerDisplay(); // Update speaker display
// Reset any end-of-debate messages
document.getElementById('currentFreeSpeaker').textContent = document.getElementById('affirmativeTeam').value; // Show initial speaker
// Ensure correct timer display is shown after reset
document.getElementById('standardTimerDisplay').classList.add('hidden');
document.getElementById('freeDebateTimerDisplay').classList.remove('hidden');
// Ensure timer buttons are visible
document.getElementById('startPauseTimer').classList.remove('hidden');
document.getElementById('resetTimer').classList.remove('hidden');
} else { // standard mode
totalSeconds = currentRound.minutes * 60 + currentRound.seconds;
remainingSeconds = totalSeconds;
updateStandardTimerDisplay();
// Reset progress bar width in standard mode
const progress = document.getElementById('progress');
progress.style.width = '100%';
const teamColor = currentRound.team === '正方' ? 'affirmative' : 'negative';
progress.className = `h-full bg-${teamColor} transition-all duration-1000`;
// Restore standard speaker display
const teamName = currentRound.team === '正方' ?
document.getElementById('affirmativeTeam').value :
document.getElementById('negativeTeam').value;
const teamColorSpeaker = currentRound.team === '正方' ? 'affirmative' : 'negative';
const speaker = document.getElementById('currentSpeaker');
speaker.textContent = teamName;
speaker.className = `text-3xl font-bold mb-2 text-${teamColorSpeaker}`;
// Ensure correct timer display is shown after reset
document.getElementById('standardTimerDisplay').classList.remove('hidden');
document.getElementById('freeDebateTimerDisplay').classList.add('hidden');
// Ensure timer buttons are visible
document.getElementById('startPauseTimer').classList.remove('hidden');
document.getElementById('resetTimer').classList.remove('hidden');
}
updateScheduleOverview(); // Update schedule overview highlight
}
// Switch free debate timer
function switchFreeTimer() {
const currentRound = rounds[currentRoundIndex];
if (!currentRound || currentRound.team !== '自由辯論') return; // Only switch in free debate
if (activeFreeTimer === 'affirmative') {
if (remainingNegativeSeconds > 0) { // Only switch if the other team has time left
activeFreeTimer = 'negative';
} else {
// If negative has no time, don't switch but show message
document.getElementById('currentFreeSpeaker').textContent = '反方時間用盡';
return;
}
} else { // activeFreeTimer === 'negative'
if (remainingAffirmativeSeconds > 0) { // Only switch if the other team has time left
activeFreeTimer = 'affirmative';
} else {
// If affirmative has no time, don't switch but show message
document.getElementById('currentFreeSpeaker').textContent = '正方時間用盡';
return;
}
}
updateFreeSpeakerDisplay();
}
</script>
</body>
</html>