Last active
August 29, 2015 14:02
-
-
Save masaakif/18a5bb2baa00c9c38a8b to your computer and use it in GitHub Desktop.
Add Arrow, Jira description, Open in new page
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 Jira Tweaks | |
// @namespace https://gist.github.com/masaakif/18a5bb2baa00c9c38a8b | |
// @description Jira Tweaks (includes Add Arrow and Open in New Page) | |
// @include http://sydlinux3/* | |
// @include http://jira/* | |
// @include http://sydln203/* | |
// ==/UserScript== | |
// | |
if (0 < location.href.indexOf('IssueNavigator.jspa')) addOpenInNewPage(); | |
if (0 < location.href.indexOf('browse/')) { | |
addArrows(); | |
addJIRAID(); | |
addJIRALinkArea(); | |
} | |
if (0 < location.href.indexOf('BrowseProject.jspa')) { | |
cleanUpRoadMaps(); | |
} | |
function addJIRALinkArea() { | |
var txt = document.createElement("textarea"); | |
txt.cols = '60'; | |
txt.rows = '1'; | |
txt.innerHTML = getJiraNo(document) + '\t' + getJiraSubject(document); | |
txt.innerHTML = txt.innerHTML + '\n[' + getJiraNoOnly(document) + '] - ' + getJiraSubject(document); | |
var body = document.getElementsByTagName('body')[0]; | |
body.insertBefore(txt, body.firstChild); | |
} | |
function getJiraNo (doc) { | |
var title = doc.getElementsByTagName('title')[0]; | |
return title.innerHTML.replace(/\[#([A-Z]*-[0-9]*)\].*/, '=hyperlink("http://jira/browse/$1","$1")'); | |
} | |
function getJiraNoOnly (doc) { | |
var title = doc.getElementsByTagName('title')[0]; | |
return title.innerHTML.replace(/\[#([A-Z]*-[0-9]*)\].*/, '$1'); | |
} | |
function getJiraSubject (doc) { | |
var title = doc.getElementsByTagName('title')[0]; | |
return title.innerHTML.replace(/.*\d+]/, '').replace(/ - Metabit/, ''); | |
} | |
function addJIRAID() { | |
var lines = document.evaluate("//table[@id='issuetable']/tbody/tr", | |
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
if (lines) { | |
for (var i = 0; i < lines.snapshotLength; i = i + 1) { | |
var tr = lines.snapshotItem(i); | |
var tds = lines.snapshotItem(i).children; | |
for (var j = tds.length; j > 0 ; j = j - 1) { | |
var td = tds[j-1]; | |
if (td.getAttribute('class') == 'nav stsummary') { | |
var ln = td.getElementsByTagName('a')[0]; | |
var jiraNo = ln.getAttribute('href').replace(/\/browse\/(.*)/, '$1'); | |
ln.innerHTML = jiraNo + ' : ' + ln.innerHTML; | |
} | |
else { | |
tr.removeChild(td); | |
} | |
} | |
} | |
} | |
lines = false; | |
lines = document.evaluate("//table[@id='summary_table']/tbody/tr", | |
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
if (lines) { | |
for (var i = 0; i < lines.snapshotLength; i = i + 1) { | |
var tr = lines.snapshotItem(i); | |
var tds = lines.snapshotItem(i).children; | |
var jiraNo = ''; | |
for (var j = 0 ; j < tds.length; j = j + 1) { | |
var td = tds[j]; | |
if (j == 2) { | |
td.setAttribute('mymark', 'should-delete'); | |
if (td.getElementsByTagName('a').length > 0) { | |
jiraNo = td.getElementsByTagName('a')[0].getAttribute('href').replace(/\/browse\/(.*)/, '$1'); | |
} | |
} | |
else if (j == 4) { | |
var parentJiraNo = hideParentTask(td); | |
var ln = td.getElementsByTagName('a')[(parentJiraNo == '') ? 0 : 1]; | |
ln.innerHTML = jiraNo + ' - ' + parentJiraNo + ' ' + ln.innerHTML; | |
} | |
else { | |
td.setAttribute('mymark', 'should-delete'); | |
} | |
} | |
for (j = tds.length; j > 0; j = j - 1) { | |
var td = tds[j-1]; | |
if (td.getAttribute('mymark') == 'should-delete') { | |
tr.removeChild(td); | |
} | |
} | |
} | |
} | |
} | |
function hideParentTask(td) | |
{ | |
var lns = td.getElementsByTagName('a'); | |
var parentJiraNo = ''; | |
if (lns.length > 1) { | |
lns[0].setAttribute('style', 'visibility:hidden;display:none;'); | |
parentJiraNo = '(' + lns[0].getAttribute('href').replace(/\/browse\/(.*)/, '$1') + ') '; | |
td.getElementsByTagName('br')[0].setAttribute('style', 'visibility:hidden;display:none;'); | |
var img = td.getElementsByTagName('img')[0].setAttribute('style', 'visibility:hidden;display:none;'); | |
} | |
return parentJiraNo; | |
} | |
function cleanUpRoadMaps() { | |
var tables = document.evaluate('//table[@id="roadmap_table"]/tbody/tr[@bgcolor="white"]', | |
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
var i = 0; | |
if (tables.snapshotLength == 0) { | |
return; | |
} | |
while (tables.snapshotItem(i)) { | |
var tr = tables.snapshotItem(i); | |
tds = tr.getElementsByTagName('td'); | |
var j = 0; | |
var jiraID = ''; | |
var sStatus = ''; | |
var sName = ''; | |
while (tds[j]) { | |
switch (j) { | |
case 2: | |
jiraID = tds[j].textContent; | |
tds[j].setAttribute('mymark', 'should-delete'); | |
break; | |
case 3: | |
sStatus = tds[j].textContent; | |
tds[j].setAttribute('mymark', 'should-delete'); | |
break; | |
case 4: | |
var res = hideParentTask(tds[j]); | |
var iNo = (res == '') ? 0 : 1; | |
var a = tds[j].getElementsByTagName('a')[iNo]; | |
a.innerHTML = jiraID + ' - ' + res + a.innerHTML; | |
break; | |
case 5: | |
tds[j].removeChild(tds[j].firstChild); | |
tds[j].textContent = sStatus; | |
break; | |
default: | |
tds[j].setAttribute('mymark', 'should-delete'); | |
} | |
j = j + 1; | |
} | |
for (j = tds.length; j > 0; j = j - 1) { | |
var td = tds[j-1]; | |
if (td.getAttribute('mymark') == 'should-delete') { | |
tr.removeChild(td); | |
} | |
} | |
i = i + 1; | |
} | |
} | |
function addArrows() { | |
var itemLink = document.evaluate("//table[@id='issuedetails']/tbody/tr/td[2]//a", | |
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
if (itemLink) { | |
parentB = itemLink.parentNode | |
itemID = itemLink.innerHTML; | |
[itemType, itemNo] = itemID.split("-"); | |
prevItemNo = itemNo - 1; | |
nextItemNo = itemNo - 0 + 1; | |
prevItemID = itemType + "-" + prevItemNo; | |
nextItemID = itemType + "-" + nextItemNo; | |
var pf = document.createElement("a"); | |
pf.setAttribute("href", prevItemID); | |
pf.innerHTML = "  <<  "; | |
parentB.insertBefore(pf,itemLink); | |
var nf = document.createElement("a"); | |
nf.setAttribute("href", nextItemID); | |
nf.innerHTML = "  >>  "; | |
parentB.appendChild(nf); | |
} | |
} | |
function addBlankInLink() { | |
var links = document.evaluate("//table[@id='issuetable']//a", document, | |
null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var i = 0; i < links.snapshotLength ; i = i + 1) { | |
var ln = links.snapshotItem(i); | |
ln.setAttribute('target', '_blank'); | |
} | |
} | |
function selectProjects() { | |
} | |
function debug() { | |
if ( typeof DEBUG != 'undefined' && DEBUG ) { | |
console.log.apply(this, arguments); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment