forked from BurninLeo/see-non-printable-characters
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
455 lines (390 loc) · 14.1 KB
/
index.html
File metadata and controls
455 lines (390 loc) · 14.1 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detect Homoglyphs & Hidden Unicode Characters</title>
<style type="text/css">
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #1f1f1f;
margin: 0;
padding: 20px;
min-height: 100vh;
color: #e8e8e8;
}
div.main {
background: #2d2d2d;
border-radius: 16px;
border: 1px solid #4d4d4d;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
padding: 2.4em 3em;
margin: 0 auto;
max-width: 1000px;
}
div.output {
margin: 1em 0;
border: 1px solid #4d4d4d;
border-radius: 8px;
padding: 1em;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
cursor: default;
background: #232323;
line-height: 1.6;
}
/* Character styling */
div.output span.symbol,
div.output span.whitespace-all,
div.output span.whitespace,
div.output span.non-typable {
border-radius: 4px;
margin: 0 2px;
padding: 2px 6px;
transition-property: background, color, padding, opacity;
transition-duration: 0.25s;
transition-timing-function: ease-in-out;
}
div.output span.symbol {
color: #2a2a2a;
background: #8b898b;
}
div.output span.whitespace-all {
color: #2a2a2a;
background: #bae1ff;
}
div.output span.whitespace {
color: #2a2a2a;
background: #8b898b;
}
div.output span.non-typable {
color: #2a2a2a;
background: #e8a966;
transition-property: background, color, padding, opacity;
transition-duration: 0.25s;
transition-timing-function: ease-in-out;
}
div.output span.typable {
border-radius: 4px;
transition-property: background, color, padding;
transition-duration: 0.25s;
transition-timing-function: ease-in-out;
white-space: pre;
padding-top: 2px;
padding-bottom: 2px;
color: #e8e8e8;
}
div.output span.symbol:hover,
div.output span.whitespace-all:hover,
div.output span.whitespace:hover,
div.output span.non-typable:hover,
div.output span.typable:hover {
background: #ff8f8f;
color: #2a2a2a;
}
/* Tooltip styling */
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
opacity: 0;
position: absolute;
left: 50%;
transform: translateX(-50%) translateY(10px);
padding: 3px 9px;
color: #e8e8e8;
background: rgba(124, 74, 74, 0.61);
backdrop-filter: blur(10px);
border: 1px solid #e7b5b5;
border-radius: 8px;
font-weight: 500;
text-align: left;
z-index: 1000;
white-space: pre;
font-size: 14px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
transition: all 0.25s cubic-bezier(.65,.05,.36,1);
pointer-events: none;
height: max-content;
bottom: 30px;
line-height: 1;
}
div.output span.symbol:hover ~ .tooltiptext,
div.output span.whitespace-all:hover ~ .tooltiptext,
div.output span.whitespace:hover ~ .tooltiptext,
div.output span.non-typable:hover ~ .tooltiptext,
div.output span.typable:hover ~ .tooltiptext {
opacity: 1;
bottom: 40px;
}
/* Form styling */
textarea {
border: 1px solid #4d4d4d;
border-radius: 8px;
padding: 12px;
background: #252525;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
resize: vertical;
color: #e8e8e8;
width: 100%;
box-sizing: border-box;
}
textarea:focus {
outline: none;
box-shadow: 0 0 5px #5447ca;
border-color: #a5b5d4;
}
textarea::placeholder {
color: #a0a0a0;
}
/* Controls styling */
.controls {
display: flex;
gap: 15px;
align-items: center;
margin: 1em 0;
padding: 12px;
background: #373737;
border-radius: 8px;
border: 1px solid #4d4d4d;
flex-wrap: wrap;
}
.checkbox-container {
display: flex;
align-items: center;
gap: 8px;
flex: 1;
}
.checkbox-container input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: #818cf8;
flex: 0;
}
.checkbox-container label {
color: #e0e0e0;
font-size: 14px;
cursor: pointer;
}
.copy-button {
background: #5447ca;
color: #e8e8e8;
border: none;
padding: 8px 16px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: background 0.2s ease;
flex-shrink: 1;
}
.copy-button:hover {
background: #6366f1;
}
.copy-button:active {
background: #4338ca;
}
.copy-button.success {
background: #2c864f;
}
/* Stats styling */
#stats {
color: #b5b5b5;
font-size: 14px;
font-weight: 500;
padding: 8px 12px;
background: #373737;
border-radius: 8px;
border: 1px solid #4d4d4d;
margin: 1em 0;
}
/* Headings */
h1 {
color: #f5f5f5;
font-weight: 600;
margin-bottom: 0.5em;
}
h2 {
color: #e0e0e0;
font-weight: 600;
margin-top: 2em;
}
/* Links */
a {
color: #818cf8;
text-decoration: none;
}
a:hover {
color: #a5b4fc;
text-decoration: underline;
}
/* List styling */
ul {
padding-left: 1.5em;
}
li {
margin-bottom: 0.5em;
color: #e0e0e0;
}
p {
color: #e0e0e0;
line-height: 1.6;
}
/* Grayed out styling for removed characters */
.removed {
opacity: 0.3;
text-decoration: line-through dotted;
}
</style>
</head>
<body>
<div class="main">
<h1>Detect Homoglyphs & Hidden Unicode Characters</h1>
<p>Online tool to display <a href="https://maxhalford.github.io/blog/homoglyphs/" target="_blank">homoglyph</a> and non-printable characters that may be hidden in copy & pasted strings.</p>
<div>
<textarea id="inputText" rows="8" cols="40" dir="auto" placeholder="Paste your text here...">Letter Α and A aren't the same.
These whitespace characters differ in Unicode.
The word bee contains 4 characters.
The emoji 🕵🏻♂️ is a multibyte character composed of 14 UTF-8 bytes and represents 5 distinct Unicode codepoints.</textarea>
</div>
<div class="controls">
<button id="copyButton" class="copy-button">Copy (Sanitized)</button>
<div class="checkbox-container">
<input type="checkbox" id="removeSpacesOnly" />
<label for="removeSpacesOnly">Remove only non-standard whitespace</label>
</div>
</div>
<div id="output"></div>
<div id="stats"></div>
<h2>Helpful Sites for Details on UTF Characters</h2>
<ul>
<li><a href="https://www.mclean.net.nz/ucf/" target="_blank"><mclean.net.nz> Unicode Character Finder</a></li>
<li><a href="https://r12a.github.io/app-conversion/" target="_blank"><r12a.github.io> Unicode Converter</a></li>
<li><a href="https://poppycocker.github.io/UnicodeFinder/" target="_blank"><poppycocker.github.io> Unicode Character Finder</a></li>
<li><a href="https://www.branah.com/unicode-converter" target="_blank"><branah.com> Unicode Converter</a></li>
<li><a href="http://www.fileformat.info/info/unicode/char/search.htm" target="_blank"><fileformat.Info> Unicode Character Search</a></li>
<li><a href="http://utf8-chartable.de/unicode-utf8-table.pl" target="_blank"><utf8-chartable.de> UTF-8 Encoding Table & Unicode Characters</a></li>
</ul>
<h2>Privacy Notice</h2>
<p>Your privacy is fully protected on this site. All text is processed locally in your browser and never leaves your device. No personal information is collected, no data is stored and no cookies or tracking tools are used.</p>
<h2>Source Code</h2>
<p>This site is a fork of the original tool from <a href="https://github.com/BurninLeo/see-non-printable-characters">soscisurvey.de</a>. The source code is available on <a href="https://github.com/0Ky/see-non-printable-characters">GitHub</a>.</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const textarea = document.getElementById('inputText');
const output = document.getElementById('output');
const stats = document.getElementById('stats');
const copyButton = document.getElementById('copyButton');
const removeSpacesOnlyCheckbox = document.getElementById('removeSpacesOnly');
function getCharCode(char) {
return char.codePointAt(0);
}
function getByteLength(str) {
return new TextEncoder().encode(str).length;
}
function isTypableOnUSKeyboard(char) {
// includes tab, newline & carriage return
const US_KEYBOARD_TYPABLE = /^[\x09\x0A\x0D\x20-\x7E]$/;
return US_KEYBOARD_TYPABLE.test(char);
}
function isSpaceChar(char) {
// Check if it's a Unicode space character (excluding normal space U+0020)
return /^(?!\u0020)[\p{Z}\p{Cf}]$/u.test(char);
}
function createTooltip(char, symbol) {
const code = getCharCode(char);
const utf8Bytes = new TextEncoder().encode(char);
const utf8Hex = Array.from(utf8Bytes).map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
const codepoint = `U+${code.toString(16).padStart(4, '0').toUpperCase()}`;
const desc = `${'UTF-8'.padStart(9)}: ${utf8Hex}\n${'Decimal'.padStart(9)}: ${code}\n${'Codepoint'}: ${codepoint}`;
return `<span class="tooltip">${symbol}<span class="tooltiptext">${desc}</span></span>`;
}
function processChar(char) {
const code = getCharCode(char);
const hex = `U+${code.toString(16).toUpperCase().padStart(4, '0')}`;
if (char === '\r') {
return createTooltip(char, '<span class="symbol">CR</span>');
} else if (char === '\n') {
return createTooltip(char, '<span class="symbol">LF</span>');
} else if (char === '\t') {
return createTooltip(char, '<span class="symbol">⟶</span>');
} else if (char === '\u0020') {
return createTooltip(char, '<span class="whitespace">·</span>');
} else if (isSpaceChar(char)) {
return createTooltip(char, `<span class="whitespace-all removed">${hex}</span>`);
} else if (!isTypableOnUSKeyboard(char)) {
const nonTypableClass = removeSpacesOnlyCheckbox.checked ? "non-typable" : "non-typable removed";
return createTooltip(char, `<span class="${nonTypableClass}">${hex}</span>`);
} else {
return createTooltip(char, `<span class="typable">${char}</span>`);
}
}
function convertTextToHtml(text) {
let html = '<div class="output" dir="auto">';
for (let i = 0; i < text.length; i++) {
const char = text[i];
if (char === '\n') {
html += processChar(char) + '</br>';
} else {
html += processChar(char);
}
}
return html + '</div>';
}
function updateStats() {
const text = textarea.value;
const removeSpacesOnly = removeSpacesOnlyCheckbox.checked;
const charCount = text.length;
const byteCount = getByteLength(text);
const removedCount = document.querySelectorAll("#output span.removed").length
stats.textContent = `${charCount} characters, ${byteCount} bytes${removedCount > 0 ? ` (${removedCount} characters removed)` : ''}`;
}
function toggleRemoveSpaces() {
const removeSpacesOnly = removeSpacesOnlyCheckbox.checked;
const nonTypableChars = document.querySelectorAll("#output span.non-typable");
if (removeSpacesOnly) {
nonTypableChars.forEach(el => el.classList.remove("removed"));
} else {
nonTypableChars.forEach(el => el.classList.add("removed"));
}
updateStats();
}
function updateDisplay() {
const text = textarea.value;
const html = convertTextToHtml(text);
output.innerHTML = html;
updateStats();
}
async function copyToClipboard() {
const text = textarea.value;
const removeSpacesOnly = removeSpacesOnlyCheckbox.checked;
let cleanedText = '';
for (let i = 0; i < text.length; i++) {
const char = text[i];
// Always remove space characters (Unicode spaces except normal space)
if (isSpaceChar(char)) {
continue;
}
// Also remove non-typable characters if checkbox unchecked
if (!removeSpacesOnly && !isTypableOnUSKeyboard(char)) {
continue;
}
cleanedText += char;
}
await navigator.clipboard.writeText(cleanedText);
copyButton.textContent = 'Copied!';
copyButton.classList.add('success');
setTimeout(() => {
copyButton.textContent = 'Copy (Sanitized)';
copyButton.classList.remove('success');
}, 2000);
}
textarea.addEventListener('input', updateDisplay);
copyButton.addEventListener('click', copyToClipboard);
removeSpacesOnlyCheckbox.addEventListener('change',toggleRemoveSpaces);
updateDisplay();
});
</script>
</body>
</html>