-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
93 lines (67 loc) · 2.19 KB
/
popup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const searchEmojiInput = document.querySelector(".searchEmoji");
const emojiContainer = document.querySelector(".emojiContainer");
const emojiList = document.querySelector(".emojiList");
const loading = document.querySelector(".loading");
searchEmojiInput.addEventListener("input", searchEmoji);
searchEmojiInput.disabled = true;
let emojis;
const getEmoji = async () => {
const res = await fetch(
"https://emoji-api.com/emojis?access_key=fc345eef934edab724d45751275dbfa0654aa322"
);
const data = await res.json();
emojis = data;
};
getEmoji();
const statusCheck = () => {
const intervalID = setInterval(() => {
if (emojis === undefined) {
loading.classList.add("active");
} else {
loading.classList.remove("active");
loading.remove();
emojis.forEach((emoji) => {
emojiListFunc(emoji);
});
copyButtonFunc();
searchEmojiInput.disabled = false;
clearInterval(intervalID);
}
}, 1000);
};
statusCheck();
function searchEmoji(e) {
const searchQuery = e.target.value.trim().toLowerCase();
showEmojiList(searchQuery);
}
const showEmojiList = (searchQuery) => {
emojiList.innerHTML = "";
emojis
.filter((emoji) => emoji.slug.includes(searchQuery))
.forEach((emoji) => {
emojiListFunc(emoji);
});
// const copyEmojiButton = document.querySelectorAll(".copyEmoji");
copyButtonFunc();
};
const emojiListFunc = (emoji) => {
const input = document.createElement("input");
input.textContent = emoji.character;
input.value = emoji.character;
input.id = emoji.unicodeName;
input.classList.add("copyEmoji");
emojiList.appendChild(input);
};
const copyButtonFunc = () => {
const copyEmojiButton = document.querySelectorAll(".copyEmoji");
copyEmojiButton.forEach((button) =>
button.addEventListener("click", (e) => {
const copyEmoji = document.getElementById(`${e.target.id}`);
// make sure its an editable area before using select(), i.e input/textarea
copyEmoji.select();
// make sure to use document.execCommand('copy') as this function is only available with document
// not with other individual document nodes
document.execCommand("copy");
})
);
};