// ==UserScript== // @name 飞书文档标题复制助手Plus // @namespace http://tampermonkey.net/ // @version 3.1 // @description 让飞书文档更好用:添加标题和时间、解除复制限制、支持右键菜单 // @author 微信11208596 // @match *://*.feishu.cn/* // @match *://*.larkoffice.com/* // @grant none // @run-at document-start // @license UNLICENSED // @downloadURL none // ==/UserScript== (function() { 'use strict'; const a = () => { const b = EventTarget.prototype.addEventListener; EventTarget.prototype.addEventListener = function (c, d, e) { if (c === 'copy') { b.call(this, c, event => { event.stopImmediatePropagation(); return null; }, e); return; } if (c === 'contextmenu') { b.call(this, c, event => { event.stopImmediatePropagation(); return d(event); }, e); return; } b.call(this, c, d, e); }; }; const x = () => { const y = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function (m, n, ...o) { this.addEventListener('readystatechange', function () { if (this.readyState === 4 && n.includes('space/api/suite/permission/document/actions/state/')) { let p = this.responseText; try { p = JSON.parse(p); if (p.data && p.data.actions && p.data.actions.copy !== 1) { p.data.actions.copy = 1; Object.defineProperty(this, 'responseText', { value: JSON.stringify(p) }); Object.defineProperty(this, 'response', { value: p }); } } catch (e) { console.log('修改响应失败:', e); } } }, false); y.call(this, m, n, ...o); }; }; function getTime() { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); return `${year}-${month}-${day} ${hours}:${minutes}`; } function processLink(link) { return link.split('?')[0]; } function formatText(title, link) { return `📄 文件「${title}」\n🔗 链接:\n${processLink(link)}\n🕐 时间「${getTime()}」\n💡 文件已分享,欢迎查阅,有任何问题都可以随时交流~`; } document.addEventListener('DOMContentLoaded', () => { document.addEventListener('copy', function(e) { try { const text = window.getSelection().toString(); if (!text || !text.includes('feishu.cn/')) return; const title = document.title.split(' - ')[0].trim(); if (!title || text.includes(title)) return; e.preventDefault(); e.clipboardData.setData('text/plain', formatText(title, text)); console.log('已添加标题和时间到链接'); } catch (err) { console.log('复制处理出错:', err); } }); document.addEventListener('click', function(e) { const target = e.target; if (!target) return; if (target.textContent?.includes('复制链接') || target.closest('.lark-link-entry-v2__copylink') || target.closest('[data-test-id="copy-share-link"]')) { setTimeout(function() { try { const title = document.title.split(' - ')[0].trim(); if (!title) return; navigator.clipboard.readText().then(function(text) { if (!text || !text.includes('feishu.cn/') || text.includes(title)) return; navigator.clipboard.writeText(formatText(title, text)).catch(function(err) { console.log('写入剪贴板失败:', err); }); }).catch(function(err) { console.log('读取剪贴板失败:', err); }); } catch (err) { console.log('处理复制按钮点击失败:', err); } }, 100); } }); }); a(); x(); console.log('飞书文档标题复制助手Plus已加载,版本3.0'); })();