Created
August 24, 2015 11:14
-
-
Save filipenevola/361ad413e112cb8c6f02 to your computer and use it in GitHub Desktop.
This file contains 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 TS - Copy TP US title/id | |
// @namespace br.com.tecsinapse | |
// @include https://tecsinapse.tpondemand.com/* | |
// @version 1.0.5 | |
// @grant GM_setClipboard | |
// ==/UserScript== | |
function formatInfo(usId, usTitle) { | |
return '[' + usId + '] ' + usTitle; | |
} | |
function getUSInfo() { | |
var titleTable = document.querySelector('.ui-title.ui-title_type_main'); | |
var usId = titleTable.querySelector('.entity-id').textContent; | |
var usTitle = titleTable.querySelector('.ui-title__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'; | |
copyBtn.textContent = 'Copy US 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('.header-links').appendChild(copyBtn); | |
var btnId = 'ts-copy-id-btn'; | |
if (document.getElementById(btnId)) return; | |
var copyBtn = document.createElement('button'); | |
copyBtn.id = btnId; | |
copyBtn.className = 'tau-btn tau-primary'; | |
copyBtn.textContent = 'Copy id:title'; | |
copyBtn.addEventListener('click', function() { | |
var usInfo = getUSInfo(); | |
GM_setClipboard('id:' + usInfo.id.substring(1)); | |
}); | |
document.querySelector('.header-links').appendChild(copyBtn); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment