您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
快速复制id/summary/link,自动working/ready
当前为
// ==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.3 // @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) { GM.log(`mutationObserver`); onAddCallback(); //} }); // have the observer observe foo for changes in children mutationObserver.observe(obj, { childList: true }); } else if (eventListenerSupported) { obj.addEventListener('DOMNodeInserted', onAddCallback, false); } }; })(); detectElementBySelector('#stalker', ()=>{ addButtons(); observeDOM(document.getElementsByClassName('issue-container')[0], /*onAdd*/ addButtons, /*onRemove*/ addButtons); }, 100) })(); function addButtons() { addWorkingButton(); addReadyButton(); if(document.getElementById("copy_id")) return; 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); 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); 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); 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'); let parent = addAndGetWorkFlowDiv(); if(!oriWorkingBtn || !parent || autoWorkingBtn) return; 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(); }); } parent.appendChild(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 = addAndGetWorkFlowDiv(); 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 addAndGetWorkFlowDiv(){ let div = document.getElementById('auto_work_flow'); if(div) return div; let parent = document.querySelector('.aui-toolbar2-primary'); div = document.createElement('div'); div.id = 'auto_work_flow'; div.className = "aui-buttons pluggable-ops"; parent.appendChild(div); return div; } 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;} } `); }