Created
March 22, 2024 23:52
-
-
Save Santosl2/a729b2b97c3d7e03d5ae1170398d488a to your computer and use it in GitHub Desktop.
A simple algorithm to catch all figma libraries colors
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
| const exportedColors = [{}]; | |
| const colorsTitle = document.querySelectorAll( | |
| "div.raw_components--modalPanel--NX71G.variable_picker_ui--modalPanel--X0bjl > div > div > div > div" | |
| ); | |
| Array.from(colorsTitle).map((el) => { | |
| const color = el.textContent; | |
| if (!color) return; | |
| const firstLetter = color?.charAt(0); | |
| const firstLetterIsUpperCase = firstLetter === firstLetter.toUpperCase(); | |
| if (firstLetterIsUpperCase) { | |
| exportedColors.push({ | |
| [color.toLowerCase()]: {}, | |
| }); | |
| } else { | |
| const splittedColors = color.split("-"); | |
| const colorName = splittedColors[0].toLowerCase(); | |
| const colorType = splittedColors[1].toLowerCase(); | |
| const hexColor = el.parentElement | |
| ?.querySelector("svg > circle") | |
| ?.getAttribute("fill"); | |
| const hex = exportedColors[colorName]; | |
| if (!hex) { | |
| exportedColors[colorName] = {}; | |
| } | |
| exportedColors[colorName][colorType] = hexColor; | |
| } | |
| }); | |
| copy(exportedColors) | |
| console.log(exportedColors); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment