Certainly! Below is a simple web-based text editor implemented with HTML, CSS, and JavaScript. It supports unlimited characters, allows you to copy the content, and has a shareable URL feature using a hash (#) to save and load the text content.
Features:
Large editable text area.
Unlimited characters (limited only by browser/system memory).
"Copy" button to copy all text to clipboard.
"Share" button to update the URL’s hash with the encoded text.
Automatically loads content from the URL hash when the page loads.
How it works:
When you click Share, it encodes the text and appends it to the URL after #.
Anyone visiting the URL will see the text already loaded.
Hash size might be limited by URL length restrictions in browsers (~2000 chars usually safe, but large texts may cause issues — for very large texts consider server-side solutions).
Code:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simple Text Editor with Shareable URL</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0; padding: 0; height: 100vh;
display: flex;
flex-direction: column;
}
header {
background: #333;
color: white;
padding: 0.5rem 1rem;
display: flex;
align-items: center;
gap: 1rem;
}
header h1 {
font-size: 1.25rem;
margin: 0;
flex-grow: 1;
}
button {
background: #555;
border: none;
color: white;
padding: 0.5rem 1rem;
cursor: pointer;
border-radius: 3px;
font-size: 1rem;
}
button:hover {
background: #777;
}
textarea {
flex-grow: 1;
width: 100%;
padding: 1rem;
box-sizing: border-box;
font-family: monospace;
font-size: 1rem;
line-height: 1.4;
border: none;
outline: none;
resize: none;
}
</style>
</head>
<body>
<header>
<h1>Text Editor</h1>
<button id="copyBtn" title="Copy all text">Copy</button>
<button id="shareBtn" title="Generate shareable URL">Share</button>
</header>
<textarea id="editor" placeholder="Start typing here..."></textarea>
<script>
const editor = document.getElementById('editor');
const copyBtn = document.getElementById('copyBtn');
const shareBtn = document.getElementById('shareBtn');
// Encode and decode helpers using base64 to keep URL safe
function encodeText(text) {
// encodeURIComponent first to preserve special chars, then Base64
return btoa(encodeURIComponent(text));
}
function decodeText(encoded) {
try {
return decodeURIComponent(atob(encoded));
} catch (e) {
return ''; // fallback on error
}
}
// Load text from URL hash if present
function loadFromHash() {
if(location.hash.length > 2) { // has at least "#x"
const encoded = location.hash.slice(1);
const decoded = decodeText(encoded);
editor.value = decoded;
}
}
// Update hash based on current text
function updateHash() {
try {
const encoded = encodeText(editor.value);
// Set the hash, adjusting URL without reloading the page
history.replaceState(null, null, '#' + encoded);
} catch (e) {
alert("Text too long to encode in URL.");
}
}
copyBtn.addEventListener('click', () => {
editor.select();
try {
const successful = document.execCommand('copy');
if(successful) {
copyBtn.textContent = 'Copied!';
setTimeout(() => copyBtn.textContent = 'Copy', 1500);
} else {
alert('Copy failed. Try manually selecting and copying.');
}
} catch {
alert('Copy failed. Try manually selecting and copying.');
}
window.getSelection().removeAllRanges();
});
shareBtn.addEventListener('click', () => {
updateHash();
shareBtn.textContent = 'URL Updated!';
setTimeout(() => shareBtn.textContent = 'Share', 1500);
});
window.addEventListener('load', () => {
loadFromHash();
});
// Optional: Update URL hash live while typing (comment if undesired)
/*
editor.addEventListener('input', () => {
updateHash();
});
*/
</script>
</body>
</html>
Usage:
Open this HTML file in a modern browser.
Type your text.
Click Copy to copy everything to clipboard.
Click Share to generate a link (in the URL bar) that you can copy and share; it will contain your text.
When someone opens the shared link, the text will load automatically.
Let me know if you want me to enhance this (e.g., markdown preview, autosave, or a larger limit)!