|
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()) |