-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
249 lines (222 loc) · 6.17 KB
/
index.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>IP address to emoji</title>
<meta name="description" content="This project uses a hand picked list of visually distinct emoji, which corelate to numbers 0 through 255, to represent IP addresses.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="ip.js"></script>
<script src="https://unpkg.com/twemoji@11/2/twemoji.min.js" crossorigin="anonymous"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<style>
html,
body {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
margin: 0;
font-family: 'Roboto', sans-serif;
text-align: center;
}
body > * {
margin-left: auto;
margin-right: auto;
}
h1 {
margin-top: 30vh;
}
p {
max-width: 630px;
display: block;
}
#input {
width: 90%;
min-height: 60px;
max-width: 700px;
border: 1px dashed #1AA0CC;
box-shadow: 0px 0px 2px #1AA0CC;
border-radius: 7px;
padding: 5px;
text-align: center;
background-color: #B4ECFF;
opacity: 0.9;
color: #111;
font-family: monospace;
white-space: pre;
overflow-y: auto;
font-size: 338%;
outline: none;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
vertical-align: middle;
}
.buttons {
margin: 20px 0;
}
button {
color: #fff;
background-color: #f09f2b;
border-radius: 10px;
font-weight: 700;
transition: background-color .3s ease;
line-height: 20px;
padding: 10px 15px;
cursor: pointer;
border: none;
outline: none;
}
.emoji {
width: 30px;
margin: 0 10px;
}
.ipv6 .emoji {
width: 25px;
margin: 0 2px;
}
@media (max-width: 768px) {
#input {
font-size: 125% !important;
}
.ipv6 .emoji {
width: 20px;
margin: 0;
}
}
#emojiContainer {
max-width: 700px;
width: 100%;
flex-wrap: wrap;
margin-top: 20vh;
text-align: center;
}
#emojiContainer > div {
margin: 0.5rem;
display: inline-block;
box-shadow: 0px 0px 2px #1AA0CC;
border-radius: 7px;
padding: 5px;
text-align: center;
background-color: #edfaff;
}
.footer {
margin-top: 2rem;
}
</style>
</head>
<body>
<h1>IP address to <em>EMOJI</em></h1>
<p style="margin-top: -1rem;">by <a href="https://www.6connect.com/">6connect</a></p>
<div contenteditable="true" data-gramm="false" id="input" class="whats-my-ip"></div>
<div class="buttons">
<button onclick="ipEncode()" style="background: #007bb8;">Encode</button>
<button onclick="ipParse()">Parse</button>
</div>
<p>
This project uses a hand picked list of visually distinct emoji, which corelate to numbers 0 through 255, to represent IP addresses.
</p>
<div class="footer">
<a href="https://github.com/6connect/ip-address-emoji">Source code</a>
<a href="https://www.6connect.com/resources/how-to-view-ip-addresses-as-emojis/">About this project</a>
</div>
<div id="emojiContainer"></div>
<script>
const emojiConf = {base: 'https://cdnjs.cloudflare.com/ajax/libs/twemoji/11.3.0/2/'};
const input = document.getElementById('input');
const checkWidth = () => {
if (input.textContent.match(':') !== null) {
input.style.fontSize = "150%";
input.classList.add('ipv6');
} else {
input.style.fontSize = "338%";
input.classList.remove('ipv6');
}
}
const ipEncode = () => {
let string = '';
for (let index = 0; index < input.childNodes.length; index++) {
if (input.childNodes[index].alt) string += input.childNodes[index].alt;
else string += input.childNodes[index].textContent;
}
input.innerHTML = twemoji.parse(ipemotes.encode(string), emojiConf);
checkWidth();
}
const ipParse = () => {
let string = '';
for (let index = 0; index < input.childNodes.length; index++) {
if (input.childNodes[index].alt) string += input.childNodes[index].alt;
else string += input.childNodes[index].textContent;
}
input.textContent = ipemotes.parse(string);
checkWidth();
}
input.addEventListener('keydown', checkWidth);
input.addEventListener('keyup', checkWidth);
input.addEventListener('click', checkWidth);
input.addEventListener('change', checkWidth);
/*
Script to track ipv6 usage vs ipv4
*/
try {
const ipv6FillInIp = (ip) => {
// Fills in the IP address if an element has the class name '6connect-whats-my-ip'
const elements = document.body.querySelectorAll('.whats-my-ip');
const elements2 = document.body.querySelectorAll('.whats-my-ip__container');
for (let index = 0; index < elements.length; index++) {
const element = elements[index];
element.textContent = ip;
}
checkWidth();
for (let index = 0; index < elements2.length; index++) {
const element = elements2[index];
element.classList.add('whats-my-ip--active');
if (ip.indexOf(':') > 0) {
element.classList.add('whats-my-ip--ipv6');
}
}
}
try {
fetch('https://ipv6.opl.io/?screen=' + window.innerWidth)
.then(
function (response) {
if (response.status !== 200) {
return;
}
response.json().then(function (data) {
ipv6FillInIp(data.yourIp);
var sparkleMe = document.querySelectorAll('.sparkleMe');
if (sparkleMe.length > 0) {
for (var i = 0; i < sparkleMe.length; i++) {
insertSparkle(sparkleMe[i]);
}
}
});
}
)
.catch(function (err) {
// IPv4 fetch failed
});
} catch (e) {
// Fetch will fail silently on older browsers
}
} catch (e) {
//fail silently on older browsers
}
const emojiContainer = document.getElementById('emojiContainer');
for (let index = 0; index < ipemotes.emojis.length; index++) {
const emoji = ipemotes.emojis[index];
const container = document.createElement('div');
container.textContent = index + ":";
container.innerHTML += twemoji.parse(emoji, emojiConf);
emojiContainer.appendChild(container);
}
</script>
</body>
</html>