-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
178 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
const dataFile = "data/data.json"; | ||
let data = {}; | ||
fetch(dataFile) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
return response.json(); | ||
}) | ||
.then((jsonData) => { | ||
data = jsonData; | ||
}) | ||
.catch((error) => { | ||
console.error("Read JSON error:", error); | ||
}); | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const dataFile = "data/data.json"; | ||
|
||
// event | ||
document.getElementById("query-button").addEventListener("click", queryHanzi); | ||
document | ||
.getElementById("query-text") | ||
.addEventListener("keydown", function (event) { | ||
if (event.key === "Enter") { | ||
queryHanzi(); | ||
} | ||
}); | ||
// init data | ||
fetch(dataFile) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error("Network response error"); | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
const charData = data.chars; | ||
const statsData = data.stats; | ||
|
||
const paragraphs = [ | ||
"<p>📝 注意这里五笔版本是<strong>1986</strong>版(王码)五笔。</p>", | ||
`<p class="note">当前收录汉字: ${statsData.total}字(五笔全码: ${statsData.fullCode}, 字根拆解:${statsData.units},图解:${statsData.segments})。</p>`, | ||
'<p class="note">⚠️ 标识表示全码和容错码存在一定争议(比如起笔或末笔笔画顺序)。</p>', | ||
]; | ||
|
||
const note = document.getElementById('note-area'); | ||
const para = document.getElementById('note-warning'); | ||
para.innerHTML = ""; | ||
paragraphs.forEach(text => { | ||
const more = document.createElement('p'); | ||
more.innerHTML = text; | ||
note.insertBefore(more, para); | ||
}); | ||
|
||
// event | ||
document | ||
.getElementById("query-button") | ||
.addEventListener("click", () => { | ||
queryHanzi(charData, statsData); | ||
}); | ||
document | ||
.getElementById("query-text") | ||
.addEventListener("keydown", function (event) { | ||
if (event.key === "Enter") { | ||
queryHanzi(charData, statsData); | ||
} | ||
}); | ||
}) | ||
.catch((error) => { | ||
console.error("Read JSON error:", error); | ||
}); | ||
}); |
Oops, something went wrong.