Last active
December 1, 2021 10:52
-
-
Save MrSquaare/c34dff2a56f8919c480c6a4103c5952d to your computer and use it in GitHub Desktop.
Export all labels of a GitHub repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let labels = [] | |
let selector = `a.js-label-link` | |
function getRGBFromElement(element) { | |
const red = element.attributeStyleMap.get('--label-r')[0] | |
const green = element.attributeStyleMap.get('--label-g')[0] | |
const blue = element.attributeStyleMap.get('--label-b')[0] | |
return `rgb(${red}, ${blue}, ${green})` | |
} | |
function hexFromRGB(rgb) { | |
let hex = parseInt(rgb).toString(16) | |
if (hex.length < 2) | |
hex = "0" + hex | |
return hex | |
} | |
function fullHexFromRGB(rgb) { | |
let colors = rgb.substring( | |
rgb.indexOf('(') + 1, | |
rgb.indexOf(')') | |
).split(',') | |
let hexColors = colors.map(color => hexFromRGB(color)) | |
return hexColors.join('') | |
} | |
document.querySelectorAll(selector).forEach(element => { | |
labels.push({ | |
"name": element.firstElementChild.textContent, | |
"description": element.title, | |
"color": fullHexFromRGB(getRGBFromElement(element)), | |
}) | |
}) | |
console.log(JSON.stringify(labels)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment