Skip to content

Instantly share code, notes, and snippets.

@pastukh-dm
Last active December 17, 2020 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pastukh-dm/a06625c622b607ea34caf2132f7275b0 to your computer and use it in GitHub Desktop.
Save pastukh-dm/a06625c622b607ea34caf2132f7275b0 to your computer and use it in GitHub Desktop.
Export GitHub labels
// Export GitHub labels
function componentFromStr(numStr, percent) {
var num = Math.max(0, parseInt(numStr, 10));
return percent ?
Math.floor(255 * Math.min(100, num) / 100) : Math.min(255, num);
}
function rgbToHex(rgb) {
var rgbRegex = /^rgb\(\s*(-?\d+)(%?)\s*,\s*(-?\d+)(%?)\s*,\s*(-?\d+)(%?)\s*\)$/;
var result, r, g, b, hex = "";
if ( (result = rgbRegex.exec(rgb)) ) {
r = componentFromStr(result[1], result[2]);
g = componentFromStr(result[3], result[4]);
b = componentFromStr(result[5], result[6]);
hex = "" + (0x1000000 + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
return hex;
}
var labels = [];
[].slice.call(document.querySelectorAll(".js-label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
description: element.closest('.js-labels-list-item')
.querySelector('.js-hide-on-label-edit')
.textContent.trim(),
color: rgbToHex(getComputedStyle(element).backgroundColor)
})
})
copy(JSON.stringify(labels, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment