Last active
August 29, 2015 14:26
-
-
Save waf/e0d122b3b572f79762f6 to your computer and use it in GitHub Desktop.
Sum Trello Points
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
/* | |
* Reads trello card titles of the format "My Trello card (4)" where the number in parentheses | |
* is some number of sprint points. It sums up the points in list, and adds it to the list header. | |
* | |
* To use it as a bookmarklet on Trello, make a new bookmark, and set the bookmark URL to the | |
* below javascript, prefixed by "javascript:" | |
* Example Bookmark: | |
* Name: Sum Trello Points | |
* URL: javascript:(function() {var pointsIn... | |
*/ | |
(function() { | |
var pointsInTitleRegex = /.*\((\d)\)$/; | |
$("#board .list").each(function(_, list) { | |
var points = sumList(list); | |
$(".list-header-name", list).append(" (" + points + ")"); | |
}); | |
function sumList(list) { | |
return $(".list-card-title", list).toArray() | |
.map(function(elem) { | |
return extractPoints(elem.textContent); | |
}) | |
.reduce(function(accumulate, current) { | |
return accumulate + current; | |
}, 0); | |
} | |
function extractPoints(cardTitle) { | |
var match = cardTitle.match(pointsInTitleRegex); | |
return match && match.length === 2 ? parseInt(match[1], 10) : 0; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment