Created
December 9, 2020 08:43
-
-
Save chrismatix/28d3247fd84c8b2fe348dca8d214a1a5 to your computer and use it in GitHub Desktop.
Parse Github labels to JSON file
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
var labels = []; | |
var hexDigits = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]; | |
//Function to convert rgb color to hex format | |
function rgb2hex(rgb) { | |
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); | |
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); | |
} | |
function hex(x) { | |
return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; | |
} | |
[].slice.call(document.querySelectorAll(".js-label-link")) | |
.forEach(function(element) { | |
labels.push({ | |
name: element.textContent.trim(), | |
description: element.getAttribute("title"), | |
// using style.backgroundColor might returns "rgb(...)" | |
color: rgb2hex(window.getComputedStyle(element) | |
.backgroundColor) | |
}) | |
}) | |
console.log(JSON.stringify(labels, null, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment