Last active
March 7, 2017 10:47
-
-
Save jikkujose/0d6caf3909b447f3c99e1570f7525c66 to your computer and use it in GitHub Desktop.
Bookmarklet to easy extraction of palettes from Coolors.co
This file contains 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
/* | |
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