mariotatis / Jira Right Cilck in Card: Copy Card Name

// ==UserScript==
// @name           Jira Right Cilck in Card: Copy Card Name
// @author         mariotatis with Oscar De Moya's collab 
// @namespace      https://openuserjs.org/users/mariotatis/scripts
// @description    Points for Jira cumulated story points and shows total points in each column
// @icon           https://www.mariotatis.com/wp-content/uploads/2020/05/favicon-32x32-1.png
// @copyright      2020+, mariotatis.com
// @version        2.0.5
// @license        MIT
// @grant          none
// @include        /^https?:\/\/.*atlassian.*
// ==/UserScript==

(function() {
    'use strict';

    function copyToClipboard(text) {
        if (window.clipboardData && window.clipboardData.setData) {
            return window.clipboardData.setData("Text", text);
        }
        else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
            var textarea = document.createElement("textarea");
            textarea.textContent = text;
            textarea.style.position = "fixed";
            document.body.appendChild(textarea);
            textarea.select();
            try {
                return document.execCommand("copy");
            }
            catch (ex) {
                console.warn("Copy to clipboard failed.", ex);
                return false;
            }
            finally {
                document.body.removeChild(textarea);
            }
        }
    }
    
    var htmlString = [
        '<li class="aui-list-item">',
            '<a class="aui-list-item-link" title="Copy card name" id="copy-card-name" href="#">Copy card name</a>',
        '</li>'
    ].join('');
    
    setTimeout( function() {
        $(".ghx-issue" ).contextmenu(function() {
            setTimeout( function() {
                $('#ghx-issue-ctx-action-copy-issue-link-container').after(htmlString);
            }, 100);
          });
    }, 3000);
    
    $(document).on('hover', '#copy-card-name', function() {
        $( this ).toggleClass("active");
        $('.aui-list-item.active').toggleClass("active");
    });
    
    $(document).on('click', '#copy-card-name', function() {
        copyToClipboard($('.ghx-selected > section:first').text());
        GH.Notification.showSuccess("Card name copied!", { autoHide: true})
    });

})();