Skip to content

Commit b20d142

Browse files
authored
Add files via upload
1 parent 22a6d83 commit b20d142

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

3code_mobile.html

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
align-items: center;
4040
background-color: var(--background-color);
4141
min-height: 100vh;
42-
padding-bottom: 250px; /* 為鍵盤預留空間 */
42+
/* 調整 padding-bottom 以容納多一行的數字鍵 */
43+
padding-bottom: 280px;
4344
}
4445

4546
/* ------------------ 頂部區域 ------------------ */
@@ -230,8 +231,7 @@
230231
<div id="main-input">編碼顯示在此</div>
231232
<div id="candidate-display">候選字顯示在此...</div>
232233
</div>
233-
234-
</div>
234+
</div>
235235

236236
<div class="keyboard-container" id="keyboard-container">
237237
</div>
@@ -247,26 +247,30 @@
247247
'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N',
248248
'o': 'O', 'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U',
249249
'v': 'V', 'w': 'W', 'x': 'X', 'y': 'Y', 'z': 'Z',
250-
// 符號對應
250+
// 數字與符號對應 (按鍵顯示)
251+
'1': '1', '2': '2', '3': '3', '4': '4', '5': '5',
252+
'6': '6', '7': '7', '8': '8', '9': '9', '0': '0',
251253
"'": "〃", ';': ';', ',': ',', '.': '.', '/': '/', ' ': '空白鍵', 'enter': 'Enter', 'backspace': '刪除鍵',
252-
'shift': '三碼', // *** 修正: 中文模式顯示 '三碼'
254+
'shift': '三碼',
253255
};
254256
// 英文模式下的鍵盤顯示 (Shift 鍵顯示為 'En')
255257
const keyname_map_lower = {
256258
'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e', 'f': 'f', 'g': 'g',
257259
'h': 'h', 'i': 'i', 'j': 'j', 'k': 'k', 'l': 'l', 'm': 'm', 'n': 'n',
258260
'o': 'o', 'p': 'p', 'q': 'q', 'r': 'r', 's': 's', 't': 't', 'u': 'u',
259261
'v': 'v', 'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z',
262+
// 數字與符號對應
263+
'1': '1', '2': '2', '3': '3', '4': '4', '5': '5',
264+
'6': '6', '7': '7', '8': '8', '9': '9', '0': '0',
260265
"'": "'", ';': ';', ',': ',', '.': '.', '/': '/', ' ': ' ', 'enter': 'Enter', 'backspace': '刪除鍵',
261-
'shift': 'En', // *** 修正: 英文模式顯示 'En'
266+
'shift': 'En',
262267
};
263268

264269
// DOM 元素
265270
const textOutput = document.getElementById('text-output');
266271
const mainInput = document.getElementById('main-input');
267272
const candidateDisplay = document.getElementById('candidate-display');
268273
const keyboardContainer = document.getElementById('keyboard-container');
269-
// const modeDisplay = document.getElementById('mode-display'); // 已移除
270274
const copyButton = document.getElementById('copy-btn');
271275
const clearButton = document.getElementById('clear-btn');
272276

@@ -311,7 +315,6 @@
311315
const { newCodemap, newReverseCodemap } = parseCinData(text);
312316
currentCodemap = newCodemap;
313317
currentReverseCodemap = newReverseCodemap;
314-
// updateModeDisplay(); // 已移除
315318
mainInput.textContent = '編碼表載入成功';
316319
} catch (error) {
317320
console.error(`載入 ${fileName} 時發生錯誤:`, error);
@@ -322,8 +325,14 @@
322325

323326
// --- 處理中文模式輸入的核心函數 ---
324327
function handleChineseInput(code) {
325-
// 忽略數字鍵
326-
if (code.match(/^[1-90]$/)) {
328+
const inputChar = code.toLowerCase();
329+
330+
// 1. 數字鍵處理 (直接輸出半形數字)
331+
if (inputChar.match(/^[0-9]$/)) {
332+
if (currentCandidates.length > 0) {
333+
selectCandidate(0); // 如果有編碼,先上字
334+
}
335+
textOutput.textContent += inputChar; // 直接輸出數字
327336
return;
328337
}
329338

@@ -354,8 +363,7 @@
354363
return;
355364
}
356365

357-
const inputChar = code.toLowerCase();
358-
// 接受所有 26 字母和 5 符號的輸入
366+
// 2. 字母 (a-z) 和符號 (;'./,) 用於編碼
359367
if (inputChar.match(/^[a-z;'./,<>]$/)) {
360368
if (currentCode.length === MAX_CODE_LENGTH) {
361369
if (currentCandidates.length > 0) {
@@ -387,7 +395,7 @@
387395
return;
388396
}
389397

390-
// 處理英文字母和符號
398+
// 處理英文字母、數字和符號
391399
if (char.length === 1) {
392400
textOutput.textContent += char;
393401
}
@@ -460,7 +468,7 @@
460468
return displayString;
461469
}
462470

463-
// --- 更新鍵盤按鍵顯示 (專門處理 Shift 鍵的變動) ---
471+
// --- 更新鍵盤按鍵顯示 ---
464472
function updateKeyboardDisplay() {
465473
const map = isEnglishMode ? keyname_map_lower : keyname_map_upper;
466474
document.querySelectorAll('.key[data-code]').forEach(keyElement => {
@@ -470,16 +478,16 @@
470478
}
471479
});
472480

473-
// 確保 Shift 鍵在模式切換時正確顯示
474481
const shiftKey = document.querySelector('.key[data-code="shift"]');
475482
if (shiftKey) {
476483
shiftKey.textContent = isEnglishMode ? keyname_map_lower['shift'] : keyname_map_upper['shift'];
477484
}
478485
}
479486

480-
// --- 動態生成手機優化鍵盤 ---
487+
// --- 動態生成手機優化鍵盤 (新增數字行) ---
481488
function generateMobileKeyboard() {
482489
const layout_mobile = [
490+
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], // 新增數字行
483491
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
484492
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';'],
485493
['Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', "'"],
@@ -514,13 +522,11 @@
514522
}
515523

516524
key.dataset.code = code;
517-
// 初始顯示為中文模式 ('三碼')
518525
key.textContent = keyname_map_upper[code] || keyText;
519526

520527
key.addEventListener('click', () => {
521528
if (code === 'shift') {
522529
isEnglishMode = !isEnglishMode;
523-
// updateModeDisplay(); // 已移除
524530
updateKeyboardDisplay();
525531
resetInputState();
526532
} else if (isEnglishMode) {

0 commit comments

Comments
 (0)