console
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="saveButton">保存为TXT</button>
<input type="file" id="fileInput1">
<input type="file" id="fileInput2">
<pre id="fileContent1"></pre>
<pre id="fileContent2"></pre>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$('#fileInput1').change(function () {
const file = this.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const fileContent = event.target.result.replaceAll('\r', '');
$('#fileContent1').text(fileContent);
};
reader.readAsText(file);
});
$('#fileInput2').change(function () {
const file = this.files[0];
const reader = new FileReader();
reader.onload = function (event) {
const fileContent = event.target.result;
const modifiedContent = fileContent.replaceAll("\r", "");
document.getElementById("fileContent2").textContent = modifiedContent;
};
reader.readAsText(file);
});
$('#saveButton').click(function () {
const file1Text = $('#fileContent1').text().trim();
const file2Text = $('#fileContent2').text().trim();
const file1Name = $('#fileInput1').prop('files')[0].name;
const file2Name = $('#fileInput2').prop('files')[0].name;
const file1Blocks = file1Text.split('\n\n');
const file2Blocks = file2Text.split('\n\n');
let syncedText = '';
file1Blocks.forEach(function (file1Block, index) {
const blockIndex = parseInt(file1Block.split('\n')[0]);
if (blockIndex > 0 && blockIndex <= file2Blocks.length) {
const file2Block = file2Blocks[blockIndex - 1];
const file1Lines = file1Block.split('\n').slice(0, 2);
const file2Lines = file2Block.split('\n').slice(2);
syncedText += `${file1Lines.join('\n')}\n${file2Lines.join('\n')}\n\n`;
}
});
const blob = new Blob([syncedText], { type: 'text/plain' });
const downloadLink = document.createElement('a');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = `${file1Name}_synced.txt`;
downloadLink.click();
});
});
</script>
</body>
</html>