-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparison.html
208 lines (174 loc) · 6.07 KB
/
comparison.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emoji Comparison</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap');
body {
font-family: Nunito, Arial, sans-serif;
background-color: #343a40;
color: #f8f9fa;
text-align: center;
margin: 0;
padding: 0;
}
h2 {
margin-top: 20px;
color: #ffd43b;
}
table {
width: 90%;
margin: 20px auto;
border-collapse: collapse;
background-color: #495057;
}
th, td {
border: 1px solid #adb5bd;
padding: 12px;
text-align: center;
}
th {
background-color: #868e96;
}
td {
font-size: 48px;
}
img {
width: 48px;
height: 48px;
}
.noto-emoji {
font-family: 'Noto Color Emoji', sans-serif;
}
</style>
</head>
<body>
<h2>Emoji Comparison: Twemoji, Toss Face, Noto, OpenMoji, Browser Default</h2>
<table id="emojiTable">
<thead>
<tr>
<th>Twemoji</th>
<th>Toss Face</th>
<th>Noto Color Emoji</th>
<th>OpenMoji</th>
<th>Browser Default</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<p>Note: Toss Face has more emojis: https://tossface.cho.sh/<br>
Toss Face: https://github.com/toss/tossface<br>
Noto Color Emoji: https://fonts.google.com/noto/specimen/Noto+Color+Emoji<br>
Twemoji: https://github.com/jdecked/twemoji<br>
OpenMoji: https://github.com/hfg-gmuend/openmoji/tree/master/color/72x72</p>
<script>
const TWEMOJI_API_URL = "https://api.github.com/repos/jdecked/twemoji/contents/assets/svg";
const TOSSFACE_API_URL = "https://api.github.com/repos/toss/tossface/contents/dist/svg";
const OPENMOJI_API_URL = "https://api.github.com/repos/hfg-gmuend/openmoji/contents/color/72x72";
const CHUNK_SIZE = 16;
async function fetchGithubFiles(url) {
const response = await fetch(url, { headers: { "Accept": "application/vnd.github.v3+json" } });
if (!response.ok) throw new Error(`Failed to fetch: ${response.statusText}`);
return await response.json();
}
function twemojiToTossFace(twemojiFilename) {
return (
"u" +
twemojiFilename
.toUpperCase()
.split("-")
.join("_u")
.replace(".SVG", ".svg")
);
}
function getUnicodeFromFilename(filename) {
return filename
.replace(".svg", "")
.split("-")
.map(hex => String.fromCodePoint(parseInt(hex, 16)))
.join("");
}
function twemojiToOpenMoji(twemojiFilename) {
return twemojiFilename
.replace(".svg", "")
.split("-")
.map(hex => hex.toUpperCase())
.join("-");
}
async function populateEmojiTable(startIndex = 0) {
try {
const [twemojiFiles, tossFaceFiles, openMojiFiles] = await Promise.all([
fetchGithubFiles(TWEMOJI_API_URL),
fetchGithubFiles(TOSSFACE_API_URL),
fetchGithubFiles(OPENMOJI_API_URL)
]);
const twemojiFilenames = twemojiFiles.map(file => file.name);
const tossFaceFilenames = tossFaceFiles.map(file => file.name);
const openMojiFilenames = openMojiFiles.map(file => file.name);
const tbody = document.querySelector("#emojiTable tbody");
const endIndex = Math.min(startIndex + CHUNK_SIZE, twemojiFilenames.length);
const emojiSubset = twemojiFilenames.slice(startIndex, endIndex);
emojiSubset.forEach(twemojiFile => {
const tossFaceEquivalent = twemojiToTossFace(twemojiFile);
const isMatch = tossFaceFilenames.includes(tossFaceEquivalent);
const openMojiEquivalent = twemojiToOpenMoji(twemojiFile) + ".png";
const isOpenMojiMatch = openMojiFilenames.includes(openMojiEquivalent);
const row = document.createElement("tr");
const twemojiCell = document.createElement("td");
const twemojiImg = document.createElement("img");
twemojiImg.src = `https://raw.githubusercontent.com/jdecked/twemoji/main/assets/svg/${twemojiFile}`;
twemojiImg.alt = `Twemoji ${twemojiFile}`;
twemojiCell.appendChild(twemojiImg);
row.appendChild(twemojiCell);
const tossFaceCell = document.createElement("td");
if (isMatch) {
const tossFaceImg = document.createElement("img");
tossFaceImg.src = `https://raw.githubusercontent.com/toss/tossface/main/dist/svg/${tossFaceEquivalent}`;
tossFaceImg.alt = `Toss Face ${tossFaceEquivalent}`;
tossFaceCell.appendChild(tossFaceImg);
} else {
tossFaceCell.textContent = "No Match";
}
row.appendChild(tossFaceCell);
const notoCell = document.createElement("td");
const notoUnicode = getUnicodeFromFilename(twemojiFile);
notoCell.classList.add("noto-emoji");
notoCell.textContent = notoUnicode;
row.appendChild(notoCell);
const openMojiCell = document.createElement("td");
if (isOpenMojiMatch) {
const openMojiImg = document.createElement("img");
openMojiImg.src = `https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/color/72x72/${openMojiEquivalent}`;
openMojiImg.alt = `OpenMoji ${openMojiEquivalent}`;
openMojiCell.appendChild(openMojiImg);
} else {
openMojiCell.textContent = "No Match";
}
row.appendChild(openMojiCell);
const defaultCell = document.createElement("td");
defaultCell.textContent = notoUnicode;
row.appendChild(defaultCell);
tbody.appendChild(row);
});
} catch (error) {
console.error("Error fetching emoji data:", error);
}
}
let currentIndex = 0;
window.addEventListener("load", () => {
populateEmojiTable(currentIndex);
currentIndex += CHUNK_SIZE;
});
window.addEventListener("scroll", () => {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
populateEmojiTable(currentIndex);
currentIndex += CHUNK_SIZE;
}
});
</script>
</body>
</html>