const textInput = document.querySelector(
".text-input"
)
const emojiInput = document.querySelector(
".emoji-input"
)
const result = document.querySelector(
".result"
)
let accessKey =
""
function
convertIntoText() {
const emoji = emojiInput.value;
if
(emoji) {
callApi(emoji,
"convertIntoText"
)
}
else
{
alert(
"Please, provide emoji to get it's text value !"
)
}
}
function
callApi(input, type) {
fetch(
`https:
.then(
response => response.json()
).then((data) => {
response = data;
if
(response.status && response.status ==
"error"
) {
alert(
"No result found for this query !"
)
}
else
{
const emojiOutput = response[0]
if
(type ==
"convertIntoEmoji"
) {
flag =
false
;
var
textUnicode =
""
var
textList = []
for
(const item of response) {
textUnicode = item.unicodeName;
textList = textUnicode.split(
" "
)
textList.shift()
var
textEmoji = textList.join(
""
)
if
(textEmoji == input) {
result.innerHTML =
`<p>${item.character}</p>`
flag =
true
;
break
;
}
}
if
(flag ==
false
) {
result.innerHTML =
`<p>${emojiOutput.character}</p>`
}
emojiInput.value = '
'
}
else {
flag = false;
for (const emoji of response) {
if (emoji.character == input) {
var unicode = emoji.unicodeName;
var tempList = unicode.split(" ")
tempList.shift()
var realEmoji = tempList.join("")
result.innerHTML = `<p>${realEmoji}</p>`
flag = true;
break;
}
}
if (flag == false) {
result.innerHTML =
`<p>${emojiOutput.subGroup}</p>`
}
textInput.value = '
'
}
}
})
}
function convertIntoEmoji() {
const text = textInput.value;
if (text) {
callApi(text, "convertIntoEmoji");
}
else {
alert("Please, provide text to get it'
s emoji !")
}
}