Skip to content

Instantly share code, notes, and snippets.

@filipecsweb
Last active May 11, 2019 19:54
Show Gist options
  • Save filipecsweb/71245fd0312882c57c90a960c7f68d2a to your computer and use it in GitHub Desktop.
Save filipecsweb/71245fd0312882c57c90a960c7f68d2a to your computer and use it in GitHub Desktop.
Builds a stylesheet content using coolors.co Color Scheme.
(function ($) {
let stylesheet = '',
html = '';
function get_colors(parent) {
let colors = {};
colors.lighter = String($(".color-shade:nth-child(5)", parent).data("color"));
colors.active = String($(".color-shade:nth-child(11)", parent).data("color"));
colors.darker = String($(".color-shade:nth-child(17)", parent).data("color"));
return colors;
}
function get_selector(args) {
html = "\n" +
args.selector +
" {\n" +
"\t" +
args.property + ";" +
"\n" +
"}\n";
return html;
}
$(".color", "#colors").each(function () {
let color_name = $(".color-info .color-info-name", $(this)).text();
let colors = get_colors($(".color-shades-container", $(this)));
stylesheet += "\r/* " + color_name + " */";
$.each(colors, function (i, v) {
let color_value = v.toUpperCase();
let args = {
selector: ".bg-" + color_value,
property: "background-color: #" + color_value
};
stylesheet += get_selector(args);
});
stylesheet += "\r/* " + color_name + " */";
$.each(colors, function (i, v) {
let color_value = v.toUpperCase();
let args = {
selector: ".color-" + color_value,
property: "color: #" + color_value
};
stylesheet += get_selector(args);
});
});
console.clear();
/**
* Start copying.
*/
let textarea = document.createElement('textarea');
textarea.style.width = '0';
textarea.style.height = '0';
textarea.value = stylesheet;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('Copy');
textarea.remove();
console.log('Copied!');
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment