Skip to content

Instantly share code, notes, and snippets.

@waako
Last active April 6, 2020 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waako/9d7faafe9d6e9cedc60e796c86a03e97 to your computer and use it in GitHub Desktop.
Save waako/9d7faafe9d6e9cedc60e796c86a03e97 to your computer and use it in GitHub Desktop.
Copy trello card title, url, attachments & checklists for pasting into CSV

Easy(ish) way to copy Trello card elements into CSV format

Following content is extracted into columns currently:

  • Title
  • URL
  • Trello Attachments (other cards linked from this card)
  • Checklists (1 column per checklist, currently up to 7 but just add more to csv file headers)

Instructions

  1. Download/Create trello-cards.csv with column headers (see example file)
  2. Open/Edit CSV file in code/text editor
  3. Copy contents of copy-card.js into browser devtools console
  4. Open trello card and run console script (use up arrow to repeat script)
  5. Paste content on new line in CSV file
  6. Repeat steps 4 & 5 as necessary for each Trello card
  7. Save CSV file and import to your favourite spreadsheet tool

Inspired by original script: https://gist.github.com/waako/56557fdbcab198db3539c0188e5d1021

function cardInfo() {
// Get Card Title and URL
var title = $(".card-detail-title-assist").text()
var url = window.location.href
// Get Trello card attachments
var attachments = $(".trello-attachment-canonical-card").map(function () {
var $attachment = $(this).find("a")
var attachmentURL = $attachment.attr("href")
// The target trello card Title is in the second div inside the anchor
var attachmentTitle = $attachment.find("div:nth-child(2)").text()
return `- ${attachmentTitle}: https://trello.com/${attachmentURL}`
}).get().join("\n")
// Get all Checklists
var checklists = $(".checklist").map(function () {
var checklistTitle = $(this).find(".checklist-title .current").html()
// For each checklist item we want to plain text but still preserve some html aspects.
var checklistItems = $(this).find(".checklist-item:not(.checklist-item-checked)").map(function () {
var e = $(this),
$item = e.find(".checklist-item-details-text").clone()
// Preserve urls from linked text
$item.children("a").replaceWith(function () {
var href = $(this).attr("href")
var linkTitle = $(this).text()
return ` ${linkTitle}: ${href}`
})
// Wrap italic text with markdown _ so formatting not lost
$item.children("em").replaceWith(function () {
var strongText = $(this).html()
return `_${strongText}_`
})
// Wrap bold text with markdown ** so formatting not lost
$item.children("strong").replaceWith(function () {
var strongText = $(this).text()
return `**${strongText}**`
})
var itemText = $item.text()
// itemText.replace('"', "'")
item = "- [ ] " + itemText.replace(/\"/g, "\"\"");
if (e.hasClass("checklist-item-state-complete")) {
item = "- [X] " + itemText.replace(/\"/g, "\"\""); + " (DONE)"
}
return item
}).get().join("\n")
var checklist = `"${checklistTitle}
${checklistItems}"`
return checklist
}).get().join(",")
var results = `"${title}",${url},"${attachments}",${checklists}
`
return results
}
// Copy function contents to clipboard (only works in console/devtools
copy(cardInfo())
Card Title URL Attachments Checklist 1 Checklist 2 Checklist 3 Checklist 4 Checklist 5 Checklist 6 Checklist 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment