-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-37-HTML-Escape-Unescape-Tool.html
More file actions
443 lines (382 loc) · 16.8 KB
/
tool-37-HTML-Escape-Unescape-Tool.html
File metadata and controls
443 lines (382 loc) · 16.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool 37 - HTML Escape Unescape Tool - Developer Toolbox</title>
<link rel="stylesheet" href="assets/core.css">
<style>
.split-view {
display: grid;
grid-template-columns: 1fr;
gap: 1.5rem;
margin-bottom: 2rem;
margin-top: 1rem;
}
@media (min-width: 900px) {
.split-view { grid-template-columns: 1fr 1fr; }
}
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.5rem;
}
textarea {
width: 100%;
height: 350px;
background: var(--bg-main);
color: var(--text-primary);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
padding: 1rem;
font-family: var(--font-mono);
font-size: 14px;
resize: vertical;
}
.controls {
display: flex;
gap: 1rem;
align-items: center;
justify-content: center;
margin: 1rem 0;
padding: 1rem;
background: rgba(255,255,255,0.05);
border-radius: var(--radius-md);
}
.swap-btn {
background: var(--primary-color);
color: white;
border: none;
width: 50px;
height: 50px;
border-radius: 50%;
font-size: 1.5rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.3s;
}
.swap-btn:hover {
transform: scale(1.1) rotate(180deg);
}
.ref-table-container {
margin-top: 2rem;
background: var(--bg-main);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
overflow: hidden;
}
.ref-table-header {
background: rgba(255,255,255,0.05);
padding: 1rem;
font-weight: bold;
border-bottom: 1px solid var(--border-color);
}
.ref-table {
width: 100%;
border-collapse: collapse;
}
.ref-table th, .ref-table td {
padding: 0.8rem;
text-align: left;
border-bottom: 1px solid rgba(255,255,255,0.05);
}
.ref-table th {
color: var(--text-secondary);
font-size: 0.9rem;
}
.ref-table td {
font-family: var(--font-mono);
}
.ref-table td.char {
font-size: 1.2rem;
text-align: center;
font-family: var(--font-main);
}
.toast {
position: fixed;
bottom: 20px;
right: 20px;
background: var(--primary-color);
color: white;
padding: 10px 20px;
border-radius: var(--radius-sm);
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
z-index: 1000;
}
</style>
</head>
<body class="theme-dark">
<div class="tool-canvas-container" id="canvas-container"></div>
<main class="main-content">
<div class="container">
<div class="tool-header">
<div>
<a href="index.html" class="back-link">← Back to Toolbox</a>
<h1>37. HTML Escape Unescape Tool</h1>
</div>
<div>
<select id="theme-select" aria-label="Select Theme">
<option value="dark">Dark Theme</option>
<option value="light">Light Theme</option>
<option value="solarized">Solarized</option>
<option value="neon">Neon Glow</option>
<option value="highcontrast">High Contrast</option>
</select>
</div>
</div>
<div class="glass-panel">
<div class="controls">
<span style="color: var(--text-secondary); font-weight: bold;" id="mode-text">Mode: Escape HTML</span>
<button class="swap-btn" id="swap-btn" title="Swap Mode">⇄</button>
</div>
<div class="split-view">
<div>
<div class="toolbar">
<label style="font-weight: bold; color: var(--text-secondary);" id="input-label">Unescaped HTML (Input)</label>
<button class="btn btn-sm" id="clear-btn">Clear</button>
</div>
<textarea id="input-area" placeholder="Enter text here..."></textarea>
</div>
<div>
<div class="toolbar">
<label style="font-weight: bold; color: var(--text-secondary);" id="output-label">Escaped HTML (Output)</label>
<button class="btn btn-sm btn-primary" id="copy-btn">Copy Output</button>
</div>
<textarea id="output-area" readonly placeholder="Result will appear here..."></textarea>
</div>
</div>
<div class="ref-table-container">
<div class="ref-table-header">Common HTML Character References</div>
<table class="ref-table">
<thead>
<tr>
<th style="text-align: center;">Character</th>
<th>Name</th>
<th>Entity Name</th>
<th>Decimal</th>
<th>Hex</th>
</tr>
</thead>
<tbody>
<tr><td class="char">&</td><td>Ampersand</td><td>&amp;</td><td>&#38;</td><td>&#x26;</td></tr>
<tr><td class="char"><</td><td>Less than</td><td>&lt;</td><td>&#60;</td><td>&#x3C;</td></tr>
<tr><td class="char">></td><td>Greater than</td><td>&gt;</td><td>&#62;</td><td>&#x3E;</td></tr>
<tr><td class="char">"</td><td>Double quote</td><td>&quot;</td><td>&#34;</td><td>&#x22;</td></tr>
<tr><td class="char">'</td><td>Single quote / Apostrophe</td><td>&apos;</td><td>&#39;</td><td>&#x27;</td></tr>
<tr><td class="char">©</td><td>Copyright</td><td>&copy;</td><td>&#169;</td><td>&#xA9;</td></tr>
<tr><td class="char">®</td><td>Registered trademark</td><td>&reg;</td><td>&#174;</td><td>&#xAE;</td></tr>
<tr><td class="char">€</td><td>Euro sign</td><td>&euro;</td><td>&#8364;</td><td>&#x20AC;</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="toast" class="toast">Copied to clipboard!</div>
</main>
<footer class="global-footer">
<div class="container">
Made with ❤️ by <a href="https://github.com/Aliriyaj007" target="_blank">Aliriyaj007</a>
</div>
</footer>
<script src="assets/core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script>
const inputArea = document.getElementById('input-area');
const outputArea = document.getElementById('output-area');
const clearBtn = document.getElementById('clear-btn');
const copyBtn = document.getElementById('copy-btn');
const swapBtn = document.getElementById('swap-btn');
const modeText = document.getElementById('mode-text');
const inputLabel = document.getElementById('input-label');
const outputLabel = document.getElementById('output-label');
const toast = document.getElementById('toast');
let isEscapeMode = true;
const escapeHtml = (text) => {
const map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return text.replace(/[&<>"']/g, (m) => map[m]);
};
const unescapeHtml = (text) => {
// Use browser DOM for robust unescaping (handles named and numeric entities)
const doc = new DOMParser().parseFromString(text, "text/html");
return doc.documentElement.textContent;
};
const processText = () => {
const val = inputArea.value;
if(!val) {
outputArea.value = '';
if(window.update3DMasks) window.update3DMasks(false); // Idle
return;
}
if (isEscapeMode) {
outputArea.value = escapeHtml(val);
if(window.update3DMasks) window.update3DMasks(true, true); // Putting on mask
} else {
outputArea.value = unescapeHtml(val);
if(window.update3DMasks) window.update3DMasks(true, false); // Taking off mask
}
};
swapBtn.addEventListener('click', () => {
isEscapeMode = !isEscapeMode;
if(isEscapeMode) {
modeText.textContent = 'Mode: Escape HTML';
inputLabel.textContent = 'Unescaped HTML (Input)';
outputLabel.textContent = 'Escaped HTML (Output)';
if(window.setSystemState) window.setSystemState('escape');
} else {
modeText.textContent = 'Mode: Unescape HTML';
inputLabel.textContent = 'Escaped HTML (Input)';
outputLabel.textContent = 'Unescaped HTML (Output)';
if(window.setSystemState) window.setSystemState('unescape');
}
// Swap Contents
const currentOutput = outputArea.value;
inputArea.value = currentOutput;
processText();
});
inputArea.addEventListener('input', processText);
clearBtn.addEventListener('click', () => {
inputArea.value = '';
processText();
});
copyBtn.addEventListener('click', () => {
if(!outputArea.value) return;
navigator.clipboard.writeText(outputArea.value);
toast.style.opacity = '1';
setTimeout(() => toast.style.opacity = '0', 2000);
});
// 3D Visualization: Characters that put on/remove masks
let scene, camera, renderer, charGroup, maskGroup;
function init3D() {
const container = document.getElementById('canvas-container');
if(!container || !window.THREE) return;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 0, 10);
camera.lookAt(0, 0, 0);
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(5, 5, 5);
scene.add(dirLight);
// Container for the character
const mainContainer = new THREE.Group();
scene.add(mainContainer);
// The "Character" (a blocky stylized person)
charGroup = new THREE.Group();
const headGeo = new THREE.BoxGeometry(1.5, 1.5, 1.5);
const bodyMat = new THREE.MeshPhongMaterial({ color: 0xcccccc });
const head = new THREE.Mesh(headGeo, bodyMat);
head.position.y = 2;
charGroup.add(head);
// Eyes
const eyeGeo = new THREE.BoxGeometry(0.2, 0.2, 0.1);
const eyeMat = new THREE.MeshBasicMaterial({ color: 0x111111 });
const eyeL = new THREE.Mesh(eyeGeo, eyeMat);
eyeL.position.set(-0.3, 2.2, 0.8);
const eyeR = new THREE.Mesh(eyeGeo, eyeMat);
eyeR.position.set(0.3, 2.2, 0.8);
charGroup.add(eyeL);
charGroup.add(eyeR);
const bodyGeo = new THREE.BoxGeometry(2, 2.5, 1);
const body = new THREE.Mesh(bodyGeo, bodyMat);
body.position.y = 0;
charGroup.add(body);
mainContainer.add(charGroup);
// The "Mask" (Entity form)
maskGroup = new THREE.Group();
const maskShape = new THREE.Shape();
maskShape.moveTo(-0.9, 0.9);
maskShape.lineTo(0.9, 0.9);
maskShape.lineTo(0.6, -0.9);
maskShape.lineTo(0, -1.2);
maskShape.lineTo(-0.6, -0.9);
maskShape.lineTo(-0.9, 0.9);
const extSettings = { depth: 0.2, bevelEnabled: true, bevelSegments: 1, steps: 1, bevelSize: 0.1, bevelThickness: 0.05 };
const mGeo = new THREE.ExtrudeGeometry(maskShape, extSettings);
mGeo.center();
const mMat = new THREE.MeshPhongMaterial({ color: 0xffaa00, shininess: 100 });
const maskBase = new THREE.Mesh(mGeo, mMat);
maskGroup.add(maskBase);
// Mask details (e.g. glowing eyes or text symbol)
const mEyeL = new THREE.Mesh(eyeGeo, new THREE.MeshBasicMaterial({ color: 0xffffff }));
mEyeL.position.set(-0.3, 0.2, 0.15);
const mEyeR = new THREE.Mesh(eyeGeo, new THREE.MeshBasicMaterial({ color: 0xffffff }));
mEyeR.position.set(0.3, 0.2, 0.15);
maskGroup.add(mEyeL);
maskGroup.add(mEyeR);
maskGroup.position.set(0, 2, 2); // default floating in front
mainContainer.add(maskGroup);
mainContainer.position.set(3, 0, 0);
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
}
let targetMaskZ = 0.8; // On face
let currentMaskZ = 0.8;
let isSystemEscape = true;
let isTyping = false;
let typingTimeout;
window.setSystemState = (state) => {
isSystemEscape = (state === 'escape');
targetMaskZ = isSystemEscape ? 0.8 : 2.5; // Face vs Floating
};
window.update3DMasks = (active, puttingOn) => {
if(!maskGroup) return;
isTyping = active;
clearTimeout(typingTimeout);
typingTimeout = setTimeout(() => { isTyping = false; }, 500);
// puttingOn = true means text is being escaped -> mask moves to face
// puttingOn = false means text is unescaped -> mask moves away
if(active) {
targetMaskZ = puttingOn ? 0.8 : 2.5;
}
};
function animate() {
requestAnimationFrame(animate);
if(maskGroup) {
// Animate mask position
currentMaskZ += (targetMaskZ - currentMaskZ) * 0.1;
maskGroup.position.z = currentMaskZ;
// Bobbing animation
if(!isTyping) {
charGroup.parent.position.y = Math.sin(Date.now() * 0.002) * 0.1;
charGroup.parent.rotation.y = Math.sin(Date.now() * 0.001) * 0.15;
} else {
// Shaking slightly when typing
charGroup.parent.position.y = (Math.random() - 0.5) * 0.05;
}
// Rotate mask slightly if it's floating
if(targetMaskZ > 1.5) {
maskGroup.rotation.y = Math.sin(Date.now() * 0.003) * 0.3;
maskGroup.position.y = 2 + Math.sin(Date.now() * 0.004) * 0.2;
} else {
maskGroup.rotation.y = 0;
maskGroup.position.y = 2; // Locked to head
}
}
renderer.render(scene, camera);
}
document.addEventListener('DOMContentLoaded', () => {
init3D();
processText(); // initial state
});
</script>
</body>
</html>