Skip to content

Instantly share code, notes, and snippets.

@wmathes
Last active February 13, 2020 03:52
Show Gist options
  • Save wmathes/1eb353d97a925353e20ec8324816d905 to your computer and use it in GitHub Desktop.
Save wmathes/1eb353d97a925353e20ec8324816d905 to your computer and use it in GitHub Desktop.
// organization's repository labels (when all labels are expanded)
[...document.getElementsByClassName('js-new-label-name-input')]
.filter((x) => /label-name-\d+/.test(x.id))
.map((x) => x.id.substring(11))
.map((x) => ({
name: document.getElementById(`label-name-${x}`).value,
description: document.getElementById(`label-description-${x}`).value,
color: document.getElementById(`label-color-${x}`).value
}))
// organization's repository labels (when all labels are collapsed)
[...document.getElementsByClassName('js-label-link')]
.map((x) => ({
name: x.firstElementChild.innerText.trim(),
description: x.title,
color: x.style.backgroundColor, // returned as RGB()
}))
.reduce((list, next) => { if (!list.find((x) => x.name == next.name)) { list.push(next); } return list; }, [])
.filter((x) => x.name && x.name != 'Label preview')
// any other page with labels (issue list, issue view, PRs, etc.)
[...document.getElementsByClassName('IssueLabel')]
.map((x) => ({
name: x.innerText.trim(),
description: x.title,
color: x.style.backgroundColor, // returned as RGB()
}))
.reduce((list, next) => { if (!list.find((x) => x.name == next.name)) { list.push(next); } return list; }, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment