|
144 | 144 | .text-output-area, |
145 | 145 | .candidate-area, |
146 | 146 | #main-input, |
147 | | - #search-input, |
148 | | - #search-result { |
| 147 | + #phrase-input { |
149 | 148 | width: 100%; |
150 | 149 | border-radius: 8px; |
151 | 150 | border: 1px solid var(--border-color); |
|
158 | 157 | /* 統一所有主要欄位的內距 */ |
159 | 158 | .text-output-area, |
160 | 159 | #main-input, |
161 | | - #search-input, |
162 | | - .candidate-area, |
163 | | - #search-result { |
| 160 | + #phrase-input, |
| 161 | + .candidate-area { |
164 | 162 | padding: 8px; |
165 | 163 | } |
166 | 164 |
|
|
176 | 174 | flex-direction: column; |
177 | 175 | gap: 8px; |
178 | 176 | } |
179 | | - |
180 | | - .search-area { |
181 | | - width: 100%; |
182 | | - display: flex; |
183 | | - align-items: center; |
184 | | - gap: 10px; |
185 | | - } |
186 | | - |
| 177 | + |
187 | 178 | #main-input { |
188 | 179 | height: 40px; |
189 | 180 | } |
|
215 | 206 | border-color: #b3b9d8; |
216 | 207 | } |
217 | 208 |
|
218 | | - #search-input { |
219 | | - flex-grow: 0; |
220 | | - width: 160px; |
221 | | - height: 40px; |
222 | | - } |
223 | | - |
224 | | - #search-result { |
225 | | - flex-grow: 1; |
226 | | - color: #555; |
227 | | - min-height: 40px; |
228 | | - } |
229 | | - |
230 | 209 | #mode-display { |
231 | 210 | font-size: 16px; |
232 | 211 | color: #757575; |
233 | 212 | align-self: flex-start; |
234 | 213 | } |
| 214 | + |
| 215 | + /* 新增的查碼練習區域樣式 */ |
| 216 | + .lookup-section { |
| 217 | + width: 100%; |
| 218 | + margin-top: 15px; |
| 219 | + display: flex; |
| 220 | + flex-direction: column; |
| 221 | + gap: 10px; |
| 222 | + padding-top: 12px; |
| 223 | + border-top: 1px dashed var(--border-color); |
| 224 | + } |
| 225 | + |
| 226 | + .lookup-section h2 { |
| 227 | + font-size: 20px; |
| 228 | + color: var(--primary-color); |
| 229 | + margin: 0; |
| 230 | + font-weight: 700; |
| 231 | + } |
| 232 | + |
| 233 | + #phrase-input { |
| 234 | + width: 100%; |
| 235 | + min-height: 50px; |
| 236 | + resize: vertical; |
| 237 | + font-size: var(--unified-font-size); |
| 238 | + padding: 8px; |
| 239 | + } |
| 240 | + |
| 241 | + #encoding-results { |
| 242 | + width: 100%; |
| 243 | + display: flex; |
| 244 | + flex-direction: row; |
| 245 | + flex-wrap: nowrap; |
| 246 | + overflow-x: auto; |
| 247 | + align-items: flex-start; |
| 248 | + gap: 8px; |
| 249 | + padding: 8px 0; |
| 250 | + font-size: 18px; |
| 251 | + -ms-overflow-style: none; /* IE and Edge */ |
| 252 | + scrollbar-width: none; /* Firefox */ |
| 253 | + } |
| 254 | + |
| 255 | + #encoding-results::-webkit-scrollbar { |
| 256 | + display: none; |
| 257 | + } |
| 258 | + |
| 259 | + .char-encoding-column { |
| 260 | + display: flex; |
| 261 | + flex-direction: column; |
| 262 | + align-items: center; |
| 263 | + min-width: 60px; /* 為 4 個全形字元 + 邊距留出空間 */ |
| 264 | + flex-shrink: 0; |
| 265 | + padding: 5px; |
| 266 | + border: 1px solid var(--border-color); |
| 267 | + border-radius: 8px; |
| 268 | + background-color: #e8eaf6; |
| 269 | + } |
| 270 | + |
| 271 | + .char-encoding-column .char-label { |
| 272 | + font-weight: bold; |
| 273 | + font-size: 24px; |
| 274 | + margin-bottom: 5px; |
| 275 | + line-height: 1; |
| 276 | + } |
| 277 | + |
| 278 | + .char-encoding-column .code-label { |
| 279 | + font-family: monospace; |
| 280 | + white-space: nowrap; |
| 281 | + line-height: 1.2; |
| 282 | + text-align: center; |
| 283 | + } |
235 | 284 |
|
236 | 285 | /* 鍵盤樣式 */ |
237 | 286 | .keyboard-container { |
|
240 | 289 | flex-direction: column; |
241 | 290 | align-items: center; |
242 | 291 | gap: 5px; |
| 292 | + margin-top: 15px; |
243 | 293 | } |
244 | 294 |
|
245 | 295 | .key-row { |
@@ -331,13 +381,14 @@ <h2>輸入法模式:</h2> |
331 | 381 | <input type="text" id="main-input" placeholder="編碼顯示在此" readonly=""> |
332 | 382 | <div id="candidate-display" class="candidate-area"></div> |
333 | 383 | </div> |
334 | | - |
335 | | - <div class="search-area"> |
336 | | - <input type="text" id="search-input" placeholder="在此輸入漢字" maxlength="1"> |
337 | | - <div id="search-result">查詢結果顯示在此</div> |
338 | | - </div> |
339 | 384 |
|
340 | 385 | <div id="mode-display">模式:三碼</div> |
| 386 | + |
| 387 | + <div class="lookup-section"> |
| 388 | + <h2>查碼練習</h2> |
| 389 | + <textarea id="phrase-input" placeholder="在此輸入或貼上一段文字..."></textarea> |
| 390 | + <div id="encoding-results"></div> |
| 391 | + </div> |
341 | 392 |
|
342 | 393 | <div class="keyboard-container"> |
343 | 394 | <div class="key-row"> |
@@ -457,8 +508,8 @@ <h2>輸入法模式:</h2> |
457 | 508 | const textOutput = document.getElementById('text-output'); |
458 | 509 | const mainInput = document.getElementById('main-input'); |
459 | 510 | const candidateDisplay = document.getElementById('candidate-display'); |
460 | | - const searchInput = document.getElementById('search-input'); |
461 | | - const searchResult = document.getElementById('search-result'); |
| 511 | + const phraseInput = document.getElementById('phrase-input'); |
| 512 | + const encodingResults = document.getElementById('encoding-results'); |
462 | 513 | const keyboardContainer = document.querySelector('.keyboard-container'); |
463 | 514 | const modeDisplay = document.getElementById('mode-display'); |
464 | 515 | const modeRadioButtons = document.querySelectorAll('input[name="input_mode"]'); |
@@ -951,55 +1002,57 @@ <h2>輸入法模式:</h2> |
951 | 1002 | } |
952 | 1003 | }); |
953 | 1004 |
|
954 | | - // --- 反向查詢事件處理 --- |
955 | | - searchInput.addEventListener('input', (event) => { |
956 | | - const charToSearch = searchInput.value; |
957 | | - if (charToSearch.length === 1) { |
958 | | - const results = currentReverseCodemap[charToSearch]; |
| 1005 | + // --- 新增的批量查碼處理邏輯 --- |
| 1006 | + phraseInput.addEventListener('input', (event) => { |
| 1007 | + const textToSearch = phraseInput.value; |
| 1008 | + encodingResults.innerHTML = ''; |
| 1009 | + |
| 1010 | + for (const char of textToSearch) { |
| 1011 | + const results = currentReverseCodemap[char]; |
| 1012 | + const column = document.createElement('div'); |
| 1013 | + column.className = 'char-encoding-column'; |
| 1014 | + |
| 1015 | + const charLabel = document.createElement('span'); |
| 1016 | + charLabel.className = 'char-label'; |
| 1017 | + charLabel.textContent = char; |
| 1018 | + column.appendChild(charLabel); |
| 1019 | + |
959 | 1020 | if (results && results.length > 0) { |
960 | | - const formattedCodes = results.map(result => { |
| 1021 | + results.slice(0, 5).forEach((result, index) => { |
| 1022 | + const codeLabel = document.createElement('span'); |
| 1023 | + codeLabel.className = 'code-label'; |
961 | 1024 | const code = result.code; |
962 | | - const index = result.index; |
963 | | - let suffix = ''; |
964 | 1025 | const candidatesForCode = currentCodemap[code]; |
| 1026 | + |
| 1027 | + let suffix = ''; |
965 | 1028 | // 只有當該編碼有多個候選字時才加上後綴 |
966 | 1029 | if (candidatesForCode && candidatesForCode.length > 1) { |
967 | | - if (index === 0) { |
968 | | - // 第一個字不顯示數字 |
| 1030 | + if (result.index === 0) { |
969 | 1031 | suffix = ''; |
970 | | - } else if (index < 9) { |
971 | | - // 第二個到第九個顯示全形數字 |
972 | | - const digit = (index + 1).toString(); |
| 1032 | + } else if (result.index < 9) { |
| 1033 | + const digit = (result.index + 1).toString(); |
973 | 1034 | suffix = fullWidthDigits[digit]; |
974 | | - } else if (index === 9) { |
975 | | - // 第十個顯示全形零 |
| 1035 | + } else if (result.index === 9) { |
976 | 1036 | suffix = '0'; |
977 | 1037 | } else { |
978 | | - // 第十一個之後顯示大於符號 |
979 | 1038 | suffix = '>'; |
980 | 1039 | } |
981 | 1040 | } |
982 | | - return formatCode(code) + suffix; |
| 1041 | + |
| 1042 | + codeLabel.textContent = formatCode(code) + suffix; |
| 1043 | + column.appendChild(codeLabel); |
983 | 1044 | }); |
984 | | - |
985 | | - searchResult.textContent = `編碼: ${formattedCodes.join(' ')}`; |
986 | 1045 | } else { |
987 | | - searchResult.textContent = '找不到該漢字編碼。'; |
| 1046 | + const codeLabel = document.createElement('span'); |
| 1047 | + codeLabel.className = 'code-label'; |
| 1048 | + codeLabel.textContent = '---'; |
| 1049 | + column.appendChild(codeLabel); |
988 | 1050 | } |
989 | | - } else { |
990 | | - searchResult.textContent = '查詢結果顯示在此'; |
991 | | - } |
992 | | - }); |
993 | | - |
994 | | - // 額外處理 Backspace 鍵清除 |
995 | | - searchInput.addEventListener('keydown', (event) => { |
996 | | - if (event.key === 'Backspace') { |
997 | | - event.stopPropagation(); |
998 | | - searchInput.value = ''; |
999 | | - searchResult.textContent = '查詢結果顯示在此'; |
| 1051 | + |
| 1052 | + encodingResults.appendChild(column); |
1000 | 1053 | } |
1001 | 1054 | }); |
1002 | | - |
| 1055 | + |
1003 | 1056 | // 頁面載入時先初始化顯示 |
1004 | 1057 | switchInputMethod('primary'); |
1005 | 1058 | updateKeyboardDisplay(); |
|
0 commit comments