diff options
Diffstat (limited to '_content/kbbiclient.js')
| -rw-r--r-- | _content/kbbiclient.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/_content/kbbiclient.js b/_content/kbbiclient.js new file mode 100644 index 0000000..ab35633 --- /dev/null +++ b/_content/kbbiclient.js @@ -0,0 +1,35 @@ +/** + * Copyright 2020, Shulhan <m.shulhan@gmail.com>. All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +class KBBIClient { + constructor(baseURL) { + if (baseURL.length === 0) { + baseURL = "https://kilabit.info/project/kbbi" + } + this.baseURL = baseURL + } + + getDefinitions(words, cb) { + if (words.length === 0) { + return + } + + let params = "kata=" + words + let xhr = new XMLHttpRequest() + + xhr.addEventListener("load", function() { + cb(JSON.parse(xhr.responseText)) + }) + + xhr.open("GET", this.baseURL + "/api/definisi?" + params) + xhr.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded", + ) + + xhr.send(null) + } +} |
