-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
91 lines (79 loc) · 3.85 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
document.addEventListener('DOMContentLoaded', function () {
const filterButtons = document.querySelectorAll('.filter');
const emojiButtons = document.querySelectorAll('.emoji');
const toolboxButton = document.getElementById("toolboxButton");
const toolboxDiv = document.getElementById("toolboxDiv");
const seperator = document.getElementById("seperator");
toolboxButton.addEventListener('click', function () {
toolboxDiv.classList.toggle("hidden");
seperator.classList.toggle("hidden");
});
filterButtons.forEach(button => {
button.addEventListener('click', function () {
const filterClass = button.classList[1]; // Target second class
const updatedEmojiButtons = document.querySelectorAll('.emoji');
// Re-fetch the emojis dynamically
if (filterClass === "all") {
updatedEmojiButtons.forEach(emoji => emoji.style.display = "block");
} else {
updatedEmojiButtons.forEach(emoji => {
if (emoji.classList.contains(filterClass)) {
emoji.style.display = "block";
} else {
emoji.style.display = "none";
}
});
}
});
});
// Emoji copy functionality
emojiButtons.forEach(button => {
button.addEventListener('click', function () {
const emoji = button.getAttribute('data-emoji'); // Get the emoji text
// Use the Clipboard API to copy the text to the clipboard
navigator.clipboard.writeText(emoji).then(() => {
const feedback = document.createElement('span');
feedback.textContent = 'Copied!';
feedback.style.color = 'green';
feedback.style.marginLeft = '10px';
button.parentNode.appendChild(feedback);
setTimeout(() => feedback.remove(), 1000);
}).catch(err => {
console.error('Failed to copy text: ', err);
});
});
});
// Emoji add functionality
const addTextmojiButton = document.getElementById("addTextmoji");
addTextmojiButton.addEventListener('click', function () {
const addFilterDiv = document.getElementById('addFilterDiv');
addFilterDiv.classList.toggle("hidden");
const filterAddButtons = document.querySelectorAll('.filterAdd');
filterAddButtons.forEach(button => {
button.addEventListener('click', function () {
const userTextmoji = document.getElementById('userTextmoji').value;
if (userTextmoji.trim() !== '') {
// Create new textmoji button
const newButton = document.createElement('button');
if (button.classList.contains("happyBtn")) {
newButton.classList.add('emoji', 'happy');
} else if (button.classList.contains("angryBtn")) {
newButton.classList.add('emoji', 'angry');
} else if (button.classList.contains("danceBtn")) {
newButton.classList.add('emoji', 'dance');
} else {
newButton.classList.add('emoji');
}
newButton.setAttribute('data-emoji', userTextmoji);
newButton.textContent = userTextmoji;
// Append new textmoji to emoji list
document.querySelector('.emoji-list').appendChild(newButton);
document.getElementById('userTextmoji').value = '';
addFilterDiv.classList.toggle("hidden");
toolboxDiv.classList.toggle("hidden");
seperator.classList.toggle("hidden");
}
});
});
});
});