Skip to content

Instantly share code, notes, and snippets.

@jikkujose
Last active March 7, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jikkujose/0d6caf3909b447f3c99e1570f7525c66 to your computer and use it in GitHub Desktop.
Save jikkujose/0d6caf3909b447f3c99e1570f7525c66 to your computer and use it in GitHub Desktop.
Bookmarklet to easy extraction of palettes from Coolors.co
/*
For
* https://coolors.co
Using
* https://babeljs.io/repl/
* https://chriszarate.github.io/bookmarkleter/
*/
(function() {
function extractColors() {
let inputElements = $('.hex input').toArray()
let colors = inputElements.map(i => i.value)
return colors
}
function theme(colors) {
let key_values = colors.map((color, i) => ` c${i + 1}: '${color}',`).join("\n")
return `export const theme = {
${key_values}
}`
}
function download(filename, text) {
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function tweakMenu() {
let exportButtonLabel = $('#export-scss span')
exportButtonLabel.html('JS')
let exportButton = $('a#export-scss')
exportButton.unbind('click')
exportButton.bind('click', function() {
download('coolors.js', theme(extractColors()))
})
}
tweakMenu()
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment