Repository navigation
Expand file tree
/
Copy pathemoji-identifier.html
More file actions
217 lines (182 loc) · 4.86 KB
/
Copy pathemoji-identifier.html
File metadata and controls
217 lines (182 loc) · 4.86 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emoji Identifier</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Helvetica, Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
h1 {
color: #333;
margin-bottom: 10px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
}
textarea {
width: 100%;
min-height: 150px;
padding: 12px;
font-size: 16px;
font-family: Helvetica, Arial, sans-serif;
border: 2px solid #ddd;
border-radius: 8px;
resize: vertical;
margin-bottom: 20px;
}
textarea:focus {
outline: none;
border-color: #4CAF50;
}
.results {
background: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.results h2 {
margin-top: 0;
color: #333;
font-size: 18px;
}
.emoji-list {
display: grid;
gap: 20px;
margin-top: 20px;
}
.emoji-item {
display: flex;
align-items: center;
gap: 20px;
padding: 15px;
background: #f9f9f9;
border-radius: 8px;
border: 1px solid #e0e0e0;
}
.emoji-display {
font-size: 48px;
line-height: 1;
min-width: 60px;
text-align: center;
}
.emoji-info {
flex: 1;
}
.emoji-name {
font-weight: bold;
color: #333;
margin-bottom: 5px;
}
.emoji-codepoint {
font-family: ‘Courier New’, monospace;
color: #666;
font-size: 14px;
}
.no-results {
color: #999;
text-align: center;
padding: 40px;
}
</style>
</head>
<body>
<h1>Emoji identifier</h1>
<p class="subtitle">Paste text below to identify all emojis</p>
<textarea id="textInput" placeholder="Paste or type text with emojis here... 😊🎉✨"></textarea>
<div class="results" id="results">
<h2>Detected emojis</h2>
<div class="no-results">No emojis detected yet</div>
</div>
<script type="module">
let emojiData = {};
// Load emoji data from unicode-emoji-json CDN
async function loadEmojiData() {
try {
const response = await fetch('https://cdn.jsdelivr.net/npm/unicode-emoji-json@0.7.0/data-by-emoji.json');
emojiData = await response.json();
} catch (error) {
console.error('Failed to load emoji data:', error);
}
}
function getCodePoints(char) {
const codePoints = [];
for (let i = 0; i < char.length; i++) {
const code = char.charCodeAt(i);
if (code >= 0xD800 && code <= 0xDBFF && i + 1 < char.length) {
const high = code;
const low = char.charCodeAt(i + 1);
if (low >= 0xDC00 && low <= 0xDFFF) {
const codePoint = (high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000;
codePoints.push('U+' + codePoint.toString(16).toUpperCase().padStart(5, '0'));
i++;
continue;
}
}
codePoints.push('U+' + code.toString(16).toUpperCase().padStart(4, '0'));
}
return codePoints.join(' ');
}
function extractEmojis(text) {
const emojiRegex = /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E0}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F900}-\u{1F9FF}\u{1F018}-\u{1F270}\u{238C}-\u{2454}\u{20D0}-\u{20FF}\u{FE00}-\u{FE0F}\u{1F170}-\u{1F251}\u{1FA70}-\u{1FAFF}\u{E0020}-\u{E007F}](\u{FE0F})?(\u{200D}[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E0}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F900}-\u{1F9FF}\u{1F018}-\u{1F270}\u{238C}-\u{2454}\u{20D0}-\u{20FF}\u{FE00}-\u{FE0F}\u{1F170}-\u{1F251}\u{1FA70}-\u{1FAFF}\u{E0020}-\u{E007F}](\u{FE0F})?)*(\u{1F3FB}|\u{1F3FC}|\u{1F3FD}|\u{1F3FE}|\u{1F3FF})?/gu;
const matches = text.match(emojiRegex) || [];
const seen = new Set();
const unique = [];
for (const emoji of matches) {
if (!seen.has(emoji)) {
seen.add(emoji);
unique.push(emoji);
}
}
return unique;
}
function displayEmojis(emojis) {
const resultsDiv = document.getElementById('results');
if (emojis.length === 0) {
resultsDiv.innerHTML = '<h2>Detected emojis</h2><div class="no-results">No emojis detected yet</div>';
return;
}
const emojiItems = emojis.map(emoji => {
const data = emojiData[emoji];
let name = 'Unknown Emoji';
if (data && data.name) {
// Capitalize first letter of each word
name = data.name.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
}
const codepoint = getCodePoints(emoji);
return `
<div class="emoji-item">
<div class="emoji-display">${emoji}</div>
<div class="emoji-info">
<div class="emoji-name">${name}</div>
<div class="emoji-codepoint">${codepoint}</div>
</div>
</div>
`;
}).join('');
resultsDiv.innerHTML = `
<h2>Detected emojis (${emojis.length})</h2>
<div class="emoji-list">${emojiItems}</div>
`;
}
const textInput = document.getElementById('textInput');
textInput.addEventListener('input', (e) => {
const emojis = extractEmojis(e.target.value);
displayEmojis(emojis);
});
// Load emoji data when page loads
loadEmojiData();
</script>
</body>
</html>