Skip to content

Instantly share code, notes, and snippets.

@bmccormack
Last active December 13, 2016 00:54
Show Gist options
  • Save bmccormack/87dd112179db6c9eb764 to your computer and use it in GitHub Desktop.
Save bmccormack/87dd112179db6c9eb764 to your computer and use it in GitHub Desktop.
Trello List Math

##Demo

img

##Installation

Ideally, I'd have a bookmarklet right here that you could just drag to your bookmark window, but I don't have that. You have to make your own. But it's pretty easy.

  1. Go to http://chriszarate.github.io/bookmarkleter/
  2. Check the first two options, "URL-encode..." and "Wrap...". You can leave the others unchecked.
  3. Copy the code from source.js below.
  4. Paste the code in the "JavaScipt" box at bookmarkleter web page.
  5. Where it says "Drag this link to your bookmarks bar", drag "My Bookmarklet" do your bookmarks bar.
  6. Optionally, change the name of the bookmarklet in your browser to "Trello List Math."

##Use

The way it recognizes numbers is kind of dumb. It's only looking for integers at the beginning of the card name, optionally with a $. You have to manually click the bookmarklet to refresh.

var lists = $('.js-list');
lists.each(function(index){
var listValue = 0;
cards = $(this).find('.list-card:not(.hide) .js-card-name');
cards.each(function(index){
var text = '';
$(this).contents().each(function(){
if(this.nodeType === 3){
text += this.wholeText;
var re = /^\$?(\d+)/;
if (re.test(text)){
var value = parseInt(re.exec(text)[1]);
listValue += value;
}
}
});
});
var listHeader = $(this).find('.js-list-header')
if ($(listHeader).html() !== undefined){
var listHeaderText = $(listHeader).html().split("<br>")[0]
$(listHeader).html(listHeaderText + "<br>$" + listValue);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment