Skip to content

Commit e0b684f

Browse files
authored
Update test.html
1 parent e3e734a commit e0b684f

1 file changed

Lines changed: 38 additions & 13 deletions

File tree

test.html

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
font-weight: bold;
311311
border: 1px dashed var(--border-color);
312312
border-radius: 4px;
313-
color: transparent;
313+
color: var(--text-color);
314314
background-color: transparent;
315315
transition: all 0.3s ease-in-out;
316316
}
@@ -553,6 +553,7 @@ <h2>查碼練習</h2>
553553
const keyboardContainer = document.querySelector('.keyboard-container');
554554
const modeDisplay = document.getElementById('mode-display');
555555
const modeRadioButtons = document.querySelectorAll('input[name="input_mode"]');
556+
const candidateDisplay = document.getElementById('candidate-display');
556557

557558
const MAX_CODE_LENGTH = 3;
558559
const SHIFT_HOLD_THRESHOLD = 300; // 300毫秒
@@ -678,6 +679,7 @@ <h2>查碼練習</h2>
678679
if (currentCode.length > 0) {
679680
currentCode = currentCode.slice(0, -1);
680681
mainInput.value = formatCode(currentCode);
682+
updateCandidates();
681683
}
682684
return;
683685
} else if (code === 'enter') {
@@ -691,20 +693,38 @@ <h2>查碼練習</h2>
691693
// 處理編碼輸入
692694
const inputChar = code.toLowerCase();
693695
if (inputChar.match(/^[a-z;'./,0-9]$/)) {
694-
currentCode += inputChar;
695-
mainInput.value = formatCode(currentCode);
696-
697-
// 當輸入達到最大長度時自動檢查
698-
if (currentCode.length === MAX_CODE_LENGTH) {
699-
checkAndFillPracticeChar();
696+
if (currentCode.length < MAX_CODE_LENGTH) {
697+
currentCode += inputChar;
698+
mainInput.value = formatCode(currentCode);
699+
updateCandidates();
700+
701+
// 當輸入達到最大長度時自動檢查
702+
if (currentCode.length === MAX_CODE_LENGTH) {
703+
checkAndFillPracticeChar();
704+
}
700705
}
701706
}
702707
});
708+
709+
function updateCandidates() {
710+
candidateDisplay.innerHTML = '';
711+
const candidates = currentCodemap[currentCode] || [];
712+
if (candidates.length > 0) {
713+
candidates.forEach(char => {
714+
const span = document.createElement('span');
715+
span.textContent = char;
716+
candidateDisplay.appendChild(span);
717+
});
718+
} else {
719+
const span = document.createElement('span');
720+
span.textContent = '查無編碼';
721+
candidateDisplay.appendChild(span);
722+
}
723+
}
703724

704725
// 檢查並填入練習區的字
705726
function checkAndFillPracticeChar() {
706727
if (completedCharsCount >= practiceChars.length) {
707-
// 練習已完成,重設狀態
708728
resetInputState();
709729
return;
710730
}
@@ -719,19 +739,20 @@ <h2>查碼練習</h2>
719739

720740
if (isCorrect) {
721741
const charBox = practiceDisplayArea.children[completedCharsCount];
722-
charBox.textContent = targetChar;
723742
charBox.classList.add('filled');
724743
completedCharsCount++;
725744
}
726745

727746
// 無論正確與否,都清空輸入碼
728747
resetInputState();
748+
updateCandidates();
729749
}
730750

731751
// --- 清空所有輸入狀態 ---
732752
function resetInputState() {
733753
currentCode = '';
734754
mainInput.value = '';
755+
candidateDisplay.innerHTML = '';
735756
}
736757

737758
// --- 格式化編碼顯示 ---
@@ -823,6 +844,7 @@ <h2>查碼練習</h2>
823844
currentCode = currentCode.slice(0, -1);
824845
}
825846
mainInput.value = formatCode(currentCode);
847+
updateCandidates();
826848
return;
827849
}
828850

@@ -837,10 +859,13 @@ <h2>查碼練習</h2>
837859
if (code === 'enter') {
838860
checkAndFillPracticeChar();
839861
} else {
840-
currentCode += code.toLowerCase();
841-
mainInput.value = formatCode(currentCode);
842-
if (currentCode.length === MAX_CODE_LENGTH) {
843-
checkAndFillPracticeChar();
862+
if (currentCode.length < MAX_CODE_LENGTH) {
863+
currentCode += code.toLowerCase();
864+
mainInput.value = formatCode(currentCode);
865+
updateCandidates();
866+
if (currentCode.length === MAX_CODE_LENGTH) {
867+
checkAndFillPracticeChar();
868+
}
844869
}
845870
}
846871
}

0 commit comments

Comments
 (0)