zidian
Version:
汉字、词语、成语查询接口
130 lines (114 loc) • 4.61 kB
HTML
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>解析</title>
<script src="https://cdn.jsdelivr.net/npm/jszip@3.3.0/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/filesaver.js@1.3.4/FileSaver.min.js"></script>
</head>
<body>
<script>
var sp = {
//源
source: {
//字
word: "/src/data/word.json",
//词
ci: "/src/data/ci.json",
//成语
idiom: "/src/data/idiom.json"
},
out: {
complete: 0,
word: {
rows: 30,
keys: [],
pagedata: []
},
ci: {
rows: 600,
keys: [],
pagedata: []
},
idiom: {
rows: 150,
keys: [],
pagedata: []
}
},
zip: null,
down: function () {
sp.zip.generateAsync({ type: "blob" }).then(function (content) {
saveAs(content, "zidian.zip");
});
},
spword: function () {
fetch(sp.source.word).then(x => x.json()).then(function (res) {
res.forEach(function (item, index) {
sp.out.word.keys.push(item.word);
var pi = Math.ceil((index + 1) / sp.out.word.rows) - 1;
var arr = sp.out.word.pagedata[pi] || [];
arr.push(item);
sp.out.word.pagedata[pi] = arr;
})
sp.zip = sp.zip || new JSZip();
var text = JSON.stringify(sp.out.word.keys);
sp.zip.file("word/00.json", text);
sp.out.word.pagedata.forEach(function (pd, pi) {
var text = JSON.stringify(pd);
sp.zip.file("word/" + pi + ".json", text);
});
if (++sp.out.complete == 3) {
sp.down();
}
})
},
spci: function () {
fetch(sp.source.ci).then(x => x.json()).then(function (res) {
res.forEach(function (item, index) {
sp.out.ci.keys.push(item.ci);
var pi = Math.ceil((index + 1) / sp.out.ci.rows) - 1;
var arr = sp.out.ci.pagedata[pi] || [];
arr.push(item);
sp.out.ci.pagedata[pi] = arr;
})
sp.zip = sp.zip || new JSZip();
var text = JSON.stringify(sp.out.ci.keys);
sp.zip.file("ci/00.json", text);
sp.out.ci.pagedata.forEach(function (pd, pi) {
var text = JSON.stringify(pd);
sp.zip.file("ci/" + pi + ".json", text);
});
if (++sp.out.complete == 3) {
sp.down();
}
})
},
spidiom: function () {
fetch(sp.source.idiom).then(x => x.json()).then(function (res) {
res.forEach(function (item, index) {
sp.out.idiom.keys.push(item.word);
var pi = Math.ceil((index + 1) / sp.out.idiom.rows) - 1;
var arr = sp.out.idiom.pagedata[pi] || [];
arr.push(item);
sp.out.idiom.pagedata[pi] = arr;
})
sp.zip = sp.zip || new JSZip();
var text = JSON.stringify(sp.out.idiom.keys);
sp.zip.file("idiom/00.json", text);
sp.out.idiom.pagedata.forEach(function (pd, pi) {
var text = JSON.stringify(pd);
sp.zip.file("idiom/" + pi + ".json", text);
});
if (++sp.out.complete == 3) {
sp.down();
}
})
},
}
sp.spword();
sp.spci();
sp.spidiom();
</script>
</body>
</html>