📚 An unofficial HJDict(沪江小D) API in Javascript [WIP]
MIT License
An unofficial HjDict API in Javascript. DAPI
Get Japanese-Chinese dict:
HjDict.jp2cn('', data => {
console.log(data)
// Do what you what with the data
})
{
"query": "",
"explains": [{
"primary": "",
"secondary": "",
"tertiary": "kasa",
"mp3": "http://d1.g.hjfile.cn/voice/jpsound/J12852.mp3",
"details": [{
"part_of_speech": "",
"items": [{
"type": "text",
"text": ""
}, {
"type": "list",
"jp": "",
"cn": ""
}]
}]
}, {
"primary": "",
"secondary": "",
"tertiary": "karakasa",
"mp3": "http://d1.g.hjfile.cn/voice/jpsound/J14795.mp3",
"details": [{
"part_of_speech": "",
"items": [{
"type": "text",
"text": ""
}]
}]
}]
}
For more data format, please check the API document.
Download hjdict.js and add following code in your HTML head:
<script src="<Path To>/hjdict.js">
Or you can just use
<script src="https://antfu.github.io/hjdict/dist/hjdict.js">
Note: When using HjDict in browser, you may face Cross Origin problem. You should try the solution here.
npm install hjdict node-fetch
const fetch = require('node-fetch')
const HjDict = require('hjdict')
HjDict.set_fetch(fetch)
For Node.js, you should install note-fetch
and pass it though HjDict.set_fetch
.
Since version 0.0.3
, the default CORS proxy is set to http://crossorigin.me/.
You can always set/unset it by using the following code at the begin of your scripts:
// Set the cors proxy
HjDict.set_cors_proxy('http://crossorigin.me/')
// Reset
HjDict.set_cors_proxy('')
Supported/Planed:
Note: There are some other languages are supported by HjDict.com but not in this list. Since I am not a user of those languages, I may not have time to implement them. However, any PR is welcome .
MIT - antfu