Copy motorola jira id and summary

Add two button to copy the jira id and summary

目前為 2021-09-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Copy motorola jira id and summary
// @name:zh-CN   快速复制jira id和summary
// @namespace    http://tampermonkey.net/
// @description  Add two button to copy the jira id and summary
// @description:zh-cn  添加两个按钮用于快速复制motorola jira的id和summary
// @author       Andy
// @version      0.1
// @include      https://idart.mot.com/browse/*
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    GM_addStyle(`
      #snackbar {
  visibility: hidden;
  min-width: 250px;
  margin-left: -125px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 2px;
  padding: 16px;
  position: fixed;
  z-index: 1;
  left: 50%;
  top: 50px;
  font-size: 17px;
}

#snackbar.show {
  visibility: visible;
  -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@-webkit-keyframes fadein {
  from {top: 0; opacity: 0;}
  to {top: 50px; opacity: 1;}
}

@keyframes fadein {
  from {top: 0; opacity: 0;}
  to {top: 50px; opacity: 1;}
}

@-webkit-keyframes fadeout {
  from {top: 50px; opacity: 1;}
  to {top: 0; opacity: 0;}
}

@keyframes fadeout {
  from {top: 50px; opacity: 1;}
  to {top: 0; opacity: 0;}
}
    `);
    var observeDOM = (function () {
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
        var eventListenerSupported = window.addEventListener;

        return function (obj, onAddCallback, onRemoveCallback) {
            if (MutationObserver) {
                // define a new observer
                var mutationObserver = new MutationObserver(function (mutations, observer) {
                    if (mutations[0].addedNodes.length && onAddCallback != undefined) {
                        onAddCallback();
                    }
                });
                // have the observer observe foo for changes in children
                mutationObserver.observe(obj, {
                    childList: true
                });
            } else if (eventListenerSupported) {
                obj.addEventListener('DOMNodeInserted', onAddCallback, false);
            }
        };
    })();


    var ff = function () {
        setTimeout(function () {
            if (document.getElementById("copy_id") == null) {
                addCopyBtn();
            }
        }, 0);
    }

    var target = document.getElementsByTagName('body')[0];
    observeDOM(target, /*onAdd*/ ff, /*onRemove*/ ff);

})();

function addCopyBtn() {
    const body = document.getElementById('stalker');
    const issueKey = document.getElementById("key-val");
    const issueName = document.getElementById("summary-val");

    const divE = document.createElement("div");
    divE.id="snackbar";
    divE.innerHTML="Copied succesfully"
    body.appendChild(divE);

    const newElement = document.createElement("li");
    const idE = document.createElement("a");
    idE.innerHTML="Copy id";
    idE.className="aui-button aui-button-primary aui-style";
    idE.id="copy_id";
    idE.onclick= (e) => {
        var snackbar = document.getElementById("snackbar");
        snackbar.className = "show";

        navigator.clipboard.writeText(issueKey.childNodes[0].data);
        //console.log("CopyId_"+ issueKey.childNodes[0].data);

        setTimeout(function(){
            snackbar.className = snackbar.className.replace("show", "");
        }, 1500);
    };
    newElement.appendChild(idE);
    issueKey.parentNode.parentNode.appendChild(newElement);

    const newElement2 = document.createElement("li");
    const summaryE = document.createElement("a");
    summaryE.className="aui-button aui-button-primary aui-style";
    summaryE.innerHTML="Copy summary";
    summaryE.id="copy_summary";
    summaryE.onclick= (e) => {
        var snackbar = document.getElementById("snackbar");
        snackbar.className = "show";

        navigator.clipboard.writeText(issueName.childNodes[0].data);
        //console.log("CopySummary_"+ issueName.childNodes[0].data);

        setTimeout(function(){
            snackbar.className = snackbar.className.replace("show", "");
        }, 1500);
    };

    newElement2.appendChild(summaryE);
    issueKey.parentNode.parentNode.appendChild(newElement2);
}