Created
April 5, 2020 12:41
-
-
Save Foair/586770ba374b12b1c9100f5aa7a80d13 to your computer and use it in GitHub Desktop.
从 https://flatuicolors.com/ 提取颜色代码
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 rgbToHex = function(rgb) { | |
var hex = Number(rgb).toString(16); | |
if (hex.length < 2) { | |
hex = "0" + hex; | |
} | |
return hex; | |
}; | |
var fullColorHex = function(r, g, b) { | |
var red = rgbToHex(r); | |
var green = rgbToHex(g); | |
var blue = rgbToHex(b); | |
return red + green + blue; | |
}; | |
var styleToHex = function($ele) { | |
const name = $ele | |
.querySelector("span") | |
.innerText.toLowerCase() | |
.split(" ") | |
.join("-"); | |
const arr = $ele.style.background.match(/\((.*)\)/)[1].split(", "); | |
return `$color-${name}: #${fullColorHex(...arr)};`; | |
}; | |
let printS = ""; | |
function log(str) { | |
printS += str + "\n"; | |
} | |
log.end = function() { | |
console.log(printS); | |
printS = ""; | |
}; | |
$$(".colors > div").forEach(item => { | |
log(styleToHex(item)); | |
}); | |
log.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment