// ==UserScript== // @name 复制信息提交 // @namespace http://tampermonkey.net/ // @version 2025-06-20 // @description try to take over the world! // @author You // @match http://nycs-redmine.shangyoo.cn/issues/* // @icon https://www.google.com/s2/favicons?sz=64&domain=shangyoo.cn // @grant none // ==/UserScript== (function() { 'use strict'; // 创建按钮元素 var button = document.createElement('button'); button.innerText = '复制提交描述'; button.style.position = 'fixed'; button.style.right = '410px'; button.style.top = '110px'; button.style.zIndex = '9999'; // 将按钮添加到页面中 document.body.appendChild(button); // 点击按钮时的事件处理函数 button.addEventListener('click', function() { // 获取 xpath 路径对应的元素 var element = document.evaluate('/html/body/div[1]/div[2]/div[1]/div[3]/div[2]/h2', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (element) { // 获取第一个 class="showValue" 的标签的内容 var showValueElement = document.querySelector('.showValue'); var showValueContent = showValueElement ? showValueElement.textContent : ''; var parentValueContent = ''; // 获取 class="subject" 元素 var subject = document.querySelector('.subject'); if (subject) { // 获取第一个 div/p/a 元素的 content var allChildren = subject.querySelector('div, p, a'); if (allChildren.childElementCount > 1) { parentValueContent = allChildren.firstChild.textContent.split(' ')[1].replace(':', ''); } showValueContent = allChildren.lastChild.outerText.substr(allChildren.lastChild.outerText.lastIndexOf("\n")+1); } var element2 = document.evaluate('/html/body/div[1]/div[2]/div[1]/div[3]/div[2]/div[2]/div[4]/div[2]/div[2]/div[1]/div[2]/span[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (element2) { var userNameElement = document.querySelector('a.user.active'); var userNameContent = userNameElement ? userNameElement.textContent : ''; } // 拼接内容 var contentToCopy = showValueContent + '\n'+ '需求:' + element2.textContent.split('')[1] + element2.textContent.split('')[3] + ' 单号:'+ element.textContent.split(' ')[1].replace('#', ''); // 创建一个临时文本输入框 var tempInput = document.createElement('textarea'); tempInput.style.position = 'fixed'; tempInput.style.opacity = 0; tempInput.value = contentToCopy; // 将临时输入框添加到页面中 document.body.appendChild(tempInput); // 选中临时输入框的内容 tempInput.select(); tempInput.setSelectionRange(0, 99999); // 兼容移动设备 // 复制文本到剪贴板 document.execCommand('copy'); // 移除临时输入框 document.body.removeChild(tempInput); } }); })();