梦境文本转换器

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>梦境文本转换器</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            color: #333;
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 900px;
            margin: 0 auto;
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            padding: 30px;
        }
        
        header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #eaeaea;
        }
        
        h1 {
            color: #6c63ff;
            font-size: 2.8rem;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 15px;
        }
        
        h1 i {
            font-size: 2.5rem;
            color: #ff6b9d;
        }
        
        .subtitle {
            color: #666;
            font-size: 1.2rem;
            max-width: 700px;
            margin: 0 auto;
            line-height: 1.5;
        }
        
        .main-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
            margin-bottom: 30px;
        }
        
        @media (max-width: 768px) {
            .main-content {
                grid-template-columns: 1fr;
            }
        }
        
        .upload-section, .settings-section {
            background: #fff;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            border: 1px solid #eaeaea;
        }
        
        .section-title {
            display: flex;
            align-items: center;
            gap: 10px;
            color: #6c63ff;
            margin-bottom: 20px;
            font-size: 1.4rem;
        }
        
        .section-title i {
            font-size: 1.3rem;
        }
        
        .file-upload-area {
            border: 3px dashed #c3cfe2;
            border-radius: 12px;
            padding: 40px 20px;
            text-align: center;
            transition: all 0.3s ease;
            cursor: pointer;
            margin-bottom: 20px;
        }
        
        .file-upload-area:hover, .file-upload-area.dragover {
            border-color: #6c63ff;
            background-color: rgba(108, 99, 255, 0.03);
        }
        
        .file-upload-area i {
            font-size: 3rem;
            color: #6c63ff;
            margin-bottom: 15px;
        }
        
        .file-upload-text {
            font-size: 1.1rem;
            color: #666;
            margin-bottom: 10px;
        }
        
        .file-name {
            margin-top: 10px;
            color: #ff6b9d;
            font-weight: 500;
        }
        
        .custom-prefix {
            margin-bottom: 25px;
        }
        
        .custom-prefix label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
        }
        
        .custom-prefix input {
            width: 100%;
            padding: 14px 20px;
            border: 2px solid #ddd;
            border-radius: 10px;
            font-size: 1.1rem;
            transition: all 0.3s;
        }
        
        .custom-prefix input:focus {
            border-color: #6c63ff;
            outline: none;
            box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
        }
        
        .preview-section {
            background: #fff;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            border: 1px solid #eaeaea;
            margin-bottom: 30px;
        }
        
        .preview-title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .preview-title h3 {
            color: #6c63ff;
            font-size: 1.4rem;
        }
        
        .line-count {
            color: #ff6b9d;
            font-weight: 500;
            background: rgba(255, 107, 157, 0.1);
            padding: 5px 12px;
            border-radius: 20px;
        }
        
        .preview-content {
            height: 300px;
            overflow-y: auto;
            border: 2px solid #eee;
            border-radius: 10px;
            padding: 20px;
            background-color: #f9f9f9;
            font-family: 'Courier New', monospace;
            line-height: 1.6;
            white-space: pre-wrap;
        }
        
        .controls {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-bottom: 30px;
        }
        
        button {
            padding: 15px 30px;
            border: none;
            border-radius: 10px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .process-btn {
            background: linear-gradient(135deg, #6c63ff 0%, #8a84ff 100%);
            color: white;
            box-shadow: 0 5px 15px rgba(108, 99, 255, 0.3);
        }
        
        .process-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(108, 99, 255, 0.4);
        }
        
        .download-btn {
            background: linear-gradient(135deg, #ff6b9d 0%, #ff8ab0 100%);
            color: white;
            box-shadow: 0 5px 15px rgba(255, 107, 157, 0.3);
        }
        
        .download-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(255, 107, 157, 0.4);
        }
        
        button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none !important;
            box-shadow: none !important;
        }
        
        footer {
            text-align: center;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #eee;
            color: #888;
            font-size: 0.9rem;
        }
        
        .example-prefix {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 15px;
        }
        
        .example-prefix span {
            background: #f0f0f0;
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 0.9rem;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .example-prefix span:hover {
            background: #6c63ff;
            color: white;
        }
        
        .highlight {
            color: #ff6b9d;
            font-weight: 600;
        }
        
        /* 滚动条样式 */
        .preview-content::-webkit-scrollbar {
            width: 8px;
        }
        
        .preview-content::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 4px;
        }
        
        .preview-content::-webkit-scrollbar-thumb {
            background: #c3cfe2;
            border-radius: 4px;
        }
        
        .preview-content::-webkit-scrollbar-thumb:hover {
            background: #6c63ff;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1><i class="fas fa-moon"></i> 梦境文本转换器</h1>
            <p class="subtitle">上传TXT文件,自动为每一行句子添加前缀。您可以自定义前缀文本,或将文本转换为梦境中的肯定句。</p>
        </header>
        
        <div class="main-content">
            <div class="upload-section">
                <div class="section-title">
                    <i class="fas fa-file-upload"></i>
                    <h2>上传TXT文件</h2>
                </div>
                
                <div class="file-upload-area" id="dropArea">
                    <i class="fas fa-cloud-upload-alt"></i>
                    <p class="file-upload-text">点击此处选择文件,或直接拖放文件到此处</p>
                    <p class="file-upload-text">支持 .txt 文本文件</p>
                    <input type="file" id="fileInput" accept=".txt" style="display: none;">
                    <p class="file-name" id="fileName">尚未选择文件</p>
                </div>
                
                <div class="file-info">
                    <p><i class="fas fa-info-circle"></i> 文件内容将按行处理,每行都会添加您指定的前缀。</p>
                </div>
            </div>
            
            <div class="settings-section">
                <div class="section-title">
                    <i class="fas fa-cog"></i>
                    <h2>前缀设置</h2>
                </div>
                
                <div class="custom-prefix">
                    <label for="prefixInput"><i class="fas fa-pen"></i> 自定义每行添加的文本:</label>
                    <input type="text" id="prefixInput" value="在梦里" placeholder="输入要添加的前缀文本">
                    
                    <div class="example-prefix">
                        <span>在梦里</span>
                        <span>梦境中</span>
                        <span>潜意识里</span>
                        <span>我的梦境</span>
                        <span>今晚的梦</span>
                        <span>梦之境</span>
                    </div>
                </div>
                
                <div class="option">
                    <p><i class="fas fa-check-circle"></i> 空行将不会添加前缀,以保持文本结构</p>
                    <p><i class="fas fa-check-circle"></i> 每行前缀后会自动添加一个空格</p>
                </div>
            </div>
        </div>
        
        <div class="preview-section">
            <div class="preview-title">
                <h3><i class="fas fa-eye"></i> 预览结果</h3>
                <div class="line-count" id="lineCount">0 行文本</div>
            </div>
            
            <div class="preview-content" id="previewContent">
                请上传TXT文件并点击"处理文本"按钮,这里将显示转换后的文本内容...
            </div>
        </div>
        
        <div class="controls">
            <button class="process-btn" id="processBtn" disabled>
                <i class="fas fa-magic"></i> 处理文本
            </button>
            <button class="download-btn" id="downloadBtn" disabled>
                <i class="fas fa-download"></i> 下载结果
            </button>
        </div>
        
        <footer>
            <p>梦境文本转换器 &copy; 2023 | 设计用于文本处理和梦境肯定句生成</p>
            <p>提示:您可以使用此工具为任何文本添加统一的前缀,尤其适合制作潜意识肯定句</p>
        </footer>
    </div>

    <script>
        // DOM元素
        const fileInput = document.getElementById('fileInput');
        const dropArea = document.getElementById('dropArea');
        const fileName = document.getElementById('fileName');
        const prefixInput = document.getElementById('prefixInput');
        const previewContent = document.getElementById('previewContent');
        const processBtn = document.getElementById('processBtn');
        const downloadBtn = document.getElementById('downloadBtn');
        const lineCount = document.getElementById('lineCount');
        const examplePrefixes = document.querySelectorAll('.example-prefix span');
        
        // 存储原始文本和处理后的文本
        let originalText = '';
        let processedText = '';
        
        // 文件拖放功能
        dropArea.addEventListener('click', () => fileInput.click());
        
        fileInput.addEventListener('change', handleFileSelect);
        
        // 拖放事件处理
        dropArea.addEventListener('dragover', (e) => {
            e.preventDefault();
            dropArea.classList.add('dragover');
        });
        
        dropArea.addEventListener('dragleave', () => {
            dropArea.classList.remove('dragover');
        });
        
        dropArea.addEventListener('drop', (e) => {
            e.preventDefault();
            dropArea.classList.remove('dragover');
            
            if (e.dataTransfer.files.length) {
                fileInput.files = e.dataTransfer.files;
                handleFileSelect();
            }
        });
        
        // 处理文件选择
        function handleFileSelect() {
            const file = fileInput.files[0];
            
            if (!file) return;
            
            // 检查文件类型
            if (!file.name.endsWith('.txt')) {
                alert('请选择TXT格式的文本文件');
                resetFileInput();
                return;
            }
            
            fileName.textContent = `已选择: ${file.name} (${formatFileSize(file.size)})`;
            fileName.classList.add('highlight');
            
            // 启用处理按钮
            processBtn.disabled = false;
            
            // 读取文件内容
            const reader = new FileReader();
            reader.onload = function(e) {
                originalText = e.target.result;
                previewContent.textContent = `已加载文件 "${file.name}",请点击"处理文本"按钮开始转换...`;
                lineCount.textContent = `${countLines(originalText)} 行文本`;
                
                // 重置下载按钮
                downloadBtn.disabled = true;
            };
            reader.readAsText(file, 'UTF-8');
        }
        
        // 示例前缀点击事件
        examplePrefixes.forEach(prefix => {
            prefix.addEventListener('click', () => {
                prefixInput.value = prefix.textContent;
                // 如果已经有文本,立即处理
                if (originalText) {
                    processText();
                }
            });
        });
        
        // 处理文本按钮事件
        processBtn.addEventListener('click', processText);
        
        // 处理文本函数
        function processText() {
            if (!originalText) {
                alert('请先上传TXT文件');
                return;
            }
            
            const prefix = prefixInput.value.trim() || '在梦里';
            const lines = originalText.split('\n');
            let processedLines = [];
            
            // 为每行非空文本添加前缀
            for (let i = 0; i < lines.length; i++) {
                const line = lines[i].trim();
                if (line) {
                    // 添加前缀和空格
                    processedLines.push(`${prefix} ${line}`);
                } else {
                    // 保持空行不变
                    processedLines.push('');
                }
            }
            
            // 合并处理后的文本
            processedText = processedLines.join('\n');
            
            // 更新预览
            previewContent.textContent = processedText;
            
            // 更新行数统计
            const nonEmptyLines = lines.filter(line => line.trim()).length;
            lineCount.textContent = `${nonEmptyLines} 行已添加前缀`;
            
            // 启用下载按钮
            downloadBtn.disabled = false;
            
            // 显示成功消息
            previewContent.innerHTML = processedText + 
                `<br><br><div style="color: #6c63ff; text-align: center; padding: 10px; background: rgba(108, 99, 255, 0.05); border-radius: 8px;">
                <i class="fas fa-check-circle"></i> 文本处理完成!共 ${nonEmptyLines} 行添加了前缀"<strong>${prefix}</strong>"。
                </div>`;
        }
        
        // 下载按钮事件
        downloadBtn.addEventListener('click', downloadResult);
        
        // 下载结果函数
        function downloadResult() {
            if (!processedText) {
                alert('请先处理文本');
                return;
            }
            
            const prefix = prefixInput.value.trim() || '在梦里';
            const blob = new Blob([processedText], { type: 'text/plain;charset=utf-8' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            
            a.href = url;
            a.download = `梦境文本_${prefix}_${new Date().getTime()}.txt`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        }
        
        // 辅助函数
        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            const k = 1024;
            const sizes = ['Bytes', 'KB', 'MB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }
        
        function countLines(text) {
            return text.split('\n').length;
        }
        
        function resetFileInput() {
            fileInput.value = '';
            fileName.textContent = '尚未选择文件';
            fileName.classList.remove('highlight');
            processBtn.disabled = true;
            downloadBtn.disabled = true;
            originalText = '';
            processedText = '';
            previewContent.textContent = '请上传TXT文件并点击"处理文本"按钮,这里将显示转换后的文本内容...';
            lineCount.textContent = '0 行文本';
        }
        
        // 初始化页面时显示示例文本
        window.addEventListener('DOMContentLoaded', () => {
            // 设置示例前缀点击事件
            examplePrefixes.forEach(prefix => {
                prefix.style.cursor = 'pointer';
            });
        });
    </script>
</body>
</html>

http://freelancerdh.free.nf/sub%E5%B0%8F%E7%AB%99/index.html

posted on 2025-12-10 15:56  小沙盒工作室  阅读(0)  评论(0)    收藏  举报