Skip to content

Commit b2abf7f

Browse files
authored
Update test.html
1 parent 36e4640 commit b2abf7f

1 file changed

Lines changed: 117 additions & 64 deletions

File tree

test.html

Lines changed: 117 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@
144144
.text-output-area,
145145
.candidate-area,
146146
#main-input,
147-
#search-input,
148-
#search-result {
147+
#phrase-input {
149148
width: 100%;
150149
border-radius: 8px;
151150
border: 1px solid var(--border-color);
@@ -158,9 +157,8 @@
158157
/* 統一所有主要欄位的內距 */
159158
.text-output-area,
160159
#main-input,
161-
#search-input,
162-
.candidate-area,
163-
#search-result {
160+
#phrase-input,
161+
.candidate-area {
164162
padding: 8px;
165163
}
166164

@@ -176,14 +174,7 @@
176174
flex-direction: column;
177175
gap: 8px;
178176
}
179-
180-
.search-area {
181-
width: 100%;
182-
display: flex;
183-
align-items: center;
184-
gap: 10px;
185-
}
186-
177+
187178
#main-input {
188179
height: 40px;
189180
}
@@ -215,23 +206,81 @@
215206
border-color: #b3b9d8;
216207
}
217208

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-
230209
#mode-display {
231210
font-size: 16px;
232211
color: #757575;
233212
align-self: flex-start;
234213
}
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+
}
235284

236285
/* 鍵盤樣式 */
237286
.keyboard-container {
@@ -240,6 +289,7 @@
240289
flex-direction: column;
241290
align-items: center;
242291
gap: 5px;
292+
margin-top: 15px;
243293
}
244294

245295
.key-row {
@@ -331,13 +381,14 @@ <h2>輸入法模式:</h2>
331381
<input type="text" id="main-input" placeholder="編碼顯示在此" readonly="">
332382
<div id="candidate-display" class="candidate-area"></div>
333383
</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>
339384

340385
<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>
341392

342393
<div class="keyboard-container">
343394
<div class="key-row">
@@ -457,8 +508,8 @@ <h2>輸入法模式:</h2>
457508
const textOutput = document.getElementById('text-output');
458509
const mainInput = document.getElementById('main-input');
459510
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');
462513
const keyboardContainer = document.querySelector('.keyboard-container');
463514
const modeDisplay = document.getElementById('mode-display');
464515
const modeRadioButtons = document.querySelectorAll('input[name="input_mode"]');
@@ -951,55 +1002,57 @@ <h2>輸入法模式:</h2>
9511002
}
9521003
});
9531004

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+
9591020
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';
9611024
const code = result.code;
962-
const index = result.index;
963-
let suffix = '';
9641025
const candidatesForCode = currentCodemap[code];
1026+
1027+
let suffix = '';
9651028
// 只有當該編碼有多個候選字時才加上後綴
9661029
if (candidatesForCode && candidatesForCode.length > 1) {
967-
if (index === 0) {
968-
// 第一個字不顯示數字
1030+
if (result.index === 0) {
9691031
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();
9731034
suffix = fullWidthDigits[digit];
974-
} else if (index === 9) {
975-
// 第十個顯示全形零
1035+
} else if (result.index === 9) {
9761036
suffix = '0';
9771037
} else {
978-
// 第十一個之後顯示大於符號
9791038
suffix = '>';
9801039
}
9811040
}
982-
return formatCode(code) + suffix;
1041+
1042+
codeLabel.textContent = formatCode(code) + suffix;
1043+
column.appendChild(codeLabel);
9831044
});
984-
985-
searchResult.textContent = `編碼: ${formattedCodes.join(' ')}`;
9861045
} else {
987-
searchResult.textContent = '找不到該漢字編碼。';
1046+
const codeLabel = document.createElement('span');
1047+
codeLabel.className = 'code-label';
1048+
codeLabel.textContent = '---';
1049+
column.appendChild(codeLabel);
9881050
}
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);
10001053
}
10011054
});
1002-
1055+
10031056
// 頁面載入時先初始化顯示
10041057
switchInputMethod('primary');
10051058
updateKeyboardDisplay();

0 commit comments

Comments
 (0)