-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathn5n4.html
135 lines (122 loc) · 4.55 KB
/
n5n4.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
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title>新标准日本语初级单词一览表</title>
<link rel="stylesheet" type="text/css" href="dataTables.min.css">
<link rel="stylesheet" type="text/css" href="accent.css">
<script src="jquery-3.5.1.min.js"></script>
<script src="datatables.min.js"></script>
<script src="config.js"></script>
<script src="n5n4.js"></script>
<style>
#my_tbl_length {
width: 200px;
}
#my_tbl_length>label>select {
width: auto;
height: 38px;
}
#my_tbl_filter {
width: calc(100% - 200px);
height: 50px;
}
#my_tbl_filter input {
width: calc(100% - 80px);
height: 80%;
}
#my_tbl>tbody>tr>td:nth-child(1) {
width: 5%;
}
#my_tbl>tbody>tr>td:nth-child(2) {
width: 25%;
}
#my_tbl>tbody>tr>td:nth-child(3) {
width: 10%;
}
#my_tbl>tbody>tr>td:nth-child(4) {
width: 20%;
}
#my_tbl>tbody>tr>td:nth-child(5) {
width: 30%;
}
#my_tbl>tbody>tr>td:nth-child(6) {
width: 5%;
}
#my_tbl>tbody>tr>td:nth-child(7) {
width: 5%;
}
</style>
</head>
<body>
<p>新标准日本语初级单词一览表</p>
<table id="my_tbl" class="display" style="width:100%">
</table>
<script>
var accent_dict = JSON.parse($.getJSON({ 'url': "n5n4.json", 'async': false }).responseText);
var accent_dict_more = JSON.parse($.getJSON({ 'url': "n5n4_more.json", 'async': false }).responseText);
function get_accent(dict, data, n, match) {
if (!(data in dict)) {
//console.log('error: no accent found of '+data);
} else if (match && n in dict[data]) {
return dict[data][n];
} else if (Object.keys(dict[data]).length > 0) {
let closest = Object.keys(dict[data]).reduce(function (prev, curr) {
return (Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev);
});
let rl = '<div class="accent_uncertain" title="' + n + ' -> ' + closest + '">';
let rc = dict[data][closest];
let rr = '</div>';
if (!match && dict[data]['diff']) {
rc = rc.replace(/<p>/, '<p>' + data + ' (');
rc = rc.replace(/<\/p>/, ')' + '</p>');
}
return rl + rc + rr;
} else {
console.log('error: corrupted accent dict');
}
return null;
}
$(document).ready(function () {
$('#my_tbl').DataTable({
"pageLength": 50,
stateSave: true,
stateDuration: 60 * 60 * 24 * 30,
data: my_data,
columns: [
{ title: "编号" },
{
title: "假名",
render: function (data, type, row, meta) {
let n = row[5].toString();
let r = get_accent(accent_dict, data, n, true);
if (!r)
r = get_accent(accent_dict_more, data, n, false);
if (r)
return r;
return data;
}
},
{ title: "类型" },
{ title: "解释" },
{ title: "日文" },
{
title: "课号",
render: function (data, type, row, meta) {
return 'L' + data;
}
},
{
title: "音频",
render: function (data, type, row, meta) {
return type === 'display' ?
'<audio controls preload="none" src="' + media_dir + data + '" type="audio/mpeg"></audio>' :
data;
}
}
]
});
});
</script>
</body>
</html>