-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (47 loc) · 1.63 KB
/
Copy pathscript.js
File metadata and controls
51 lines (47 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
let datasets = [];
let currentData = {};
fetch("datasets.json")
.then((res) => res.json())
.then((list) => {
datasets = list;
const select = document.getElementById("dataset-select");
list.forEach(ds => {
const opt = document.createElement("option");
opt.value = ds.file;
opt.textContent = ds.label;
select.appendChild(opt);
});
select.addEventListener("change", (e) => loadData(e.target.value));
loadData(list[0].file); // 初期データ
});
function loadData(file) {
fetch(file)
.then((res) => res.json())
.then((json) => {
currentData = json;
renderList(Object.entries(currentData));
});
}
document.getElementById("search").addEventListener("input", (e) => {
const query = e.target.value.toLowerCase();
const results = Object.entries(currentData).filter(([key, value]) =>
key.toLowerCase().includes(query) ||
(value.abbreviation || []).some((abbr) =>
abbr.toLowerCase().includes(query)
)
);
renderList(results);
});
function renderList(entries) {
const ul = document.getElementById("results");
ul.innerHTML = "";
for (const [key, value] of entries) {
const li = document.createElement("li");
li.innerHTML = `<strong>${key}</strong><br/>
${value.abbreviation ? "略号: " + value.abbreviation.join(", ") + "<br/>" : ""}
${value.edition ? "<ul>" + value.edition.map((ed) =>
`<li><em>${ed.author}</em>: ${ed.bibliography}</li>`
).join("") + "</ul>" : ""}`;
ul.appendChild(li);
}
}