mirror of
https://github.com/PR0M3TH3AN/text_splitter.git
synced 2025-09-08 07:18:42 +00:00
update
This commit is contained in:
112
src/index.html
112
src/index.html
@@ -3,84 +3,74 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>eCash Text Splitter for Meshtastic</title>
|
<title>eCash Text Splitter & Reassembler</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
}
|
}
|
||||||
textarea {
|
h1, h2 {
|
||||||
width: 100%;
|
color: #333;
|
||||||
height: 100px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
}
|
||||||
.split-text {
|
p {
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.section {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
.split-text textarea {
|
.section p {
|
||||||
height: 60px;
|
margin: 0 0 10px;
|
||||||
}
|
}
|
||||||
.copy-btn {
|
.link-btn {
|
||||||
margin-top: 5px;
|
display: inline-block;
|
||||||
|
margin: 5px 0;
|
||||||
|
padding: 10px 15px;
|
||||||
|
font-size: 16px;
|
||||||
|
color: white;
|
||||||
|
background-color: #007bff;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
.repo-link {
|
.link-btn:hover {
|
||||||
margin-top: 20px;
|
background-color: #0056b3;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>eCash Text Splitter for Meshtastic</h1>
|
<h1>eCash Text Splitter & Reassembler</h1>
|
||||||
<p>Paste your eCash text below and click "Split Text" to divide it into smaller parts of up to 150 characters each, suitable for sending over Meshtastic.</p>
|
|
||||||
<textarea id="inputText" placeholder="Paste your eCash text here..."></textarea>
|
|
||||||
<button onclick="splitText()">Split Text</button>
|
|
||||||
<div id="output"></div>
|
|
||||||
|
|
||||||
<script>
|
<div class="section">
|
||||||
function splitText() {
|
<h2>How to Use the eCash Text Splitter</h2>
|
||||||
const maxLength = 150;
|
<p>This tool helps you split a large eCash payment text into smaller, manageable parts that can be sent over Meshtastic. Each part will include a prefix indicating its sequence and a hash for integrity verification.</p>
|
||||||
const inputText = document.getElementById('inputText').value;
|
<p>To use the text splitter:</p>
|
||||||
const outputDiv = document.getElementById('output');
|
<ol>
|
||||||
outputDiv.innerHTML = '';
|
<li>Go to the <a class="link-btn" href="splitter.html">eCash Text Splitter Tool</a>.</li>
|
||||||
|
<li>Paste your eCash payment text into the text area.</li>
|
||||||
|
<li>Click the "Split Text" button. The text will be divided into chunks of up to 150 characters.</li>
|
||||||
|
<li>Each chunk will include a prefix with its sequence number and, for the first chunk, a hash of the entire text.</li>
|
||||||
|
<li>Copy each chunk and send them as separate messages.</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
|
||||||
if (inputText.length === 0) {
|
<div class="section">
|
||||||
alert('Please paste some text to split.');
|
<h2>How to Reassemble the eCash Payment</h2>
|
||||||
return;
|
<p>To reassemble the split eCash payment text and verify its integrity:</p>
|
||||||
}
|
<ol>
|
||||||
|
<li>Go to the <a class="link-btn" href="reassemble.html">eCash Text Reassembler Tool</a>.</li>
|
||||||
|
<li>Paste all received message chunks into the provided text area.</li>
|
||||||
|
<li>The tool will automatically reorder the messages, combine them, and check the hash for integrity verification.</li>
|
||||||
|
<li>If the hash matches, you will get the original text back. If not, verify the chunks for completeness and correct order.</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
|
||||||
let parts = [];
|
<div class="section">
|
||||||
for (let i = 0; i < inputText.length; i += maxLength) {
|
<h2>Links</h2>
|
||||||
parts.push(inputText.substring(i, i + maxLength));
|
<p>Access the tools and repository below:</p>
|
||||||
}
|
<ul>
|
||||||
|
<li><a class="link-btn" href="splitter.html">eCash Text Splitter Tool</a></li>
|
||||||
parts.forEach((part, index) => {
|
<li><a class="link-btn" href="reassemble.html">eCash Text Reassembler Tool</a></li>
|
||||||
const partDiv = document.createElement('div');
|
<li><a class="link-btn" href="https://github.com/PR0M3TH3AN/text_splitter">GitHub Repository</a></li>
|
||||||
partDiv.className = 'split-text';
|
</ul>
|
||||||
|
|
||||||
const textArea = document.createElement('textarea');
|
|
||||||
textArea.readOnly = true;
|
|
||||||
textArea.value = part;
|
|
||||||
|
|
||||||
const copyButton = document.createElement('button');
|
|
||||||
copyButton.className = 'copy-btn';
|
|
||||||
copyButton.innerText = 'Copy';
|
|
||||||
copyButton.onclick = () => copyToClipboard(textArea);
|
|
||||||
|
|
||||||
partDiv.appendChild(textArea);
|
|
||||||
partDiv.appendChild(copyButton);
|
|
||||||
outputDiv.appendChild(partDiv);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyToClipboard(textArea) {
|
|
||||||
textArea.select();
|
|
||||||
document.execCommand('copy');
|
|
||||||
alert('Text copied to clipboard!');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="repo-link">
|
|
||||||
<p>Find the code for this eCash Text Splitter on GitHub: <a href="https://github.com/PR0M3TH3AN/text_splitter">https://github.com/PR0M3TH3AN/text_splitter</a></p>
|
|
||||||
<p>Access the live version of the tool here: <a href="https://ecash-text-splitter.netlify.app/">https://ecash-text-splitter.netlify.app/</a></p>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
102
src/reassemble.html
Normal file
102
src/reassemble.html
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>eCash Text Reassembler</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 150px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-size: 16px;
|
||||||
|
color: white;
|
||||||
|
background-color: #007bff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
white-space: pre-wrap; /* Allows text to wrap and maintains formatting */
|
||||||
|
background: #f4f4f4;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>eCash Text Reassembler</h1>
|
||||||
|
|
||||||
|
<textarea id="inputChunks" placeholder="Paste all received message chunks here..."></textarea>
|
||||||
|
<button onclick="reassembleText()">Reassemble Text</button>
|
||||||
|
|
||||||
|
<h2>Reassembled Text</h2>
|
||||||
|
<pre id="outputText"></pre>
|
||||||
|
<p id="statusMessage" class="error"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function reassembleText() {
|
||||||
|
const chunks = document.getElementById('inputChunks').value.split('\n\n---\n\n');
|
||||||
|
let text = '';
|
||||||
|
let hashReceived = '';
|
||||||
|
const chunkOrder = [];
|
||||||
|
|
||||||
|
// Extract the hash from the first chunk and remove it from the text
|
||||||
|
chunks.forEach(chunk => {
|
||||||
|
const lines = chunk.split('\n');
|
||||||
|
if (lines[0].startsWith('Hash:')) {
|
||||||
|
hashReceived = lines[0].replace('Hash: ', '').trim();
|
||||||
|
text += lines.slice(2).join('\n') + '\n';
|
||||||
|
} else {
|
||||||
|
text += chunk.replace(/^Message \d+\/\d+\n\n/, '') + '\n';
|
||||||
|
}
|
||||||
|
const match = lines[0].match(/Message (\d+)\/(\d+)/);
|
||||||
|
if (match) {
|
||||||
|
chunkOrder[parseInt(match[1], 10) - 1] = chunk;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reassemble text in order
|
||||||
|
const reassembledText = chunkOrder.join('\n\n---\n\n');
|
||||||
|
|
||||||
|
// Calculate the hash of the reassembled text
|
||||||
|
crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
|
||||||
|
.then(hashBuffer => {
|
||||||
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
|
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
||||||
|
|
||||||
|
if (hashHex === hashReceived) {
|
||||||
|
document.getElementById('outputText').textContent = text;
|
||||||
|
document.getElementById('statusMessage').textContent = 'The reassembled text matches the original hash!';
|
||||||
|
document.getElementById('statusMessage').classList.remove('error');
|
||||||
|
} else {
|
||||||
|
document.getElementById('outputText').textContent = '';
|
||||||
|
document.getElementById('statusMessage').textContent = 'Hash mismatch! The reassembled text may be corrupted.';
|
||||||
|
document.getElementById('statusMessage').classList.add('error');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
document.getElementById('statusMessage').textContent = 'Error calculating hash: ' + err;
|
||||||
|
document.getElementById('statusMessage').classList.add('error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
86
src/splitter.html
Normal file
86
src/splitter.html
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>eCash Text Splitter</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 150px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-size: 16px;
|
||||||
|
color: white;
|
||||||
|
background-color: #007bff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
white-space: pre-wrap; /* Allows text to wrap and maintains formatting */
|
||||||
|
background: #f4f4f4;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>eCash Text Splitter</h1>
|
||||||
|
|
||||||
|
<textarea id="inputText" placeholder="Paste your eCash payment text here..."></textarea>
|
||||||
|
<button onclick="splitText()">Split Text</button>
|
||||||
|
|
||||||
|
<h2>Output Chunks</h2>
|
||||||
|
<pre id="outputChunks"></pre>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function splitText() {
|
||||||
|
const text = document.getElementById('inputText').value;
|
||||||
|
const maxChunkSize = 150;
|
||||||
|
const chunks = [];
|
||||||
|
|
||||||
|
// Calculate the hash of the text
|
||||||
|
const hash = crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
|
||||||
|
.then(hashBuffer => {
|
||||||
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
|
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
||||||
|
|
||||||
|
// Split the text into chunks
|
||||||
|
for (let i = 0; i < text.length; i += maxChunkSize) {
|
||||||
|
let chunk = text.substring(i, i + maxChunkSize);
|
||||||
|
let chunkNumber = Math.floor(i / maxChunkSize) + 1;
|
||||||
|
let totalChunks = Math.ceil(text.length / maxChunkSize);
|
||||||
|
let prefix = `Message ${chunkNumber}/${totalChunks}`;
|
||||||
|
|
||||||
|
// Add the hash only to the first chunk
|
||||||
|
if (chunkNumber === 1) {
|
||||||
|
chunk = `Hash: ${hashHex}\n${prefix}\n\n${chunk}`;
|
||||||
|
} else {
|
||||||
|
chunk = `${prefix}\n\n${chunk}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
chunks.push(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display the chunks
|
||||||
|
document.getElementById('outputChunks').textContent = chunks.join('\n\n---\n\n');
|
||||||
|
})
|
||||||
|
.catch(err => console.error('Error calculating hash:', err));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user