你需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
你需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
你需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
你需要先安装一款用户样式管理器扩展后才能安装此样式。
你需要先安装一款用户样式管理器扩展后才能安装此样式。
你需要先安装一款用户样式管理器扩展后才能安装此样式。
(我已安装用户样式管理器,立即安装用户样式!)
// ==UserScript==
// @name Quick Copy and Auto Working/Ready
// @name:zh-CN 快速复制,自动working/ready
// @namespace http://tampermonkey.net/
// @description Add buttons for copying the id/summary/link and for auto working/ready
// @description:zh-cn 快速复制id/summary/link,自动working/ready
// @author Jackie
// @version 0.1
// @match https://idart.mot.com/browse/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=mot.com
// @run-at document-start
// @grant GM.addStyle
// @grant GM.log
// ==/UserScript==
(function () {
'use strict';
let observeDOM = (function () {
let MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
let eventListenerSupported = window.addEventListener;
return function (obj, onAddCallback, onRemoveCallback) {
if (MutationObserver) {
// define a new observer
let 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);
}
};
})();
detectElementBySelector('.issue-container', ()=>{
addButtons();
observeDOM(document.getElementsByClassName('issue-container')[0], /*onAdd*/ addButtons, /*onRemove*/ addButtons);
}, 100)
})();
function addButtons() {
addWorkingButton();
addReadyButton();
if(document.getElementById("copy_id")) return;
console.log(`=======================addCopyBtn`);
const container = document.getElementById('stalker');
const issueKey = document.getElementById("key-val");
const issueName = document.getElementById("summary-val");
if(!container) return;
const divE = document.createElement("div");
divE.id="snackbar";
divE.innerHTML="Copied succesfully"
container.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);
const newElement3 = document.createElement("li");
const linkE = document.createElement("a");
linkE.className="aui-button aui-button-primary aui-style";
linkE.innerHTML="Copy link";
linkE.id="copy_link";
linkE.onclick= (e) => {
var snackbar = document.getElementById("snackbar");
snackbar.className = "show";
navigator.clipboard.writeText("https://idart.mot.com/browse/" + issueKey.childNodes[0].data);
//console.log("CopyLink_"+ "https://idart.mot.com/browse/" + issueKey.childNodes[0].data);
setTimeout(function(){
snackbar.className = snackbar.className.replace("show", "");
}, 1500);
};
newElement3.appendChild(linkE);
issueKey.parentNode.parentNode.appendChild(newElement3);
const newElement4 = document.createElement("li");
const idSummaryE = document.createElement("a");
idSummaryE.className="aui-button aui-button-primary aui-style";
idSummaryE.innerHTML="Copy as git title";
idSummaryE.id="copy_id_summary";
idSummaryE.onclick= (e) => {
var snackbar = document.getElementById("snackbar");
snackbar.className = "show";
navigator.clipboard.writeText(issueKey.childNodes[0].data + " " + issueName.childNodes[0].data);
setTimeout(function(){
snackbar.className = snackbar.className.replace("show", "");
}, 1500);
};
newElement4.appendChild(idSummaryE);
issueKey.parentNode.parentNode.appendChild(newElement4);
addStyles();
}
function addWorkingButton() {
let oriWorkingBtn = document.querySelector('#action_id_131');
let autoWorkingBtn = document.querySelector('#auto_working');
if(!oriWorkingBtn || autoWorkingBtn) return;
oriWorkingBtn.style.display = 'none';
autoWorkingBtn = createWorkFlowButton('auto_working', 'Auto Working');
autoWorkingBtn.onclick = ()=>{
oriWorkingBtn.click();
detectElementBySelector("#customfield_10572", ()=>{
let targetDate = document.querySelector('#customfield_10572');
targetDate.value = getLastDayOfCurrentMonth();
let workingSubmit = document.querySelector('#issue-workflow-transition-submit');
//workingSubmit.click();
});
}
oriWorkingBtn.parentElement.prepend(autoWorkingBtn);
}
function getLastDayOfCurrentMonth() {
let date = new Date();
let lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
let [_,month,day,year] = lastDay.toDateString().split(' ');
return day + '/'+month+'/'+year.substr(2,2);
}
function addReadyButton() {
let oriReadyBtn = document.getElementById('action_id_541');
if(!oriReadyBtn) return;
let parent = document.getElementById('opsbar-opsbar-transitions');
if(!parent || document.getElementById('btn_ready')) return;
let btnReady = createWorkFlowButton('btn_ready', 'Auto Ready');
btnReady.onclick = ()=>{
oriReadyBtn.click();
// observer ready dialog
detectElementBySelector("#customfield_10867", ()=>{
let testsExecuted = document.querySelector('#customfield_10867');
testsExecuted.textContent = "Test good";
let dependentCRs = document.querySelector('#customfield_10127');
dependentCRs.value = "NA";
let readySubmit = document.querySelector('#issue-workflow-transition-submit');
readySubmit.click();
});
}
parent.appendChild(btnReady);
}
function createWorkFlowButton(id, text){
let btn = document.createElement('a');
btn.id = id;
btn.className = "aui-button toolbar-trigger issueaction-workflow-transition";
let span = document.createElement('span');
span.className = "trigger-label";
span.innerHTML = text;
btn.appendChild(span);
return btn;
}
function detectElementBySelector(selector, action, delay) {
let queryAction = ()=>{
return document.querySelector(selector);
}
if(queryAction()) {
action();
} else {
setTimeout(()=>{
detectElementBySelector(selector, action)
}, delay ? delay : 200);
}
}
function addStyles() {
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;}
}
`);
}
const observeDOM = (function () {
let MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
let eventListenerSupported = window.addEventListener;
return function (obj, onAddCallback, onRemoveCallback) {
if (MutationObserver) {
// define a new observer
let 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);
}
};
})();