Skip to content

Instantly share code, notes, and snippets.

@waako
Forked from niallsmart/copy-checklist.js
Last active April 6, 2020 14:14
Show Gist options
  • Save waako/56557fdbcab198db3539c0188e5d1021 to your computer and use it in GitHub Desktop.
Save waako/56557fdbcab198db3539c0188e5d1021 to your computer and use it in GitHub Desktop.
Copy Card title, url, attachments and checklists to clipboard

Copy Trello card elements to clipboard in Markdown format

Instructions

  1. Open trello card in browser
  2. Open browser devtools to console tab
  3. Paste copy-card-info.js contents into console
  4. Run script
  5. Card information written to clipboard

Features

Extracts and formats following elements:

  • Card Title (set as Heading 1)
  • Card URL
  • Trello card attachments (list with card title and URL)
  • Checklists (checklist title is Heading 3 and items are checklist items, completed items are checked)
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}**`
})
item = "- [ ] " + $item.text()
if (e.hasClass("checklist-item-state-complete")) {
item = "- [X] " + $item.text() + " (DONE)"
}
return item
}).get().join("\n")
var checklist = `
### ${checklistTitle}
${checklistItems}
`
return checklist
}).get().join("\n")
var results = `
# ${title}
URL: ${url}
## Attachments:
${attachments}
## Checklists:
${checklists}`
return results
}
// Copy function contents to clipboard
copy(cardInfo())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment