forked from code4fukui/ipsj-words
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
281 lines (266 loc) · 6.69 KB
/
index.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<link rel="icon" href="./icon.png">
<link rel="apple-touch-icon" href="./icon.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>IT用語集</title>
<body>
<div id=divin>
<input type=text id=intext><span class=title>IT用語集</span>
</div>
<div id=divresult></div>
<div id=btnc>
<button class=btn id=btnclear>クリア</button>
<button class=btn id=btnrnd>ランダム</button>
</div>
<footer>
<a id=credit></a>
<h1>IT用語集</h1>
DATA: <a href=https://creativecommons.org/licenses/by-sa/4.0/deed.ja>CC BY-SA 4.0</a> <a href=https://github.com/code4fukui/SakuraCloudCertificationStudyMaterial>さくらインターネット株式会社制作のスライド</a>より<br>
app: MIT <a href=https://github.com/code4fukui/it-words>src on GitHub</a>, forked from: <a href=https://github.com/code4fukui/ipsj-words>IT辞典</a>
</footer>
<script type="module">
import { CSV } from "https://js.sabae.cc/CSV.js";
import { Pinyin } from "https://code4fukui.github.io/Pinyin/Pinyin.js";
import { IndexedCache } from "https://code4fukui.github.io/IndexedCache/IndexedCache.js";
//import { ArrayUtil } from "https://js.sabae.cc/ArrayUtil.js";
import { rnd } from "https://js.sabae.cc/rnd.js";
intext.disabled = true;
intext.value = "loading...";
//const fn = "ipsj-words-ver.1.0_2024-4-10.csv";
const fn = "./it-words.csv";
const cache = await IndexedCache.create(fn, 1);
const bin = await cache.fetchOrLoad(fn);
const data = CSV.parse(new TextDecoder().decode(bin));
console.log(data);
const keys0 = [];
for (const d of data) {
d.word.split("()()").forEach(i => keys0.push(i));
}
const keys = keys0.sort((a, b) => b.length - a.length);
//console.log("keys.length", keys, keys.length);
//data0.filter(i => i.説明);
//const data2 = ArrayUtil.toUnique(data.map(i => i.用語));
//console.log(data2.length, "/", data.length, "/", data0.length);
//console.log(data.length, "/", data0.length);
//console.log(data);
data.forEach(i => i.key = (i.word + i.description).toUpperCase());
intext.disabled = false;
intext.value = "";
const renderListSimple = (div, data2) => {
div.innerHTML = data2.map(i => {
const res = [];
for (const name in i) {
res.push(`${name}: ${i[name]}`);
}
return res.join("<br>\n");
}).join("<hr>");
};
const cr = (tag, parent) => {
const res = document.createElement(tag);
if (parent) parent.appendChild(res);
return res;
};
const setWithLink = (div, s) => {
const ss = [];
let n = 0;
for (;;) {
let keyhit = null;
let nhit = s.length;
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const m = s.indexOf(key, n);
if (m >= 0 && m < nhit) {
keyhit = key;
nhit = m;
}
}
if (!keyhit) {
div.appendChild(document.createTextNode(s.substring(n)));
break;
}
div.appendChild(document.createTextNode(s.substring(n, nhit)));
// link
const span = cr("span", div);
span.textContent = keyhit;
span.className = "keyword";
span.onclick = () => {
intext.value = keyhit;
intext.oninput();
};
n = nhit + keyhit.length;
}
};
const list2htmlBlock = (div, data) => {
const tbl = cr("table");
for (const d of data) {
const set = (td, name) => {
setWithLink(td, d[name]);
td.className = name;
return td;
};
const tr = cr("tr", tbl);
/*
set(cr("th", tr), "kanji");
set(cr("td", tr), "kanji_s");
*/
const td1 = cr("td", tr);
td1.className = "means";
//setWithLink(td1, d.用語.replace(/\|/g, "、"));
td1.textContent = d.word.replace(/\|/g, "、");
const td = set(cr("td", tr), "description");
const addspan = cr("span", td);
addspan.className = "spansrc";
addspan.innerHTML = " (出展: <a href=" + d.src_url + ">" + d.src_title + "</a>)";
/*
const tr2 = cr("tr", tbl);
const tdp = cr("td", tr2);
//set(tdp, "pron").setAttribute("colspan", 2);
//tdp.onclick = () => speech(d.kanji);
*/
}
div.innerHTML = "";
div.appendChild(tbl);
};
const maxcnt = 100;
intext.oninput = () => {
const key = intext.value.trim();
//if (key.length == 0) return;
const keyu = key.toUpperCase();
const data2 = data.filter(d => {
for (const name in d) {
if (d.key.indexOf(keyu) >= 0) {
return true;
}
}
});
/*
if (data2.length == 0) {
if (key.length == 0) return;
intext.value = key.substring(0, key.length - 1);
intext.oninput();
return;
}
*/
const val = (i) => {
let pnt = 0;
const keys = i.word.split("|");
if (keys.indexOf(key) >= 0) return 0;
const n = i.word.charCodeAt(0) + 100000 * i.word.length;
if (!i.description) return 100000 * 10000 + n;
if (i.word.indexOf(key) >= 0) return -1 + n;
return 100000 * 100 + n;
};
data2.sort((a, b) => val(a) - val(b));
const flgmore = data2.length > maxcnt;
if (flgmore) {
data2.length = maxcnt;
}
//renderListSimple(divresult, data2);
list2htmlBlock(divresult, data2);
if (flgmore) {
divresult.appendChild(document.createTextNode("and more..."));
}
scrollTo(0, 0);
document.location.hash = encodeURIComponent(key);
};
const defaultword = "";
onhashchange = () => {
intext.value = decodeURIComponent(document.location.hash.substring(1)) || defaultword;
intext.oninput();
};
onhashchange();
btnclear.onclick = () => {
intext.value = "";
intext.oninput();
};
btnrnd.onclick = () => {
const key = keys[rnd(keys.length)];
intext.value = key;
intext.oninput();
};
</script>
<style>
:root {
--main-bg-color: #ff96b9;
}
body {
font-family: sans-serif;
margin: 0;
padding-bottom: 50vh;
}
.title {
font-weight: bold;
padding: 0 .4em;
}
#divin {
background-color: var(--main-bg-color);
color: black;
padding: .5em;
top: 0;
position: fixed;
width: 100vw;
}
#divin a {
margin: .5em;
color: black !important;
font-weight: bold;
font-size: 130%;
text-decoration: none;
}
#divresult {
margin: .5em;
padding-top: 3.5em;
}
input {
font-size: 140%;
width: 70vw;
max-width: 10em;
padding: .2em;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: .2em .3em;
}
.keyword {
font-weight: bold;
}
.means {
x-font-size: 90%;
font-weight: bold;
}
footer {
position: fixed;
width: 100%;
bottom: 0;
background-color: var(--main-bg-color);
color: black;
padding: .5em;
}
.spansrc {
font-size: 80%;
}
a {
color: black !important;
}
h1 {
font-size: 130%;
margin: 0;
}
#btnc {
text-align: center;
}
.btn {
font-weight: bold;
padding: 1em;
margin: .5em 0 1.5em 0;
border-radius: 1em;
background-color: var(--main-bg-color);
border: none;
}
</style>
</body>
</html>