-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (40 loc) · 1.2 KB
/
index.js
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
const kpop = require('kpop')
const hangul = require('./hangul.js')
const inputField = document.querySelector('.inputField')
const assembledBtn = document.querySelector('.btn.assambled')
const deassambledBtn = document.querySelector('.btn.deassambled')
const output = document.querySelector('.output')
const convert = () => {
const text = inputField.value
if (text.length > 0) {
if (true) {
if (assembledBtn.classList.contains('active')) {
output.innerText = kpop.hangulify(text)
}
if (deassambledBtn.classList.contains('active')) {
output.innerText = hangul.d(kpop.hangulify(text)).join('')
}
} else {
output.innerText = ''
}
} else {
output.innerText = ''
}
}
const setMode = (mode, shouldConvert = false) => {
if (mode === 'assambled') {
assembledBtn.classList.add('active')
deassambledBtn.classList.remove('active')
}
if (mode === 'deassambled') {
assembledBtn.classList.remove('active')
deassambledBtn.classList.add('active')
}
if (shouldConvert) {
convert()
}
}
assembledBtn.addEventListener('click', () => setMode('assambled', true))
deassambledBtn.addEventListener('click', () => setMode('deassambled', true))
inputField.addEventListener('input', convert)
convert()