Created
October 16, 2019 08:59
-
-
Save filipenevola/abaecfdf0bd8383c679d207ae0634e9a to your computer and use it in GitHub Desktop.
Tampermonkey script to copy id and title of an entity on Target Process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Pathable - Copy TP US title/id | |
// @namespace com.pathable | |
// @include https://pathable.tpondemand.com/* | |
// @version 1.0.5 | |
// @grant GM_setClipboard | |
// ==/UserScript== | |
function formatInfo(usId, usTitle) { | |
return '[' + usId + '] ' + usTitle; | |
} | |
function getUSInfo() { | |
var titleTable = document.querySelector('.view-header'); | |
var usId = titleTable.querySelector('.entity-id').textContent; | |
var usTitle = titleTable.querySelector('.view-header__entity-title').textContent; | |
var usType = titleTable.querySelector('.tau-entity-icon').textContent; | |
return { | |
id: usId, | |
title: usTitle, | |
type: usType | |
}; | |
} | |
function getUSInfoIfTask() { | |
var additionalInfoTable = document.querySelector('.additional-info-table'); | |
var infos = additionalInfoTable.querySelectorAll('.ui-additionalinfo__label'); | |
for (var i = 0, max = infos.length; i < max; i++) { | |
if (infos[i].textContent == 'User Story') { | |
break; | |
} | |
} | |
if (i == max) { | |
return ''; | |
} | |
var usInfo = infos[i].nextElementSibling; | |
var usIdTag = usInfo.querySelector('.tau-entity-icon--userstory'); | |
// empty field | |
if (!usIdTag) { | |
return ''; | |
} | |
var usId = '#' + usIdTag.textContent; | |
var usTitle = usInfo.querySelector('.tau-linkentity__inner').textContent; | |
return formatInfo(usId, usTitle); | |
} | |
setInterval(function() { | |
var btnId = 'ts-copy-title-btn'; | |
if (document.getElementById(btnId)) return; | |
var copyBtn = document.createElement('button'); | |
copyBtn.id = btnId; | |
copyBtn.className = 'tau-btn tau-primary view-header__link'; | |
copyBtn.textContent = 'Copy [#ID] Title'; | |
copyBtn.addEventListener('click', function() { | |
var usInfo = getUSInfo(); | |
var toCopy = formatInfo(usInfo.id, usInfo.title); | |
if (usInfo.type === 'Task') { | |
var taskInfo = getUSInfoIfTask(); | |
toCopy = taskInfo + '\n' + toCopy; | |
} | |
GM_setClipboard(toCopy); | |
}); | |
document.querySelector('.view-header-group').appendChild(copyBtn); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment