Last active
December 17, 2020 16:24
-
-
Save pastukh-dm/a06625c622b607ea34caf2132f7275b0 to your computer and use it in GitHub Desktop.
Export GitHub labels
This file contains hidden or 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
// 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