返回列表 发布新帖

油猴脚本,一键导出腾讯会议转写内容

2884 0
小K网牛逼 发表于 2026-5-13 00:00:21 | 查看全部 阅读模式 <

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

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

×
想把腾讯视频会议转写的文字稿导出,在网上找到一个油猴脚本,无法使用,然后放到deepseek里面让其修改,经过几次反复,修改成功。下面是代码,复制到油猴里面就可以用了。代码里面有修改前代码的github地址。

油猴脚本,一键导出腾讯会议转写内容

油猴脚本,一键导出腾讯会议转写内容

  1. // ==UserScript==
  2. // @name         腾讯会议转写纪要导出神器 (Tencent Meeting Transcript Exporter) 修复版
  3. // @namespace    https://github.com/awesome-tampermonkey
  4. // @version      1.1.2
  5. // @description  一键导出腾讯会议录制视频和纯文字转写的内容和纪要,支持Markdown、HTML、TXT格式导出和复制
  6. // @author       东哥说AI
  7. // @match        https://meeting.tencent.com/cw/*
  8. // @match        https://meeting.tencent.com/ct/*
  9. // @grant        none
  10. // @license      MIT
  11. // ==/UserScript==
  12. (function() {
  13.     'use strict';
  14.     const CONFIG = {
  15.         BUTTON_STYLE: `
  16.             position: fixed;
  17.             top: 20px;
  18.             right: 20px;
  19.             z-index: 10000;
  20.             background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  21.             color: white;
  22.             border: none;
  23.             border-radius: 8px;
  24.             padding: 12px 20px;
  25.             font-size: 14px;
  26.             font-weight: 600;
  27.             cursor: pointer;
  28.             box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  29.             transition: all 0.3s ease;
  30.             font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  31.         `,
  32.         MODAL_STYLE: `
  33.             position: fixed;
  34.             top: 0;
  35.             left: 0;
  36.             width: 100%;
  37.             height: 100%;
  38.             background: rgba(0, 0, 0, 0.7);
  39.             z-index: 10001;
  40.             display: flex;
  41.             justify-content: center;
  42.             align-items: center;
  43.         `,
  44.         MODAL_CONTENT_STYLE: `
  45.             background: white;
  46.             border-radius: 12px;
  47.             padding: 30px;
  48.             max-width: 500px;
  49.             width: 90%;
  50.             box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  51.             font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  52.         `
  53.     };
  54.     const utils = {
  55.         getPageType() {
  56.             const url = window.location.href;
  57.             if (url.includes('/cw/')) return 'recording';
  58.             if (url.includes('/ct/')) return 'transcript';
  59.             return 'unknown';
  60.         },
  61.         getMeetingTitle() {
  62.             // 尝试多种方式获取会议标题
  63.             const selectors = [
  64.                 '.meeting-main-subject .subject',
  65.                 '.meeting-subject',
  66.                 '.meeting-title',
  67.                 '.style_header-info__6mQkP', // 新增选择器
  68.                 'h1', // 通用标题
  69.             ];
  70.             
  71.             for (const sel of selectors) {
  72.                 const el = document.querySelector(sel);
  73.                 if (el) {
  74.                     const text = el.textContent.trim();
  75.                     // 如果只获取到部分内容(比如"返回"等),继续查找
  76.                     if (text && text.length > 3 && !text.startsWith('返回')) {
  77.                         return text;
  78.                     }
  79.                 }
  80.             }
  81.             
  82.             // 如果以上都失败,从URL或其他地方获取
  83.             const pageTitle = document.title;
  84.             if (pageTitle && pageTitle !== '腾讯会议') {
  85.                 return pageTitle;
  86.             }
  87.             
  88.             return '腾讯会议转写';
  89.         },
  90.          
  91.         getRecordingTime() {
  92.             // 尝试从页面中提取录制时间
  93.             const selectors = [
  94.                 '.meeting-begin-time-in-date',
  95.                 '.meeting-time',
  96.                 '[class*="time"]',
  97.             ];
  98.             
  99.             for (const sel of selectors) {
  100.                 const el = document.querySelector(sel);
  101.                 if (el) {
  102.                     const text = el.textContent.trim();
  103.                     // 匹配时间格式
  104.                     if (/\d{4}[\/\-]\d{2}[\/\-]\d{2}/.test(text)) {
  105.                         return text.match(/\d{4}[\/\-]\d{2}[\/\-]\d{2}[\s\d\:]*/)[0];
  106.                     }
  107.                 }
  108.             }
  109.             
  110.             return new Date().toLocaleString('zh-CN');
  111.         },
  112.          
  113.         getMeetingKeywords() {
  114.             const keywords = [];
  115.             const topicElements = document.querySelectorAll('.topicTag .topicText');
  116.             topicElements.forEach(element => {
  117.                 const keyword = element.textContent.trim();
  118.                 if (keyword) {
  119.                     keywords.push(keyword);
  120.                 }
  121.             });
  122.             return keywords;
  123.         },
  124.         getCurrentTabType() {
  125.             const pageType = this.getPageType();
  126.             if (pageType === 'transcript') return 'both';
  127.             const activeTab = document.querySelector('.met-tabs__tabitem.is-active .tab');
  128.             if (!activeTab) return 'transcript';
  129.             const tabText = activeTab.textContent.trim();
  130.             if (tabText.includes('纪要')) return 'summary';
  131.             return 'transcript';
  132.         },
  133.         // 修复后的转写内容获取方法
  134.         async getTranscriptContent() {
  135.             const pageType = this.getPageType();
  136.             
  137.             // 查找虚拟滚动容器
  138.             const scrollContainer = document.querySelector('.minutes-module-list');
  139.             
  140.             if (!scrollContainer) {
  141.                 return this.getTranscriptContentFallback();
  142.             }
  143.             
  144.             // 检查是否需要滚动
  145.             if (scrollContainer.scrollHeight <= scrollContainer.clientHeight + 100) {
  146.                 return this.getTranscriptContentFallback();
  147.             }
  148.             
  149.             const originalScrollTop = scrollContainer.scrollTop;
  150.             let allContent = new Map();
  151.             let lastScrollTop = -1;
  152.             let stuckCounter = 0;
  153.             
  154.             try {
  155.                 // 先滚动到顶部
  156.                 scrollContainer.scrollTop = 0;
  157.                 await this.sleep(300);
  158.                  
  159.                 // 持续滚动直到底部
  160.                 while (scrollContainer.scrollTop !== lastScrollTop && stuckCounter < 3) {
  161.                     lastScrollTop = scrollContainer.scrollTop;
  162.                      
  163.                     // 收集当前可见的内容
  164.                     const paragraphs = document.querySelectorAll('.paragraph-module_detail-page-style__Lhz8l');
  165.                      
  166.                     paragraphs.forEach(para => {
  167.                         const pid = para.getAttribute('data-pid');
  168.                         if (!pid || allContent.has(pid)) return;
  169.                         
  170.                         const speakerElement = para.querySelector('.paragraph-module_speaker-name__afSbd');
  171.                         const timeElement = para.querySelector('.paragraph-module_p-start-time__QAWWl');
  172.                         const textElement = para.querySelector('.paragraph-module_sentences__zK2oL');
  173.                         
  174.                         if (textElement && textElement.textContent.trim()) {
  175.                             allContent.set(pid, {
  176.                                 pid: parseInt(pid),
  177.                                 time: timeElement ? timeElement.textContent.trim() : '',
  178.                                 speaker: speakerElement ? speakerElement.textContent.trim() : '未知发言人',
  179.                                 text: textElement.textContent.trim()
  180.                             });
  181.                         }
  182.                     });
  183.                      
  184.                     // 向下滚动
  185.                     const newScrollTop = scrollContainer.scrollTop + scrollContainer.clientHeight * 0.8;
  186.                     scrollContainer.scrollTop = newScrollTop;
  187.                      
  188.                     // 等待渲染
  189.                     await this.sleep(150);
  190.                      
  191.                     // 检查是否卡住
  192.                     if (scrollContainer.scrollTop === lastScrollTop) {
  193.                         stuckCounter++;
  194.                         // 尝试多滚动一点
  195.                         scrollContainer.scrollTop += 50;
  196.                         await this.sleep(100);
  197.                     } else {
  198.                         stuckCounter = 0;
  199.                     }
  200.                 }
  201.                  
  202.                 // 恢复原始滚动位置
  203.                 scrollContainer.scrollTop = originalScrollTop;
  204.                  
  205.                 // 按pid排序
  206.                 return Array.from(allContent.values()).sort((a, b) => a.pid - b.pid);
  207.                  
  208.             } catch (error) {
  209.                 console.error('获取转写内容失败:', error);
  210.                 scrollContainer.scrollTop = originalScrollTop;
  211.                 return this.getTranscriptContentFallback();
  212.             }
  213.         },
  214.          
  215.         getTranscriptContentFallback() {
  216.             const paragraphs = document.querySelectorAll('.paragraph-module_detail-page-style__Lhz8l');
  217.             let content = [];
  218.             
  219.             paragraphs.forEach(para => {
  220.                 const speakerElement = para.querySelector('.paragraph-module_speaker-name__afSbd');
  221.                 const timeElement = para.querySelector('.paragraph-module_p-start-time__QAWWl');
  222.                 const textElement = para.querySelector('.paragraph-module_sentences__zK2oL');
  223.                  
  224.                 if (textElement && textElement.textContent.trim()) {
  225.                     content.push({
  226.                         time: timeElement ? timeElement.textContent.trim() : '',
  227.                         speaker: speakerElement ? speakerElement.textContent.trim() : '未知发言人',
  228.                         text: textElement.textContent.trim()
  229.                     });
  230.                 }
  231.             });
  232.             
  233.             return content;
  234.         },
  235.         sleep(ms) {
  236.             return new Promise(resolve => setTimeout(resolve, ms));
  237.         },
  238.         getSummaryContent() {
  239.             const pageType = this.getPageType();
  240.             
  241.             if (pageType === 'transcript') {
  242.                 const summaryContainer = document.querySelector('.aisummary-container .summary-content-wrap');
  243.                 if (!summaryContainer) return null;
  244.                 const elements = summaryContainer.querySelectorAll('h4, p, li');
  245.                 return Array.from(elements).map(el => ({
  246.                     type: el.tagName.toLowerCase(),
  247.                     text: el.textContent.trim()
  248.                 })).filter(item => item.text);
  249.             }
  250.             const summaryContainer = document.querySelector('.summary-content-wrap');
  251.             if (!summaryContainer) return null;
  252.             const elements = summaryContainer.querySelectorAll('h4, p, li, div[contenteditable="true"]');
  253.             return Array.from(elements).map(el => ({
  254.                 type: el.tagName.toLowerCase(),
  255.                 text: el.textContent.trim()
  256.             })).filter(item => item.text);
  257.         },
  258.         formatAsMarkdown(data, type) {
  259.             const title = this.getMeetingTitle();
  260.             const recordingTime = this.getRecordingTime();
  261.             const keywords = this.getMeetingKeywords();
  262.             const exportTime = new Date().toLocaleString('zh-CN');
  263.             
  264.             let markdown = `# ${title}\n\n`;
  265.             markdown += `**录制时间**: ${recordingTime}\n`;
  266.             markdown += `**导出时间**: ${exportTime}\n`;
  267.             markdown += `**内容类型**: ${type === 'transcript' ? '转写内容' : '会议纪要'}\n`;
  268.             
  269.             if (keywords.length > 0) {
  270.                 markdown += `**会议关键词**: ${keywords.join('、')}\n`;
  271.             }
  272.             markdown += `\n---\n\n`;
  273.             
  274.             if (type === 'transcript' && Array.isArray(data)) {
  275.                 markdown += `## 转写内容\n\n`;
  276.                 data.forEach(item => {
  277.                     markdown += `### ${item.speaker}${item.time ? ` (${item.time})` : ''}\n\n`;
  278.                     markdown += `${item.text}\n\n---\n\n`;
  279.                 });
  280.             } else if (type === 'summary' && Array.isArray(data)) {
  281.                 markdown += `## 会议纪要\n\n`;
  282.                 data.forEach(item => {
  283.                     if (item.type === 'h4') {
  284.                         markdown += `### ${item.text}\n\n`;
  285.                     } else if (item.type === 'li') {
  286.                         markdown += `- ${item.text}\n`;
  287.                     } else {
  288.                         markdown += `${item.text}\n\n`;
  289.                     }
  290.                 });
  291.             }
  292.             
  293.             return markdown;
  294.         },
  295.         formatAsHTML(data, type) {
  296.             const title = this.getMeetingTitle();
  297.             const recordingTime = this.getRecordingTime();
  298.             const keywords = this.getMeetingKeywords();
  299.             const exportTime = new Date().toLocaleString('zh-CN');
  300.             
  301.             let html = `<!DOCTYPE html>\n<html lang="zh-CN">\n<head>\n`;
  302.             html += `    <meta charset="UTF-8">\n`;
  303.             html += `    <meta name="viewport" content="width=device-width, initial-scale=1.0">\n`;
  304.             html += `    <title>${title}</title>\n`;
  305.             html += `    <style>\n`;
  306.             html += `        body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; }\n`;
  307.             html += `        .header { border-bottom: 2px solid #eee; padding-bottom: 20px; margin-bottom: 30px; }\n`;
  308.             html += `        .transcript-item { margin-bottom: 20px; padding: 15px; background: #f8f9fa; border-radius: 8px; }\n`;
  309.             html += `        .speaker { font-weight: bold; color: #2c3e50; }\n`;
  310.             html += `        .time { color: #7f8c8d; font-size: 0.9em; }\n`;
  311.             html += `        .content { margin-top: 8px; }\n`;
  312.             html += `        .keywords { margin: 10px 0; }\n`;
  313.             html += `        .keyword-tag { display: inline-block; background: #e3f2fd; color: #1976d2; padding: 4px 8px; margin: 2px; border-radius: 4px; font-size: 0.9em; }\n`;
  314.             html += `    </style>\n</head>\n<body>\n`;
  315.             
  316.             html += `    <div class="header">\n`;
  317.             html += `        <h1>${title}</h1>\n`;
  318.             html += `        <p><strong>录制时间</strong>: ${recordingTime}</p>\n`;
  319.             html += `        <p><strong>导出时间</strong>: ${exportTime}</p>\n`;
  320.             html += `        <p><strong>内容类型</strong>: ${type === 'transcript' ? '转写内容' : '会议纪要'}</p>\n`;
  321.             if (keywords.length > 0) {
  322.                 html += `        <div class="keywords">\n`;
  323.                 html += `            <strong>会议关键词</strong>: `;
  324.                 keywords.forEach(keyword => {
  325.                     html += `<span class="keyword-tag">${keyword}</span>`;
  326.                 });
  327.                 html += `\n        </div>\n`;
  328.             }
  329.             html += `    </div>\n`;
  330.             
  331.             if (type === 'transcript' && Array.isArray(data)) {
  332.                 html += `    <h2>转写内容</h2>\n`;
  333.                 data.forEach(item => {
  334.                     html += `    <div class="transcript-item">\n`;
  335.                     html += `        <div class="speaker">${item.speaker}${item.time ? ` <span class="time">(${item.time})</span>` : ''}</div>\n`;
  336.                     html += `        <div class="content">${item.text}</div>\n`;
  337.                     html += `    </div>\n`;
  338.                 });
  339.             } else if (type === 'summary' && Array.isArray(data)) {
  340.                 html += `    <h2>会议纪要</h2>\n`;
  341.                 data.forEach(item => {
  342.                     if (item.type === 'h4') {
  343.                         html += `    <h3>${item.text}</h3>\n`;
  344.                     } else if (item.type === 'li') {
  345.                         html += `    <li>${item.text}</li>\n`;
  346.                     } else {
  347.                         html += `    <p>${item.text}</p>\n`;
  348.                     }
  349.                 });
  350.             }
  351.             
  352.             html += `</body>\n</html>`;
  353.             return html;
  354.         },
  355.         formatAsTXT(data, type) {
  356.             const title = this.getMeetingTitle();
  357.             const recordingTime = this.getRecordingTime();
  358.             const keywords = this.getMeetingKeywords();
  359.             const exportTime = new Date().toLocaleString('zh-CN');
  360.             
  361.             let txt = `${title}\n`;
  362.             txt += `${'='.repeat(Math.min(title.length, 50))}\n\n`;
  363.             txt += `录制时间: ${recordingTime}\n`;
  364.             txt += `导出时间: ${exportTime}\n`;
  365.             txt += `内容类型: ${type === 'transcript' ? '转写内容' : '会议纪要'}\n`;
  366.             
  367.             if (keywords.length > 0) {
  368.                 txt += `会议关键词: ${keywords.join('、')}\n`;
  369.             }
  370.             txt += `\n`;
  371.             
  372.             if (type === 'transcript' && Array.isArray(data)) {
  373.                 txt += `转写内容\n${'-'.repeat(10)}\n\n`;
  374.                 data.forEach(item => {
  375.                     txt += `${item.speaker}${item.time ? ` (${item.time})` : ''}\n`;
  376.                     txt += `${item.text}\n\n`;
  377.                 });
  378.             } else if (type === 'summary' && Array.isArray(data)) {
  379.                 txt += `会议纪要\n${'-'.repeat(10)}\n\n`;
  380.                 data.forEach(item => {
  381.                     if (item.type === 'h4') {
  382.                         txt += `\n${item.text}\n${'-'.repeat(Math.min(item.text.length, 30))}\n`;
  383.                     } else if (item.type === 'li') {
  384.                         txt += `&#8226; ${item.text}\n`;
  385.                     } else {
  386.                         txt += `${item.text}\n\n`;
  387.                     }
  388.                 });
  389.             }
  390.             
  391.             return txt;
  392.         },
  393.         downloadFile(content, filename, type) {
  394.             const mimeTypes = {
  395.                 'md': 'text/markdown',
  396.                 'html': 'text/html',
  397.                 'txt': 'text/plain'
  398.             };
  399.             
  400.             const blob = new Blob(['\ufeff' + content], { type: mimeTypes[type] || 'text/plain' }); // 添加BOM解决中文乱码
  401.             const url = URL.createObjectURL(blob);
  402.             const a = document.createElement('a');
  403.             a.href = url;
  404.             a.download = filename;
  405.             document.body.appendChild(a);
  406.             a.click();
  407.             document.body.removeChild(a);
  408.             URL.revokeObjectURL(url);
  409.         },
  410.         async copyToClipboard(text) {
  411.             try {
  412.                 await navigator.clipboard.writeText(text);
  413.                 return true;
  414.             } catch (err) {
  415.                 const textArea = document.createElement('textarea');
  416.                 textArea.value = text;
  417.                 textArea.style.position = 'fixed';
  418.                 textArea.style.opacity = '0';
  419.                 document.body.appendChild(textArea);
  420.                 textArea.select();
  421.                 const success = document.execCommand('copy');
  422.                 document.body.removeChild(textArea);
  423.                 return success;
  424.             }
  425.         },
  426.         showMessage(message, type = 'success') {
  427.             const existingMsg = document.querySelector('.tm-exporter-message');
  428.             if (existingMsg) existingMsg.remove();
  429.             
  430.             const messageDiv = document.createElement('div');
  431.             messageDiv.className = 'tm-exporter-message';
  432.             const colors = {
  433.                 'success': '#10b981',
  434.                 'error': '#ef4444',
  435.                 'info': '#3b82f6',
  436.                 'warning': '#f59e0b'
  437.             };
  438.             messageDiv.style.cssText = `
  439.                 position: fixed;
  440.                 top: 80px;
  441.                 right: 20px;
  442.                 z-index: 10002;
  443.                 padding: 12px 20px;
  444.                 border-radius: 6px;
  445.                 color: white;
  446.                 font-weight: 600;
  447.                 font-size: 14px;
  448.                 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  449.                 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  450.                 transition: all 0.3s ease;
  451.                 background: ${colors[type] || colors.success};
  452.                 max-width: 400px;
  453.                 word-wrap: break-word;
  454.             `;
  455.             messageDiv.textContent = message;
  456.             document.body.appendChild(messageDiv);
  457.             
  458.             setTimeout(() => {
  459.                 messageDiv.style.opacity = '0';
  460.                 messageDiv.style.transform = 'translateX(100%)';
  461.                 setTimeout(() => {
  462.                     if (messageDiv.parentNode) {
  463.                         messageDiv.parentNode.removeChild(messageDiv);
  464.                     }
  465.                 }, 300);
  466.             }, 3000);
  467.         }
  468.     };
  469.     class TencentMeetingExporter {
  470.         constructor() {
  471.             this.init();
  472.         }
  473.         init() {
  474.             this.createExportButton();
  475.         }
  476.         createExportButton() {
  477.             // 移除已存在的按钮
  478.             const existingBtn = document.querySelector('.tm-exporter-btn');
  479.             if (existingBtn) existingBtn.remove();
  480.             
  481.             const button = document.createElement('button');
  482.             button.className = 'tm-exporter-btn';
  483.             button.textContent = '&#128221; 导出转写/纪要';
  484.             button.style.cssText = CONFIG.BUTTON_STYLE;
  485.             
  486.             button.addEventListener('mouseenter', () => {
  487.                 button.style.transform = 'translateY(-2px)';
  488.                 button.style.boxShadow = '0 6px 20px rgba(102, 126, 234, 0.6)';
  489.             });
  490.             
  491.             button.addEventListener('mouseleave', () => {
  492.                 button.style.transform = 'translateY(0)';
  493.                 button.style.boxShadow = '0 4px 15px rgba(102, 126, 234, 0.4)';
  494.             });
  495.             
  496.             button.addEventListener('click', () => {
  497.                 this.showExportModal();
  498.             });
  499.             
  500.             document.body.appendChild(button);
  501.         }
  502.         showExportModal() {
  503.             const currentTab = utils.getCurrentTabType();
  504.             let modalHTML;
  505.             if (currentTab === 'both') {
  506.                 modalHTML = `
  507.                     <h2 style="margin: 0 0 20px 0; color: #2c3e50; font-size: 24px;">导出转写/纪要</h2>
  508.                     <p style="margin: 0 0 25px 0; color: #7f8c8d; line-height: 1.5;">选择要导出的内容类型和格式</p>
  509.                     <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 25px;">
  510.                         <button id="export-transcript-md" style="padding: 15px; border: 2px solid #3498db; background: white; color: #3498db; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128196; 导出转写(MD)</button>
  511.                         <button id="export-summary-md" style="padding: 15px; border: 2px solid #e74c3c; background: white; color: #e74c3c; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128203; 导出纪要(MD)</button>
  512.                         <button id="export-transcript-html" style="padding: 15px; border: 2px solid #f39c12; background: white; color: #f39c12; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#127760; 导出转写(HTML)</button>
  513.                         <button id="export-summary-html" style="padding: 15px; border: 2px solid #9b59b6; background: white; color: #9b59b6; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#127760; 导出纪要(HTML)</button>
  514.                         <button id="export-transcript-txt" style="padding: 15px; border: 2px solid #16a085; background: white; color: #16a085; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128221; 导出转写(TXT)</button>
  515.                         <button id="copy-transcript-md" style="padding: 15px; border: 2px solid #8e44ad; background: white; color: #8e44ad; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128203; 复制转写(MD)</button>
  516.                     </div>
  517.                     <div style="display: flex; justify-content: flex-end; gap: 10px;">
  518.                         <button id="modal-close" style="padding: 10px 20px; border: 1px solid #bdc3c7; background: white; color: #7f8c8d; border-radius: 6px; cursor: pointer;">取消</button>
  519.                     </div>
  520.                 `;
  521.             } else {
  522.                 const tabName = currentTab === 'transcript' ? '转写内容' : '会议纪要';
  523.                 modalHTML = `
  524.                     <h2 style="margin: 0 0 20px 0; color: #2c3e50; font-size: 24px;">导出${tabName}</h2>
  525.                     <p style="margin: 0 0 25px 0; color: #7f8c8d; line-height: 1.5;">选择导出格式,文件名将自动使用会议标题</p>
  526.                     <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 25px;">
  527.                         <button id="export-md" style="padding: 15px; border: 2px solid #3498db; background: white; color: #3498db; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128196; Markdown</button>
  528.                         <button id="export-html" style="padding: 15px; border: 2px solid #e74c3c; background: white; color: #e74c3c; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#127760; HTML</button>
  529.                         <button id="export-txt" style="padding: 15px; border: 2px solid #f39c12; background: white; color: #f39c12; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128221; TXT</button>
  530.                         <button id="copy-md" style="padding: 15px; border: 2px solid #9b59b6; background: white; color: #9b59b6; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.3s ease;">&#128203; 复制Markdown</button>
  531.                     </div>
  532.                     <div style="display: flex; justify-content: flex-end; gap: 10px;">
  533.                         <button id="modal-close" style="padding: 10px 20px; border: 1px solid #bdc3c7; background: white; color: #7f8c8d; border-radius: 6px; cursor: pointer;">取消</button>
  534.                     </div>
  535.                 `;
  536.             }
  537.             const modal = document.createElement('div');
  538.             modal.style.cssText = CONFIG.MODAL_STYLE;
  539.             
  540.             const modalContent = document.createElement('div');
  541.             modalContent.style.cssText = CONFIG.MODAL_CONTENT_STYLE;
  542.             modalContent.innerHTML = modalHTML;
  543.             
  544.             // 添加按钮悬停效果
  545.             const buttons = modalContent.querySelectorAll('button[id^="export-"], button[id^="copy-"]');
  546.             buttons.forEach(btn => {
  547.                 btn.addEventListener('mouseenter', () => {
  548.                     btn.style.background = btn.style.color;
  549.                     btn.style.color = 'white';
  550.                 });
  551.                 btn.addEventListener('mouseleave', () => {
  552.                     btn.style.background = 'white';
  553.                     btn.style.color = btn.style.borderColor;
  554.                 });
  555.             });
  556.             // 绑定事件
  557.             if (currentTab === 'both') {
  558.                 modalContent.querySelector('#export-transcript-md')?.addEventListener('click', () => this.exportContent('md', 'transcript'));
  559.                 modalContent.querySelector('#export-summary-md')?.addEventListener('click', () => this.exportContent('md', 'summary'));
  560.                 modalContent.querySelector('#export-transcript-html')?.addEventListener('click', () => this.exportContent('html', 'transcript'));
  561.                 modalContent.querySelector('#export-summary-html')?.addEventListener('click', () => this.exportContent('html', 'summary'));
  562.                 modalContent.querySelector('#export-transcript-txt')?.addEventListener('click', () => this.exportContent('txt', 'transcript'));
  563.                 modalContent.querySelector('#copy-transcript-md')?.addEventListener('click', () => this.copyContent('transcript'));
  564.             } else {
  565.                 modalContent.querySelector('#export-md')?.addEventListener('click', () => this.exportContent('md'));
  566.                 modalContent.querySelector('#export-html')?.addEventListener('click', () => this.exportContent('html'));
  567.                 modalContent.querySelector('#export-txt')?.addEventListener('click', () => this.exportContent('txt'));
  568.                 modalContent.querySelector('#copy-md')?.addEventListener('click', () => this.copyContent());
  569.             }
  570.             modalContent.querySelector('#modal-close').addEventListener('click', () => this.closeModal(modal));
  571.             
  572.             modal.addEventListener('click', (e) => {
  573.                 if (e.target === modal) {
  574.                     this.closeModal(modal);
  575.                 }
  576.             });
  577.             
  578.             modal.appendChild(modalContent);
  579.             document.body.appendChild(modal);
  580.         }
  581.         async exportContent(format, contentType = null) {
  582.             try {
  583.                 const currentTab = utils.getCurrentTabType();
  584.                 const exportType = contentType || (currentTab === 'both' ? 'transcript' : currentTab);
  585.                 let data;
  586.                 if (exportType === 'transcript') {
  587.                     utils.showMessage('正在获取转写内容,请稍候...', 'info');
  588.                     data = await utils.getTranscriptContent();
  589.                      
  590.                     if (!data || data.length === 0) {
  591.                         utils.showMessage('未找到转写内容,请确保页面已加载完成', 'error');
  592.                         return;
  593.                     }
  594.                      
  595.                     utils.showMessage(`获取成功!共找到 ${data.length} 条转写记录`, 'success');
  596.                 } else {
  597.                     data = utils.getSummaryContent();
  598.                     if (!data || data.length === 0) {
  599.                         utils.showMessage('未找到纪要内容,请确保页面已加载完成', 'error');
  600.                         return;
  601.                     }
  602.                 }
  603.                  
  604.                 const title = utils.getMeetingTitle();
  605.                 const recordingTime = utils.getRecordingTime();
  606.                  
  607.                 let timestamp;
  608.                 if (recordingTime) {
  609.                     timestamp = recordingTime.replace(/[^\d]/g, '').slice(0, 14);
  610.                     if (timestamp.length >= 12) {
  611.                         timestamp = timestamp.slice(0, 8) + '_' + timestamp.slice(8);
  612.                     }
  613.                 } else {
  614.                     const now = new Date();
  615.                     timestamp = now.getFullYear().toString() +
  616.                         (now.getMonth() + 1).toString().padStart(2, '0') +
  617.                         now.getDate().toString().padStart(2, '0') + '_' +
  618.                         now.getHours().toString().padStart(2, '0') +
  619.                         now.getMinutes().toString().padStart(2, '0') +
  620.                         now.getSeconds().toString().padStart(2, '0');
  621.                 }
  622.                  
  623.                 const tabName = exportType === 'transcript' ? '转写' : '纪要';
  624.                 // 清理文件名中的特殊字符
  625.                 const safeTitle = title.replace(/[\\/:*?"<>|]/g, '_');
  626.                 const filename = `${safeTitle}_${tabName}_${timestamp}.${format}`;
  627.                 let content;
  628.                 switch (format) {
  629.                     case 'md':
  630.                         content = utils.formatAsMarkdown(data, exportType);
  631.                         break;
  632.                     case 'html':
  633.                         content = utils.formatAsHTML(data, exportType);
  634.                         break;
  635.                     case 'txt':
  636.                         content = utils.formatAsTXT(data, exportType);
  637.                         break;
  638.                 }
  639.                  
  640.                 utils.downloadFile(content, filename, format);
  641.                 utils.showMessage(`${format.toUpperCase()}文件导出成功!`);
  642.                  
  643.                 const modal = document.querySelector('div[style*="position: fixed"][style*="z-index: 10001"]');
  644.                 if (modal) this.closeModal(modal);
  645.                  
  646.             } catch (error) {
  647.                 console.error('导出失败:', error);
  648.                 utils.showMessage('导出失败:' + error.message, 'error');
  649.             }
  650.         }
  651.         async copyContent(contentType = null) {
  652.             try {
  653.                 const currentTab = utils.getCurrentTabType();
  654.                 const exportType = contentType || (currentTab === 'both' ? 'transcript' : currentTab);
  655.                 let data;
  656.                 if (exportType === 'transcript') {
  657.                     utils.showMessage('正在获取转写内容,请稍候...', 'info');
  658.                     data = await utils.getTranscriptContent();
  659.                      
  660.                     if (!data || data.length === 0) {
  661.                         utils.showMessage('未找到转写内容,请确保页面已加载完成', 'error');
  662.                         return;
  663.                     }
  664.                      
  665.                     utils.showMessage(`获取成功!共找到 ${data.length} 条转写记录`, 'success');
  666.                 } else {
  667.                     data = utils.getSummaryContent();
  668.                     if (!data || data.length === 0) {
  669.                         utils.showMessage('未找到纪要内容,请确保页面已加载完成', 'error');
  670.                         return;
  671.                     }
  672.                 }
  673.                 const content = utils.formatAsMarkdown(data, exportType);
  674.                 const success = await utils.copyToClipboard(content);
  675.                 if (success) {
  676.                     utils.showMessage('Markdown内容已复制到剪贴板!');
  677.                 } else {
  678.                     utils.showMessage('复制失败,请重试', 'error');
  679.                 }
  680.                 const modal = document.querySelector('div[style*="position: fixed"][style*="z-index: 10001"]');
  681.                 if (modal) this.closeModal(modal);
  682.                  
  683.             } catch (error) {
  684.                 console.error('复制失败:', error);
  685.                 utils.showMessage('复制失败:' + error.message, 'error');
  686.             }
  687.         }
  688.         closeModal(modal) {
  689.             modal.style.opacity = '0';
  690.             setTimeout(() => {
  691.                 if (modal.parentNode) {
  692.                     modal.parentNode.removeChild(modal);
  693.                 }
  694.             }, 300);
  695.         }
  696.     }
  697.     // 页面加载完成后初始化
  698.     function init() {
  699.         // 先检查页面是否包含转写内容
  700.         const checkInterval = setInterval(() => {
  701.             const hasContent = document.querySelector('.minutes-module-list');
  702.             if (hasContent) {
  703.                 clearInterval(checkInterval);
  704.                 new TencentMeetingExporter();
  705.             }
  706.         }, 500);
  707.          
  708.         // 最多等待10秒
  709.         setTimeout(() => {
  710.             clearInterval(checkInterval);
  711.             if (!document.querySelector('.tm-exporter-btn')) {
  712.                 new TencentMeetingExporter();
  713.             }
  714.         }, 10000);
  715.     }
  716.     init();
  717. })();
复制代码


回复

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

本版积分规则

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