Skip to content

Instantly share code, notes, and snippets.

@SamDudley
Last active July 23, 2019 02:19
Show Gist options
  • Save SamDudley/dc53d0984e478c4247b00f199f428191 to your computer and use it in GitHub Desktop.
Save SamDudley/dc53d0984e478c4247b00f199f428191 to your computer and use it in GitHub Desktop.
Alerts a markdown like text version of trello board's lists and cards.
// Helper function to convert node lists returned by querySelectorAll to an array
// so that we can used methods like map and filter.
function toArray(nodeList) {
let array = []
nodeList.forEach(node => array.push(node))
return array
}
// Returns a text (like markdown) representation of a trello board.
function trelloBoardAsText() {
let title = document.querySelector('.board-header-btn-text').innerText
let listText = toArray(document.querySelectorAll('.list')).map(listAsText).join('\n\n')
return `Board: ${title}\n\n${listText}`
}
// This is how to represent a list as text.
function listAsText(list) {
let header = list.querySelector('.list-header-name').value
let cardText = toArray(list.querySelectorAll('.list-card-details'))
.map(card => `- ${cardAsText(card)}`)
.join('\n')
return `${header}\n${'='.repeat(header.length)}\n${cardText}`
}
// And this is how to represent a card as text.
function cardAsText(card) {
return card.querySelector('.list-card-title').innerText
}
// Alert gives us an easy way to copy and paste this text out.
alert(trelloBoardAsText())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment