225 lines
6.9 KiB
HTML
225 lines
6.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>String Tools</title>
|
|
<style>
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
}
|
|
body {
|
|
background-color: #f4f6f8;
|
|
color: #333;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
.container {
|
|
background: #ffffff;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
|
|
padding: 30px;
|
|
width: 100%;
|
|
max-width: 650px;
|
|
}
|
|
h2 {
|
|
margin-bottom: 20px;
|
|
font-size: 1.5rem;
|
|
text-align: center;
|
|
}
|
|
.input-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
label {
|
|
display: block;
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
margin-bottom: 6px;
|
|
}
|
|
textarea {
|
|
width: 100%;
|
|
height: 100px;
|
|
padding: 12px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 6px;
|
|
font-size: 0.95rem;
|
|
resize: vertical;
|
|
background-color: #fafafa;
|
|
}
|
|
textarea:focus {
|
|
outline: none;
|
|
border-color: #0066ff;
|
|
background-color: #fff;
|
|
}
|
|
.output-card {
|
|
background-color: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 6px;
|
|
padding: 12px;
|
|
margin-bottom: 12px;
|
|
}
|
|
.output-card.error {
|
|
border-color: #ffc9c9;
|
|
background-color: #fff5f5;
|
|
}
|
|
.output-card .title {
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
color: #6c757d;
|
|
margin-bottom: 4px;
|
|
font-weight: 700;
|
|
}
|
|
.output-card .value {
|
|
font-family: monospace;
|
|
font-size: 0.95rem;
|
|
word-break: break-all;
|
|
white-space: pre-wrap;
|
|
color: #212529;
|
|
}
|
|
.value.error-text {
|
|
color: #d9534f;
|
|
font-style: italic;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<h2>String Tools</h2>
|
|
|
|
<div class="input-group">
|
|
<label for="strInput">Enter your string below:</label>
|
|
<textarea id="strInput" placeholder="Type or paste something here..."></textarea>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Character Count (Length)</div>
|
|
<div class="value" id="outLength">0</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Uppercase</div>
|
|
<div class="value" id="outUpper">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Lowercase</div>
|
|
<div class="value" id="outLower">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">URL Encoded</div>
|
|
<div class="value" id="outEncoded">---</div>
|
|
</div>
|
|
|
|
<div class="output-card" id="urlDecodedCard">
|
|
<div class="title">URL Decoded</div>
|
|
<div class="value" id="outDecoded">---</div>
|
|
</div>
|
|
|
|
<div class="output-card" id="b64EncCard">
|
|
<div class="title">Base64 Encoded</div>
|
|
<div class="value" id="outB64Enc">---</div>
|
|
</div>
|
|
|
|
<div class="output-card" id="b64DecCard">
|
|
<div class="title">Base64 Decoded</div>
|
|
<div class="value" id="outB64Dec">---</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const strInput = document.getElementById('strInput');
|
|
const outLength = document.getElementById('outLength');
|
|
const outUpper = document.getElementById('outUpper');
|
|
const outLower = document.getElementById('outLower');
|
|
const outEncoded = document.getElementById('outEncoded');
|
|
const outDecoded = document.getElementById('outDecoded');
|
|
const urlDecodedCard = document.getElementById('urlDecodedCard');
|
|
|
|
const outB64Enc = document.getElementById('outB64Enc');
|
|
const b64EncCard = document.getElementById('b64EncCard');
|
|
const outB64Dec = document.getElementById('outB64Dec');
|
|
const b64DecCard = document.getElementById('b64DecCard');
|
|
|
|
// Helper functions to handle Unicode safely in Base64 (UTF-8 support)
|
|
function utf8ToBase64(str) {
|
|
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => {
|
|
return String.fromCharCode('0x' + p1);
|
|
}));
|
|
}
|
|
|
|
function base64ToUtf8(str) {
|
|
return decodeURIComponent(atob(str).split('').map((c) => {
|
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
}).join(''));
|
|
}
|
|
|
|
strInput.addEventListener('input', () => {
|
|
const val = strInput.value;
|
|
|
|
if (val.length === 0) {
|
|
outLength.textContent = '0';
|
|
outUpper.textContent = '---';
|
|
outLower.textContent = '---';
|
|
outEncoded.textContent = '---';
|
|
outDecoded.textContent = '---';
|
|
outB64Enc.textContent = '---';
|
|
outB64Dec.textContent = '---';
|
|
|
|
urlDecodedCard.classList.remove('error');
|
|
b64EncCard.classList.remove('error');
|
|
b64DecCard.classList.remove('error');
|
|
return;
|
|
}
|
|
|
|
// String Length, Uppercase, Lowercase, URL Encoded
|
|
outLength.textContent = val.length;
|
|
outUpper.textContent = val.toUpperCase();
|
|
outLower.textContent = val.toLowerCase();
|
|
outEncoded.textContent = encodeURIComponent(val);
|
|
|
|
// URL Decoded
|
|
try {
|
|
outDecoded.textContent = decodeURIComponent(val);
|
|
outDecoded.classList.remove('error-text');
|
|
urlDecodedCard.classList.remove('error');
|
|
} catch (e) {
|
|
outDecoded.textContent = "Error: Invalid URL encoding sequence";
|
|
outDecoded.classList.add('error-text');
|
|
urlDecodedCard.classList.add('error');
|
|
}
|
|
|
|
// Base64 Encoded
|
|
try {
|
|
outB64Enc.textContent = utf8ToBase64(val);
|
|
outB64Enc.classList.remove('error-text');
|
|
b64EncCard.classList.remove('error');
|
|
} catch (e) {
|
|
outB64Enc.textContent = "Error encoding to Base64";
|
|
outB64Enc.classList.add('error-text');
|
|
b64EncCard.classList.add('error');
|
|
}
|
|
|
|
// Base64 Decoded
|
|
try {
|
|
outB64Dec.textContent = base64ToUtf8(val.trim());
|
|
outB64Dec.classList.remove('error-text');
|
|
b64DecCard.classList.remove('error');
|
|
} catch (e) {
|
|
outB64Dec.textContent = "Error: Invalid Base64 string";
|
|
outB64Dec.classList.add('error-text');
|
|
b64DecCard.classList.add('error');
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |