Skip to content

Instantly share code, notes, and snippets.

@Foair
Created April 5, 2020 12:41
Show Gist options
  • Save Foair/586770ba374b12b1c9100f5aa7a80d13 to your computer and use it in GitHub Desktop.
Save Foair/586770ba374b12b1c9100f5aa7a80d13 to your computer and use it in GitHub Desktop.
https://flatuicolors.com/ 提取颜色代码
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