// ==UserScript== // @name 飞书妙计自动复制转换后的文字到剪切板 // @namespace http://tampermonkey.net/ // @version 0.5 // @description Extract title and subtitle from Feishu Meeting Minutes, format and copy to clipboard with centered non-blocking alerts and retry mechanism // @author You // @match https://*.feishu.cn/minutes/obcn* // @grant GM_setClipboard // @license GPLv3 // @downloadURL none // ==/UserScript== (function() { 'use strict'; function notify(message) { const notificationBoxId = 'tm-notification-box'; let box = document.getElementById(notificationBoxId); if (!box) { box = document.createElement('div'); box.id = notificationBoxId; Object.assign(box.style, { position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', backgroundColor: 'lightgrey', padding: '20px', zIndex: 10000, borderRadius: '10px', boxShadow: '0 4px 8px rgba(0,0,0,0.5)', textAlign: 'center', maxWidth: '80%', wordWrap: 'break-word' }); document.body.appendChild(box); } box.style.display = 'block'; box.textContent = message; setTimeout(() => { box.style.display = 'none'; }, 3000); } function copyToClipboard(text) { try { GM_setClipboard(text); notify('已复制到剪切板'); } catch (e) { notify('复制失败,请手动复制'); } } function extractAndCopy(triesLeft = 3) { if (triesLeft === 0) { notify('查找失败,已放弃'); return; } notify('正在查找信息...'); const titleXpath = "//div[@class='larkw-web-header-caption-head-title-edit']//span"; const textXpath = "//div[@class='subtitle-comp']/div[@id='subtitle-scroll-container']"; const titleResults = document.evaluate(titleXpath, document, null, XPathResult.ANY_TYPE, null); const textResults = document.evaluate(textXpath, document, null, XPathResult.ANY_TYPE, null); const titleElement = titleResults.iterateNext(); const textElement = textResults.iterateNext(); if (titleElement && textElement) { const titleContent = titleElement.textContent || ""; const textContent = textElement.textContent || ""; if (titleContent && textContent) { notify('查找成功'); copyToClipboard(`#### ${titleContent}\n${textContent}\n\n`); } else { notify('查找成功,但是没有找到完整的内容'); } } else { notify(`查找失败,尝试剩余次数:${triesLeft - 1}`); setTimeout(() => extractAndCopy(triesLeft - 1), 1000); } } if (document.readyState === "complete" || document.readyState === "interactive") { setTimeout(extractAndCopy, 1000); } else { document.addEventListener("DOMContentLoaded", () => setTimeout(extractAndCopy, 1000)); } })();