Skip to content

Commit e6f751f

Browse files
authored
Update test.html
1 parent 766db2e commit e6f751f

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

test.html

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
background-color: white;
140140
}
141141

142+
142143
/* 輸入與顯示區塊 */
143144
.text-output-area,
144145
.candidate-area,
@@ -438,11 +439,11 @@ <h2>輸入法模式:</h2>
438439

439440
for (const line of lines) {
440441
const trimmedLine = line.trim();
441-
if (trimmedLine === '%chardef begin') {
442+
if (trimmedLine.includes('[data]') || trimmedLine.includes('%chardef begin')) {
442443
inDataSection = true;
443444
continue;
444445
}
445-
if (trimmedLine === '%chardef end') {
446+
if (trimmedLine.includes('%chardef end')) {
446447
inDataSection = false;
447448
break;
448449
}
@@ -472,12 +473,12 @@ <h2>輸入法模式:</h2>
472473
console.log("編碼資料解析完成。");
473474
resetInputState();
474475
}
475-
476+
476477
function loadCinFile(filename) {
477478
fetch(filename)
478479
.then(response => {
479480
if (!response.ok) {
480-
throw new Error('載入編碼檔失敗,請檢查檔案路徑。');
481+
throw new Error(`載入編碼檔失敗,請檢查檔案路徑。`);
481482
}
482483
return response.text();
483484
})
@@ -528,18 +529,21 @@ <h2>輸入法模式:</h2>
528529
});
529530
}
530531

532+
function switchInputMethod(methodName) {
533+
if (methodName === 'primary') {
534+
loadCinFile('3code.cin');
535+
} else if (methodName === 'secondary') {
536+
loadCinFile('3code2.txt');
537+
}
538+
updateModeDisplay();
539+
}
540+
531541
// --- 事件處理 ---
532542

533543
// 模式切換事件監聽
534544
modeRadios.forEach(radio => {
535545
radio.addEventListener('change', (event) => {
536-
const mode = event.target.value;
537-
if (mode === 'primary') {
538-
loadCinFile('3code.cin'); // 這裡可以根據需要調整成不同的檔案
539-
} else {
540-
loadCinFile('3code2.cin'); // 例如次常用字檔案
541-
}
542-
updateModeDisplay();
546+
switchInputMethod(event.target.value);
543547
});
544548
});
545549

@@ -680,8 +684,7 @@ <h2>輸入法模式:</h2>
680684
});
681685

682686
// 頁面載入時先初始化顯示
683-
loadCinFile('3code.cin'); // 載入預設的檔案
687+
switchInputMethod('primary');
684688
updateKeyboardDisplay();
685-
updateModeDisplay();
686689
</script>
687-
</body></html>
690+
</body></html>

0 commit comments

Comments
 (0)