Certainly! Below is a simple but full-featured HTML/CSS/JS text editor you can use right in the browser. It supports:
- Unlimited characters (limited by your browser/memory)
- Copy the editor content to clipboard with one click
- Share the content encoded in the URL hash (after
#/), so you can reload or share the URL and your content is restored
- Basic styling for readability
Open this as an .html file and try it out!
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 Share & Copy</title>
<style>
body, html {
margin: 0; padding: 0; height: 100%;
font-family: monospace, monospace;
display: flex; flex-direction: column;
}
header {
background: #222;
color: #eee;
padding: 0.5em 1em;
display: flex; align-items: center; justify-content: space-between;
}
#editor {
flex-grow: 1;
width: 100%;
padding: 1em;
box-sizing: border-box;
border: none;
resize: none;
font-family: monospace, monospace;
font-size: 1rem;
line-height: 1.4em;
}
button {
background: #444;
border: none;
color: #eee;
padding: 0.5em 1em;
margin-left: 0.5em;
cursor: pointer;
font-size: 1rem;
border-radius: 3px;
transition: background-color 0.3s;
}
button:hover {
background: #666;
}
#status {
margin-left: 1em;
font-size: 0.9rem;
color: #aaa;
user-select: none;
}
@media (max-width: 500px) {
header {
flex-direction: column;
align-items: stretch;
gap: 0.5em;
}
#status {
margin-left: 0;
margin-top: 0.2em;
}
button {
width: 100%;
margin-left: 0;
}
}
</style>
</head>
<body>
<header>
<div>
<strong>Simple Text Editor</strong>
</div>
<div>
<button id="copyBtn" title="Copy All Text">Copy</button>
<button id="shareBtn" title="Generate Share Link">Share</button>
<span id="status"></span>
</div>
</header>
<textarea id="editor" spellcheck="false" placeholder="Start typing..."></textarea>
<script>
(function() {
const editor = document.getElementById('editor');
const copyBtn = document.getElementById('copyBtn');
const shareBtn = document.getElementById('shareBtn');
const status = document.getElementById('status');
// Helper: encode text -> URL safe base64
function encodeText(text) {
// UTF-8 encode string then base64
return btoa(unescape(encodeURIComponent(text)));
}
// Helper: decode text from URL safe base64 back to string
function decodeText(base64) {
try {
return decodeURIComponent(escape(atob(base64)));
} catch(e) {
return null;
}
}
// Load content from URL hash if present
function loadFromHash() {
if (location.hash.startsWith('#/')) {
const encoded = location.hash.slice(2);
const decoded = decodeText(encoded);
if (decoded !== null) {
editor.value = decoded;
setStatus('Content loaded from URL');
} else {
setStatus('Failed to decode content from URL');
}
}
}
// Save content to the hash in URL
function saveToHash() {
const encoded = encodeText(editor.value);
location.hash = '#/' + encoded;
}
// Copy editor content to clipboard
function copyToClipboard() {
navigator.clipboard.writeText(editor.value)
.then(() => setStatus('Copied to clipboard!'))
.catch(() => setStatus('Failed to copy'));
}
// Display a temporary status message
let statusTimeout;
function setStatus(msg) {
clearTimeout(statusTimeout);
status.textContent = msg;
if (msg) {
statusTimeout = setTimeout(() => {
status.textContent = '';
}, 3000);
}
}
// Event listeners
copyBtn.addEventListener('click', copyToClipboard);
shareBtn.addEventListener('click', () => {
saveToHash();
// Show the full URL so user can copy or share it easily
setStatus('Shareable URL updated in address bar. Copy URL to share!');
});
// Automatically restore content from URL on page load
window.addEventListener('load', loadFromHash);
// Optional: update URL in real-time as user types (commented because it may cause lag with huge text)
/*
editor.addEventListener('input', () => {
saveToHash();
});
*/
})();
</script>
</body>
</html>
How to use
- Open the file in your browser.
- Type or paste any text into the editor.
- Click Copy to copy it to clipboard.
- Click Share to encode the text into the URL hash. The URL will update (e.g.
yourfile.html#/...base64...).
- You can copy the URL and share it — opening it elsewhere restores the text.
Notes
- The content is encoded as Base64 in the URL hash - browsers allow quite a long URL but extremely huge text may cause issues.
- For huge texts, you can remove comment from the
input event code to automatically keep URL in sync.
- Clipboard API requires HTTPS or localhost to work in most browsers.
Let me know if you'd like enhancements or features like syntax highlighting, line numbers, or downloading!