Greasy Fork

来自缓存

JIRA Copy

Copy Copy Copy!

目前为 2024-10-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         JIRA Copy
// @namespace    http://tampermonkey.net/
// @version      0.4.0
// @description  Copy Copy Copy!
// @author       alex4814
// @match        http://jira.sanguosha.com:8080/browse/PX*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sanguosha.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Wait until the DOM is fully loaded
    window.addEventListener('load', function() {
        // Find the div with class "aui-toolbar2-inner" within the element with id "stalker"
        const toolbarInnerDiv = document.querySelector('#stalker .aui-toolbar2-primary');

        // Check if the div exists
        if (toolbarInnerDiv) {
            // Create a new div to wrap the button
            const wrapperDiv = document.createElement('div');
            wrapperDiv.classList.add('aui-buttons', 'pluggable-ops'); // Apply the required classes

            // Create a new button element
            const button = document.createElement('button');
            button.innerText = '复制单号与标题';

            // Style the button (optional)
            button.style.marginRight = '10px'; // Adds some spacing from other elements
            button.classList.add('aui-button'); // Add any existing button styling class if needed

            // Append the button to the wrapper div
            wrapperDiv.appendChild(button);

            // Insert the button at the first position in the toolbarInnerDiv
            toolbarInnerDiv.insertBefore(wrapperDiv, toolbarInnerDiv.firstChild);

            // Add event listener to the button
            button.addEventListener('click', function() {
                // Get the text content from the two divs
                const issueKeyText = document.getElementById('key-val').textContent.trim();
                const summaryText = document.getElementById('summary-val').textContent.trim();

                // Check if both divs exist and have content
                if (issueKeyText && summaryText) {
                    const combinedText = `#${issueKeyText} ${summaryText}`;

                    // Copy the combined text to the clipboard
                    copyToClipboard(combinedText);
                } else {
                    alert('Could not find both issue key and summary elements!');
                }
            });
        } else {
            console.error('Could not find the div with class "aui-toolbar2-inner" inside #stalker.');
        }
    });

    // Helper function to copy text to clipboard
    function copyToClipboard(text) {
        const tempInput = document.createElement('textarea');
        tempInput.value = text;
        document.body.appendChild(tempInput);
        tempInput.select();
        document.execCommand('copy');
        document.body.removeChild(tempInput);
    }
})();