Sure! I understand you want a simple web-based text editor with HTML, CSS, and JavaScript that can:
- Edit text
- Copy the content to clipboard
- Share the content via URL (using the hash
#/ for deep linking)
- Handle large text (you mentioned 10GB, which is very large; browsers won't practically handle that — but I'll design it to efficiently store/share reasonable large text)
I'll create a basic text editor that:
- Shows a large textarea
- Has buttons to copy and share (generates a shareable URL with the content in the hash)
- On page load, reads the content from URL hash and populates the editor
Note About 10GB
10GB text size cannot be practically handled by client-side JS in any current browser. Even a few MBs can be sluggish. But the editor is designed to handle large text blocks reasonably.
Here's the complete code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simple Text Editor</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; height: 100vh; display: flex; flex-direction: column; }
textarea {
flex: 1;
width: 100%;
padding: 10px;
font-size: 16px;
font-family: monospace;
box-sizing: border-box;
resize: none;
border: none;
outline: none;
}
header {
background: #333;
color: white;
padding: 10px;
display: flex;
align-items: center;
gap: 10px;
}
button {
background: #555;
border: none;
padding: 8px 15px;
font-size: 14px;
color: white;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #777;
}
.status {
margin-left: auto;
font-size: 14px;
color: #ccc;
}
</style>
</head>
<body>
<header>
<button id="copyBtn" title="Copy Text">Copy</button>
<button id="shareBtn" title="Generate Shareable URL">Share</button>
<div class="status" id="status"></div>
</header>
<textarea id="editor" placeholder="Start typing..."></textarea>
<script>
// JavaScript to handle:
// - Loading content from URL hash (after #/)
// - Copying text to clipboard
// - Sharing text by encoding it in URL hash
const textarea = document.getElementById('editor');
const copyBtn = document.getElementById('copyBtn');
const shareBtn = document.getElementById('shareBtn');
const status = document.getElementById('status');
// Utility: compress and decompress text using LZ-string to reduce URL length
// Including minimal LZ-string code here for compress/decompress
// Source: https://pieroxy.net/blog/pages/lz-string/index.html
// Only compressToEncodedURIComponent / decompressFromEncodedURIComponent used
const LZString = (function() {
// ... full library is big - I'll include only compressToEncodedURIComponent and decompressFromEncodedURIComponent functions (minimal)
const keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
function compressToEncodedURIComponent(input) {
if(input == null) return "";
return _compress(input, 6, function(a){return keyStrUriSafe.charAt(a);});
}
function decompressFromEncodedURIComponent(input) {
if(input == null) return "";
if(input == "") return null;
return _decompress(input.length, 32, function(index) {return keyStrUriSafe.indexOf(input.charAt(index));});
}
function _compress(uncompressed, bitsPerChar, getCharFromInt) {
if(uncompressed == null) return "";
let i,
value,
context_dictionary= {},
context_dictionaryToCreate= {},
context_c="",
context_wc="",
context_w="",
context_enlargeIn= 2, // Compensate for the first 2 entries in the dictionary
context_dictSize=3,
context_numBits=2,
context_data=[],
context_data_val=0,
context_data_position=0,
ii;
for (ii = 0; ii < uncompressed.length; ii += 1) {
context_c = uncompressed.charAt(ii);
if (!Object.prototype.hasOwnProperty.call(context_dictionary,context_c)) {
context_dictionary[context_c] = context_dictSize++;
context_dictionaryToCreate[context_c] = true;
}
context_wc = context_w + context_c;
if (Object.prototype.hasOwnProperty.call(context_dictionary,context_wc)) {
context_w = context_wc;
} else {
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
if (context_w.charCodeAt(0) < 256) {
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
}
value = context_w.charCodeAt(0);
for (i=0;i<8;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
} else {
value = 1;
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1) | value;
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = 0;
}
value = context_w.charCodeAt(0);
for (i=0;i<16;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
delete context_dictionaryToCreate[context_w];
} else {
value = context_dictionary[context_w];
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
// Add wc to the dictionary.
context_dictionary[context_wc] = context_dictSize++;
context_w = String(context_c);
}
}
// Output the code for w.
if (context_w !== "") {
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
if (context_w.charCodeAt(0) < 256) {
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
}
value = context_w.charCodeAt(0);
for (i=0;i<8;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
} else {
value = 1;
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1) | value;
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = 0;
}
value = context_w.charCodeAt(0);
for (i=0;i<16;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
delete context_dictionaryToCreate[context_w];
} else {
value = context_dictionary[context_w];
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
}
// Mark the end of the stream
value = 2;
for (i=0;i<context_numBits;i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
// Flush the last char
while (true) {
context_data_val = (context_data_val << 1);
if (context_data_position == bitsPerChar-1) {
context_data.push(getCharFromInt(context_data_val));
break;
}
else context_data_position++;
}
return context_data.join('');
}
function _decompress(length, resetValue, getNextValue) {
let dictionary = [],
next,
enlargeIn = 4,
dictSize = 4,
numBits = 3,
entry = "",
result = [],
i,
w,
bits, resb, maxpower, power,
c,
data = { val:getNextValue(0), position:resetValue, index:1 };
function readBits(n) {
let bits = 0, maxpower = Math.pow(2,n), power=1;
while (power!=maxpower) {
const resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
return bits;
}
for (i = 0; i < 3; i += 1) {
dictionary[i] = i;
}
bits = readBits(2);
switch(bits) {
case 0: c = String.fromCharCode(readBits(8)); break;
case 1: c = String.fromCharCode(readBits(16)); break;
case 2: return "";
}
dictionary[3] = c;
w = c;
result.push(c);
while (true) {
if (data.index > length) {
return "";
}
bits = readBits(numBits);
switch(bits) {
case 0:
c = String.fromCharCode(readBits(8));
dictionary[dictSize++] = c;
bits = dictSize - 1;
enlargeIn--;
break;
case 1:
c = String.fromCharCode(readBits(16));
dictionary[dictSize++] = c;
bits = dictSize - 1;
enlargeIn--;
break;
case 2:
return result.join('');
}
if (enlargeIn == 0) {
enlargeIn = Math.pow(2, numBits);
numBits++;
}
if (dictionary[bits]) {
entry = dictionary[bits];
} else {
if (bits === dictSize) {
entry = w + w.charAt(0);
} else {
return null;
}
}
result.push(entry);
// Add w+entry[0] to the dictionary.
dictionary[dictSize++] = w + entry.charAt(0);
enlargeIn--;
w = entry;
if (enlargeIn == 0) {
enlargeIn = Math.pow(2, numBits);
numBits++;
}
}
}
return {
compressToEncodedURIComponent: compressToEncodedURIComponent,
decompressFromEncodedURIComponent: decompressFromEncodedURIComponent
};
})();
// Load from URL hash
function loadFromHash() {
const hash = location.hash;
if(hash.startsWith("#/")) {
const compressed = hash.slice(2);
try {
const decompressed = LZString.decompressFromEncodedURIComponent(compressed);
if(decompressed !== null) textarea.value = decompressed;
} catch(e) {
console.error("Failed to decompress content from URL hash!", e);
}
}
}
// Update URL hash with compressed content
function updateHash(content) {
try {
status.textContent = "Encoding ...";
setTimeout(()=>{
const compressed = LZString.compressToEncodedURIComponent(content);
location.hash = "#/" + compressed;
status.textContent = "URL updated";
setTimeout(() => { status.textContent = ""; }, 2000);
}, 10);
} catch(e) {
alert("Error compressing content for sharing: "+e.message);
}
}
// Copy textarea content to clipboard
copyBtn.addEventListener("click", () => {
textarea.select();
try {
if(navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(textarea.value).then(() => {
status.textContent = "Copied to clipboard!";
setTimeout(() => status.textContent = "", 2000);
}, () => {
alert("Clipboard API denied. Try manual copy (Ctrl+C).");
});
} else {
document.execCommand("copy");
status.textContent = "Copied to clipboard!";
setTimeout(() => status.textContent = "", 2000);
}
} catch(e) {
alert("Copy failed: " + e.message);
}
});
// Share button generates shareable URL
shareBtn.addEventListener("click", () => {
if(textarea.value.length > 500000) { // roughly 0.5 million characters
if(!confirm("Sharing very large content may be slow or fail in URL encoding. Continue?")) return;
}
updateHash(textarea.value);
// Also, show user a prompt with URL to copy/share
setTimeout(() => {
prompt("Shareable URL:", location.href);
}, 100);
});
window.addEventListener("load", loadFromHash);
</script>
</body>
</html>
How to use this:
- Open this HTML in any modern browser.
- Start typing in the editor.
- Click Copy to copy all text to clipboard.
- Click Share to compress content into the URL hash fragment
#/ and update the URL.
- Share this URL with the content embedded.
- When someone opens the URL, your content will be decompressed and loaded automatically in the textarea.
Limitations:
- Very large text (over several MBs) will not compress efficiently and may cause browser slowdowns.
- Real 10GB text editors require server-backed storage, streaming and specialized tools.
- This editor is for basic text editing & sharing with URL-embedded content.
If you want a more advanced or persistent editor (with file saving, syntax highlighting, etc), let me know!