Last active
July 9, 2016 10:08
-
-
Save Fedott/c00ab7d8e0c0d402616c9c82919c739e to your computer and use it in GitHub Desktop.
Replace estimates numeric to TShirt sizes (actual script http://tm.fedot.name/pivotal-tshirt.user.js)
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 T-Shirt estimates | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Changed estimates to t-shirts | |
// @author Fedot | |
// @match https://www.pivotaltracker.com/n/projects/* | |
// @grant none | |
// @updateUrl http://tm.fedot.name/pivotal-tshirt.user.js | |
// ==/UserScript== | |
function makeTShirtsForDropdownItems(estimateDropDownItems) { | |
for (var i = 0; i < estimateDropDownItems.length; i++) { | |
var originVal = estimateDropDownItems[i].innerHTML; | |
switch (originVal) { | |
case '1 point': | |
estimateDropDownItems[i].innerHTML = 'XS size'; | |
break; | |
case '2 points': | |
estimateDropDownItems[i].innerHTML = 'S size'; | |
break; | |
case '4 points': | |
estimateDropDownItems[i].innerHTML = 'M size'; | |
break; | |
case '8 points': | |
estimateDropDownItems[i].innerHTML = 'L size'; | |
break; | |
case '16 points': | |
estimateDropDownItems[i].innerHTML = 'XL size'; | |
break; | |
} | |
} | |
} | |
var makeTShitForNode = function (node) { | |
var estimates; | |
estimates = node.querySelectorAll('span.estimate > label > div'); | |
makeTShirts(estimates); | |
estimates = node.querySelectorAll('span.meta > span'); | |
makeTShirts(estimates); | |
var estimateDropDownItems = node | |
.querySelectorAll('.story_estimate div.dropdown_menu > ul > li.dropdown_item .dropdown_label, .story_estimate > a.selection > span'); | |
makeTShirtsForDropdownItems(estimateDropDownItems); | |
}; | |
function makeTShirts(estimates) { | |
for (var i = 0; i < estimates.length; i++) { | |
var numericVal = estimates[i].innerHTML; | |
switch (numericVal) { | |
case '1': | |
estimates[i].innerHTML = 'XS'; | |
break; | |
case '2': | |
estimates[i].innerHTML = 'S'; | |
break; | |
case '4': | |
estimates[i].innerHTML = 'M'; | |
break; | |
case '8': | |
estimates[i].innerHTML = 'L'; | |
break; | |
case '16': | |
estimates[i].innerHTML = 'XL'; | |
break; | |
} | |
} | |
} | |
function trackChangeStories(node) { | |
console.log('start track stories'); | |
var observer = new MutationObserver( | |
function (mutations) { | |
mutations.forEach(function (mutation) { | |
if (mutation.addedNodes) { | |
for (var i = 0; i < mutation.addedNodes.length; i++) { | |
var node = mutation.addedNodes[i]; | |
if ( | |
node.nodeName != 'DIV' | |
|| node.classList === undefined | |
|| !node.classList.contains('story') | |
) { | |
continue; | |
} | |
makeTShitForNode(node); | |
return; | |
} | |
} | |
if ( | |
mutation.target.nodeName == 'HEADER' | |
&& mutation.target.classList.contains('preview') | |
) { | |
makeTShitForNode(mutation.target); | |
} | |
if ( | |
mutation.target.firstChild | |
&& mutation.target.firstChild.nodeName == 'DIV' | |
&& mutation.target.firstChild.classList.contains('edit') | |
&& mutation.target.firstChild.classList.contains('details') | |
&& mutation.addedNodes.length | |
) { | |
makeTShitForNode(mutation.target); | |
} | |
if ( | |
mutation.target.nodeName == 'DIV' | |
&& mutation.target.classList.contains('info') | |
) { | |
makeTShitForNode(mutation.target); | |
} | |
}); | |
} | |
); | |
observer.observe(node, { | |
childList: true, | |
subtree: true, | |
attributes: false, | |
characterData: false | |
}); | |
} | |
var waitProjectsDom = function () { | |
var observer = new MutationObserver( | |
function (mutations) { | |
mutations.forEach(function (mutation) { | |
if (!mutation.addedNodes) { | |
return; | |
} | |
for (var i = 0; i < mutation.addedNodes.length; i++) { | |
var node = mutation.addedNodes[i]; | |
if ( | |
node.nodeName != 'DIV' | |
|| node.classList === undefined | |
|| !node.classList.contains('table') | |
) { | |
continue; | |
} | |
makeTShitForNode(node); | |
trackChangeStories(node); | |
observer.disconnect(); | |
return; | |
} | |
}); | |
} | |
); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true, | |
attributes: false, | |
characterData: false | |
}); | |
}; | |
(function() { | |
'use strict'; | |
waitProjectsDom(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment