返回列表 发布新帖

原生HTML的SRT字幕净化工具

306 0
小K网牛逼 发表于 2 小时前 | 查看全部 阅读模式 <

马上注册,结交更多好友,享用更多功能,让你轻松玩转小K网。

您需要 登录 才可以下载或查看,没有账号?立即注册 微信登录

×

原生HTML的SRT字幕净化工具

原生HTML的SRT字幕净化工具


对于srt字幕文件,可以去除其中的行号、时间、格式、空行,仅保留字幕文本。
代码:

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>SRT字幕净化工具</title>
  7.     <style>
  8.         * {
  9.             box-sizing: border-box;
  10.             margin: 0;
  11.             padding: 0;
  12.             font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  13.         }
  14.          
  15.         body {
  16.             background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  17.             color: #333;
  18.             min-height: 100vh;
  19.             padding: 20px;
  20.             display: flex;
  21.             justify-content: center;
  22.             align-items: center;
  23.         }
  24.          
  25.         .container {
  26.             width: 100%;
  27.             max-width: 900px;
  28.             background-color: rgba(255, 255, 255, 0.95);
  29.             border-radius: 16px;
  30.             box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  31.             overflow: hidden;
  32.         }
  33.          
  34.         header {
  35.             background: linear-gradient(90deg, #4b6cb7, #182848);
  36.             color: white;
  37.             padding: 25px 30px;
  38.             text-align: center;
  39.             position: relative;
  40.         }
  41.          
  42.         h1 {
  43.             font-size: 2.2rem;
  44.             margin-bottom: 10px;
  45.         }
  46.          
  47.         .subtitle {
  48.             font-size: 1.1rem;
  49.             opacity: 0.9;
  50.             max-width: 600px;
  51.             margin: 0 auto;
  52.             line-height: 1.5;
  53.         }
  54.          
  55.         .main-content {
  56.             padding: 30px;
  57.         }
  58.          
  59.         .upload-area {
  60.             border: 3px dashed #4b6cb7;
  61.             border-radius: 12px;
  62.             padding: 40px 20px;
  63.             text-align: center;
  64.             background-color: #f8f9ff;
  65.             transition: all 0.3s ease;
  66.             margin-bottom: 30px;
  67.             position: relative;
  68.         }
  69.          
  70.         .upload-area:hover, .upload-area.dragover {
  71.             background-color: #eef2ff;
  72.             border-color: #182848;
  73.         }
  74.          
  75.         .upload-icon {
  76.             font-size: 60px;
  77.             color: #4b6cb7;
  78.             margin-bottom: 15px;
  79.         }
  80.          
  81.         .upload-text {
  82.             font-size: 1.2rem;
  83.             margin-bottom: 20px;
  84.             color: #444;
  85.         }
  86.          
  87.         .file-input {
  88.             display: none;
  89.         }
  90.          
  91.         .btn {
  92.             background: linear-gradient(90deg, #4b6cb7, #182848);
  93.             color: white;
  94.             border: none;
  95.             padding: 12px 30px;
  96.             font-size: 1.1rem;
  97.             border-radius: 50px;
  98.             cursor: pointer;
  99.             transition: all 0.3s ease;
  100.             display: inline-flex;
  101.             align-items: center;
  102.             justify-content: center;
  103.             gap: 8px;
  104.             box-shadow: 0 4px 10px rgba(75, 108, 183, 0.3);
  105.         }
  106.          
  107.         .btn:hover {
  108.             transform: translateY(-3px);
  109.             box-shadow: 0 6px 15px rgba(75, 108, 183, 0.4);
  110.         }
  111.          
  112.         .btn:active {
  113.             transform: translateY(1px);
  114.         }
  115.          
  116.         .options-section {
  117.             background-color: #f0f7ff;
  118.             border-radius: 12px;
  119.             padding: 20px;
  120.             margin-bottom: 25px;
  121.             border: 1px solid #d0e3ff;
  122.         }
  123.          
  124.         .option-title {
  125.             font-size: 1.2rem;
  126.             color: #182848;
  127.             margin-bottom: 15px;
  128.             display: flex;
  129.             align-items: center;
  130.             gap: 10px;
  131.         }
  132.          
  133.         .option-item {
  134.             display: flex;
  135.             align-items: center;
  136.             margin: 10px 0;
  137.         }
  138.          
  139.         .option-item input[type="checkbox"] {
  140.             width: 20px;
  141.             height: 20px;
  142.             margin-right: 10px;
  143.             accent-color: #4b6cb7;
  144.         }
  145.          
  146.         .option-item label {
  147.             font-size: 1rem;
  148.             color: #444;
  149.         }
  150.          
  151.         .result-container {
  152.             display: none;
  153.             margin-top: 30px;
  154.             animation: fadeIn 0.5s ease;
  155.         }
  156.          
  157.         @keyframes fadeIn {
  158.             from { opacity: 0; transform: translateY(20px); }
  159.             to { opacity: 1; transform: translateY(0); }
  160.         }
  161.          
  162.         .section-title {
  163.             font-size: 1.4rem;
  164.             color: #182848;
  165.             margin-bottom: 15px;
  166.             padding-bottom: 10px;
  167.             border-bottom: 2px solid #eaeaea;
  168.             display: flex;
  169.             align-items: center;
  170.             gap: 10px;
  171.         }
  172.          
  173.         .content-box {
  174.             background-color: #f8f9ff;
  175.             border-radius: 10px;
  176.             padding: 20px;
  177.             height: 250px;
  178.             overflow-y: auto;
  179.             margin-bottom: 20px;
  180.             border: 1px solid #e0e0e0;
  181.             line-height: 1.6;
  182.             white-space: pre-wrap;
  183.             font-family: monospace;
  184.             font-size: 0.95rem;
  185.         }
  186.          
  187.         .stats {
  188.             display: flex;
  189.             justify-content: space-between;
  190.             background-color: #eef7ff;
  191.             padding: 12px 15px;
  192.             border-radius: 8px;
  193.             margin-bottom: 20px;
  194.             font-size: 0.9rem;
  195.             color: #4b6cb7;
  196.         }
  197.          
  198.         .stat-item {
  199.             display: flex;
  200.             flex-direction: column;
  201.             align-items: center;
  202.         }
  203.          
  204.         .stat-value {
  205.             font-weight: bold;
  206.             font-size: 1.2rem;
  207.             color: #182848;
  208.         }
  209.          
  210.         .action-buttons {
  211.             display: flex;
  212.             gap: 15px;
  213.             flex-wrap: wrap;
  214.         }
  215.          
  216.         .btn-download {
  217.             background: linear-gradient(90deg, #11998e, #38ef7d);
  218.         }
  219.          
  220.         .btn-copy {
  221.             background: linear-gradient(90deg, #ff416c, #ff4b2b);
  222.         }
  223.          
  224.         .btn-new {
  225.             background: linear-gradient(90deg, #4b6cb7, #182848);
  226.         }
  227.          
  228.         .file-info {
  229.             margin-top: 15px;
  230.             font-size: 0.9rem;
  231.             color: #666;
  232.             padding: 10px;
  233.             background-color: #f0f7ff;
  234.             border-radius: 8px;
  235.         }
  236.          
  237.         .example {
  238.             background-color: #eef7ff;
  239.             border-left: 4px solid #4b6cb7;
  240.             padding: 15px;
  241.             margin: 20px 0;
  242.             border-radius: 0 8px 8px 0;
  243.         }
  244.          
  245.         .example h3 {
  246.             color: #182848;
  247.             margin-bottom: 10px;
  248.             display: flex;
  249.             align-items: center;
  250.             gap: 10px;
  251.         }
  252.          
  253.         .example-content {
  254.             font-family: monospace;
  255.             white-space: pre-line;
  256.             font-size: 0.9rem;
  257.             background-color: white;
  258.             padding: 10px;
  259.             border-radius: 6px;
  260.             margin-top: 10px;
  261.         }
  262.          
  263.         .status {
  264.             padding: 12px;
  265.             border-radius: 8px;
  266.             margin: 15px 0;
  267.             text-align: center;
  268.             display: none;
  269.             font-weight: 500;
  270.         }
  271.          
  272.         .status.success {
  273.             background-color: #d4edda;
  274.             color: #155724;
  275.             display: block;
  276.         }
  277.          
  278.         .status.error {
  279.             background-color: #f8d7da;
  280.             color: #721c24;
  281.             display: block;
  282.         }
  283.          
  284.         .status.info {
  285.             background-color: #cce5ff;
  286.             color: #004085;
  287.             display: block;
  288.         }
  289.          
  290.         footer {
  291.             text-align: center;
  292.             padding: 20px;
  293.             color: #777;
  294.             font-size: 0.9rem;
  295.             border-top: 1px solid #eee;
  296.             background-color: #f8f9ff;
  297.         }
  298.          
  299.         .preview-toggle {
  300.             display: flex;
  301.             justify-content: center;
  302.             margin: 15px 0;
  303.         }
  304.          
  305.         .toggle-btn {
  306.             background: #eef2ff;
  307.             border: 1px solid #d0e3ff;
  308.             padding: 8px 20px;
  309.             cursor: pointer;
  310.             transition: all 0.3s ease;
  311.         }
  312.          
  313.         .toggle-btn:first-child {
  314.             border-radius: 20px 0 0 20px;
  315.         }
  316.          
  317.         .toggle-btn:last-child {
  318.             border-radius: 0 20px 20px 0;
  319.         }
  320.          
  321.         .toggle-btn.active {
  322.             background: linear-gradient(90deg, #4b6cb7, #182848);
  323.             color: white;
  324.             border-color: #4b6cb7;
  325.         }
  326.          
  327.         [url=home.php?mod=space&uid=945662]@media[/url] (max-width: 768px) {
  328.             .container {
  329.                 margin: 10px;
  330.             }
  331.             
  332.             header {
  333.                 padding: 20px 15px;
  334.             }
  335.             
  336.             .logo {
  337.                 position: static;
  338.                 margin: 0 auto 15px;
  339.             }
  340.             
  341.             h1 {
  342.                 font-size: 1.8rem;
  343.             }
  344.             
  345.             .main-content {
  346.                 padding: 20px 15px;
  347.             }
  348.             
  349.             .action-buttons {
  350.                 flex-direction: column;
  351.             }
  352.             
  353.             .btn {
  354.                 width: 100%;
  355.             }
  356.             
  357.             .stats {
  358.                 flex-direction: column;
  359.                 gap: 15px;
  360.             }
  361.             
  362.             .stat-item {
  363.                 flex-direction: row;
  364.                 justify-content: space-between;
  365.                 width: 100%;
  366.             }
  367.         }
  368.     </style>
  369. </head>
  370. <body>
  371.     <div class="container">
  372.         <header>
  373.             <h1>SRT字幕净化工具</h1>
  374.             <p class="subtitle">上传SRT字幕文件,自动去除序号、时间码和格式代码,仅保留纯文本内容</p>
  375.         </header>
  376.          
  377.         <div class="main-content">
  378.             <div class="upload-area" id="dropArea">
  379.                 <div class="upload-icon">&#128196;</div>
  380.                 <p class="upload-text">拖放SRT文件到此处,或点击下方按钮选择文件</p>
  381.                 <input type="file" id="fileInput" class="file-input" accept=".srt">
  382.                 <label for="fileInput" class="btn">
  383.                     &#128193; 选择SRT文件
  384.                 </label>
  385.                 <div class="file-info" id="fileInfo"></div>
  386.                 <div class="status" id="statusMessage"></div>
  387.             </div>
  388.             
  389.             <div class="options-section">
  390.                 <h3 class="option-title">&#9881;&#65039; 处理选项</h3>
  391.                 <div class="option-item">
  392.                     <input type="checkbox" id="removeEmptyLines" checked>
  393.                     <label for="removeEmptyLines">删除所有空行(包括字幕块之间的空行)</label>
  394.                 </div>
  395.                 <div class="option-item">
  396.                     <input type="checkbox" id="removeHtmlTags" checked>
  397.                     <label for="removeHtmlTags">移除HTML标签(如<b>, <i>, <u>等)</label>
  398.                 </div>
  399.                 <div class="option-item">
  400.                     <input type="checkbox" id="mergeShortLines">
  401.                     <label for="mergeShortLines">合并每段字幕中的短行(少于15个字符的行)</label>
  402.                 </div>
  403.             </div>
  404.             
  405.             <div class="example">
  406.                 <h3>&#128161; 格式示例</h3>
  407.                 <div class="example-content">原始SRT格式:
  408. 1
  409. 00:00:01,000 --> 00:00:04,000
  410. <b>你好,世界!</b>
  411. 2
  412. 00:00:05,000 --> 00:00:08,000
  413. 欢迎使用字幕清理工具
  414. 它可以去除所有格式代码
  415. 3
  416. 00:00:09,000 --> 00:00:12,000
  417. 处理完成后,您可以下载或复制结果</div>
  418.             </div>
  419.             
  420.             <div class="result-container" id="resultContainer">
  421.                 <h2 class="section-title">&#128203; 处理结果</h2>
  422.                  
  423.                 <div class="stats">
  424.                     <div class="stat-item">
  425.                         <span>原始行数</span>
  426.                         <span class="stat-value" id="originalLines">0</span>
  427.                     </div>
  428.                     <div class="stat-item">
  429.                         <span>清理后行数</span>
  430.                         <span class="stat-value" id="cleanedLines">0</span>
  431.                     </div>
  432.                     <div class="stat-item">
  433.                         <span>字符数</span>
  434.                         <span class="stat-value" id="charCount">0</span>
  435.                     </div>
  436.                     <div class="stat-item">
  437.                         <span>处理时间</span>
  438.                         <span class="stat-value" id="processTime">0ms</span>
  439.                     </div>
  440.                 </div>
  441.                  
  442.                 <div class="preview-toggle">
  443.                     <div class="toggle-btn active" data-preview="cleaned">清理后内容</div>
  444.                     <div class="toggle-btn" data-preview="original">原始内容预览</div>
  445.                 </div>
  446.                  
  447.                 <h3>清理后的字幕内容</h3>
  448.                 <div class="content-box" id="cleanedContent"></div>
  449.                  
  450.                 <div class="action-buttons">
  451.                     <button class="btn btn-download" id="downloadBtn">
  452.                         &#11015;&#65039; 下载清理后的文本
  453.                     </button>
  454.                     <button class="btn btn-copy" id="copyBtn">
  455.                         &#9112; 复制到剪贴板
  456.                     </button>
  457.                     <button class="btn btn-new" id="newFileBtn">
  458.                         &#8635; 处理新文件
  459.                     </button>
  460.                 </div>
  461.             </div>
  462.         </div>
  463.          
  464.         <footer>
  465.             <p>SRT字幕净化工具 &#169; 2026</p>
  466.         </footer>
  467.     </div>
  468.     <script>
  469.         document.addEventListener('DOMContentLoaded', function() {
  470.             const fileInput = document.getElementById('fileInput');
  471.             const dropArea = document.getElementById('dropArea');
  472.             const fileInfo = document.getElementById('fileInfo');
  473.             const statusMessage = document.getElementById('statusMessage');
  474.             const resultContainer = document.getElementById('resultContainer');
  475.             const cleanedContent = document.getElementById('cleanedContent');
  476.             const downloadBtn = document.getElementById('downloadBtn');
  477.             const copyBtn = document.getElementById('copyBtn');
  478.             const newFileBtn = document.getElementById('newFileBtn');
  479.             const removeEmptyLines = document.getElementById('removeEmptyLines');
  480.             const removeHtmlTags = document.getElementById('removeHtmlTags');
  481.             const mergeShortLines = document.getElementById('mergeShortLines');
  482.             const toggleButtons = document.querySelectorAll('.toggle-btn');
  483.             
  484.             let currentFile = null;
  485.             let cleanedText = '';
  486.             let originalContent = '';
  487.             let startTime = 0;
  488.             
  489.             // 文件选择处理
  490.             fileInput.addEventListener('change', function(e) {
  491.                 if (e.target.files.length > 0) {
  492.                     handleFile(e.target.files[0]);
  493.                 }
  494.             });
  495.             
  496.             // 拖放功能
  497.             ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
  498.                 dropArea.addEventListener(eventName, preventDefaults, false);
  499.             });
  500.             
  501.             function preventDefaults(e) {
  502.                 e.preventDefault();
  503.                 e.stopPropagation();
  504.             }
  505.             
  506.             ['dragenter', 'dragover'].forEach(eventName => {
  507.                 dropArea.addEventListener(eventName, highlight, false);
  508.             });
  509.             
  510.             ['dragleave', 'drop'].forEach(eventName => {
  511.                 dropArea.addEventListener(eventName, unhighlight, false);
  512.             });
  513.             
  514.             function highlight() {
  515.                 dropArea.classList.add('dragover');
  516.             }
  517.             
  518.             function unhighlight() {
  519.                 dropArea.classList.remove('dragover');
  520.             }
  521.             
  522.             dropArea.addEventListener('drop', function(e) {
  523.                 const dt = e.dataTransfer;
  524.                 const file = dt.files[0];
  525.                 if (file && file.name.endsWith('.srt')) {
  526.                     handleFile(file);
  527.                 } else {
  528.                     showStatus('请上传有效的SRT文件', 'error');
  529.                 }
  530.             });
  531.             
  532.             // 处理文件
  533.             function handleFile(file) {
  534.                 if (!file.name.endsWith('.srt')) {
  535.                     showStatus('请上传SRT格式的文件', 'error');
  536.                     return;
  537.                 }
  538.                  
  539.                 currentFile = file;
  540.                 fileInfo.textContent = `已选择: ${file.name} (${(file.size / 1024).toFixed(2)} KB)`;
  541.                 fileInfo.style.color = '#4CAF50';
  542.                 hideStatus();
  543.                  
  544.                 startTime = performance.now();
  545.                  
  546.                 const reader = new FileReader();
  547.                 reader.onload = function(e) {
  548.                     try {
  549.                         originalContent = e.target.result;
  550.                         cleanedText = cleanSRT(originalContent);
  551.                         
  552.                         const processTime = Math.round(performance.now() - startTime);
  553.                         updateStats(originalContent, cleanedText, processTime);
  554.                         
  555.                         displayResults(cleanedText);
  556.                         showStatus('文件处理成功!', 'success');
  557.                     } catch (error) {
  558.                         showStatus(`处理文件时出错: ${error.message}`, 'error');
  559.                         console.error(error);
  560.                     }
  561.                 };
  562.                 reader.onerror = function() {
  563.                     showStatus('读取文件失败', 'error');
  564.                 };
  565.                 reader.readAsText(file);
  566.             }
  567.             
  568.             // 修复后的SRT清理函数(处理各种格式)
  569.             function cleanSRT(srtContent) {
  570.                 const removeHtml = removeHtmlTags.checked;
  571.                 const deleteEmpty = removeEmptyLines.checked;
  572.                 const mergeLines = mergeShortLines.checked;
  573.                  
  574.                 // 分割字幕块(兼容有无空行的情况)
  575.                 const blocks = [];
  576.                 let currentBlock = [];
  577.                 const lines = srtContent.split(/\r?\n/);
  578.                  
  579.                 for (let i = 0; i < lines.length; i++) {
  580.                     const line = lines[i].trim();
  581.                      
  582.                     // 检查是否为序号行(只包含数字)
  583.                     if (/^\d+$/.test(line)) {
  584.                         // 保存前一个块(如果有内容)
  585.                         if (currentBlock.length > 0) {
  586.                             blocks.push(currentBlock.join('\n'));
  587.                             currentBlock = [];
  588.                         }
  589.                         continue;
  590.                     }
  591.                      
  592.                     // 检查是否为时间码行(包含 -->)
  593.                     if (line.includes('-->')) {
  594.                         continue;
  595.                     }
  596.                      
  597.                     // 跳过空行(如果设置了删除空行)
  598.                     if (line === '') {
  599.                         if (!deleteEmpty && currentBlock.length > 0) {
  600.                             blocks.push(currentBlock.join('\n'));
  601.                             currentBlock = [];
  602.                         }
  603.                         continue;
  604.                     }
  605.                      
  606.                     // 移除HTML标签(如果设置了移除HTML)
  607.                     let cleanLine = line;
  608.                     if (removeHtml) {
  609.                         cleanLine = line.replace(/<[^>]*>/g, '');
  610.                     }
  611.                      
  612.                     // 添加到当前块
  613.                     if (cleanLine !== '') {
  614.                         currentBlock.push(cleanLine);
  615.                     }
  616.                 }
  617.                  
  618.                 // 添加最后一个块
  619.                 if (currentBlock.length > 0) {
  620.                     blocks.push(currentBlock.join('\n'));
  621.                 }
  622.                  
  623.                 // 修复合并短行功能
  624.                 if (mergeLines) {
  625.                     for (let i = 0; i < blocks.length; i++) {
  626.                         const linesInBlock = blocks[i].split('\n');
  627.                         const mergedLines = [];
  628.                         let currentMerge = '';
  629.                         
  630.                         for (let j = 0; j < linesInBlock.length; j++) {
  631.                             const line = linesInBlock[j].trim();
  632.                              
  633.                             if (line === '') continue;
  634.                              
  635.                             // 如果当前行是短行(少于15个字符)
  636.                             if (line.length < 15) {
  637.                                 if (currentMerge === '') {
  638.                                     currentMerge = line;
  639.                                 } else {
  640.                                     currentMerge += ' ' + line;
  641.                                 }
  642.                             } else {
  643.                                 // 当前行不是短行
  644.                                 if (currentMerge !== '') {
  645.                                     mergedLines.push(currentMerge);
  646.                                     currentMerge = '';
  647.                                 }
  648.                                 mergedLines.push(line);
  649.                             }
  650.                         }
  651.                         
  652.                         // 处理最后剩余的合并行
  653.                         if (currentMerge !== '') {
  654.                             mergedLines.push(currentMerge);
  655.                         }
  656.                         
  657.                         blocks[i] = mergedLines.join('\n');
  658.                     }
  659.                 }
  660.                  
  661.                 // 根据选项决定是否删除空行
  662.                 let result;
  663.                 if (deleteEmpty) {
  664.                     result = blocks.join('\n');
  665.                 } else {
  666.                     result = blocks.join('\n\n');
  667.                 }
  668.                  
  669.                 return result;
  670.             }
  671.             
  672.             // 更新统计信息
  673.             function updateStats(original, cleaned, time) {
  674.                 const origLines = original.split(/\r?\n/).length;
  675.                 const cleanedLines = cleaned.split(/\n/).length;
  676.                 const charCount = cleaned.length;
  677.                  
  678.                 document.getElementById('originalLines').textContent = origLines;
  679.                 document.getElementById('cleanedLines').textContent = cleanedLines;
  680.                 document.getElementById('charCount').textContent = charCount;
  681.                 document.getElementById('processTime').textContent = time + 'ms';
  682.             }
  683.             
  684.             // 显示结果
  685.             function displayResults(text) {
  686.                 cleanedContent.textContent = text;
  687.                 resultContainer.style.display = 'block';
  688.             }
  689.             
  690.             // 下载功能
  691.             downloadBtn.addEventListener('click', function() {
  692.                 if (!cleanedText) return;
  693.                  
  694.                 const blob = new Blob([cleanedText], { type: 'text/plain' });
  695.                 const url = URL.createObjectURL(blob);
  696.                  
  697.                 const a = document.createElement('a');
  698.                 a.href = url;
  699.                 a.download = currentFile ?
  700.                     currentFile.name.replace('.srt', '_cleaned.txt') :
  701.                     'cleaned_subtitles.txt';
  702.                 document.body.appendChild(a);
  703.                 a.click();
  704.                  
  705.                 setTimeout(() => {
  706.                     document.body.removeChild(a);
  707.                     window.URL.revokeObjectURL(url);
  708.                 }, 0);
  709.             });
  710.             
  711.             // 复制功能
  712.             copyBtn.addEventListener('click', function() {
  713.                 if (!cleanedText) return;
  714.                  
  715.                 navigator.clipboard.writeText(cleanedText)
  716.                     .then(() => {
  717.                         const originalText = copyBtn.innerHTML;
  718.                         copyBtn.innerHTML = '&#10003; 已复制!';
  719.                         showStatus('内容已复制到剪贴板', 'success');
  720.                         setTimeout(() => {
  721.                             copyBtn.innerHTML = originalText;
  722.                         }, 2000);
  723.                     })
  724.                     .catch(err => {
  725.                         console.error('复制失败:', err);
  726.                         showStatus('复制失败,请手动选择文本复制', 'error');
  727.                     });
  728.             });
  729.             
  730.             // 处理新文件
  731.             newFileBtn.addEventListener('click', function() {
  732.                 fileInput.value = '';
  733.                 fileInfo.textContent = '';
  734.                 resultContainer.style.display = 'none';
  735.                 cleanedText = '';
  736.                 originalContent = '';
  737.                 currentFile = null;
  738.                 hideStatus();
  739.             });
  740.             
  741.             // 预览切换
  742.             toggleButtons.forEach(button => {
  743.                 button.addEventListener('click', function() {
  744.                     toggleButtons.forEach(btn => btn.classList.remove('active'));
  745.                     this.classList.add('active');
  746.                      
  747.                     if (this.dataset.preview === 'original') {
  748.                         cleanedContent.textContent = originalContent;
  749.                     } else {
  750.                         cleanedContent.textContent = cleanedText;
  751.                     }
  752.                 });
  753.             });
  754.             
  755.             // 状态消息显示
  756.             function showStatus(message, type) {
  757.                 statusMessage.textContent = message;
  758.                 statusMessage.className = 'status ' + type;
  759.             }
  760.             
  761.             function hideStatus() {
  762.                 statusMessage.style.display = 'none';
  763.             }
  764.             
  765.             // 初始示例显示
  766.             showStatus('请上传SRT字幕文件进行处理', 'info');
  767.         });
  768.     </script>
  769. </body>
  770. </html>
复制代码


回复

您需要登录后才可以回帖 登录 | 立即注册 微信登录

本版积分规则

您需要 登录 后才可以回复,轻松玩转社区,没有帐号?立即注册
快速回复
关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表