Created
September 23, 2015 18:19
-
-
Save jelbourn/9ee0ae5d7a1010b431e8 to your computer and use it in GitHub Desktop.
Scrape Material Design colors from public site
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 us = document.createElement('script'); | |
us.src = 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'; | |
document.body.appendChild(us); | |
setTimeout(() => { | |
window.palettes = {}; | |
_.each(document.querySelectorAll('.color-group:not(:last-child)'), (group) => { | |
var nameElement = group.querySelector('.name'); | |
if (!nameElement) return; | |
var paletteName = nameElement.textContent.trim(); | |
palettes[paletteName] = _.map(group.querySelectorAll('.color:not(.main-color)'), (color) => { | |
return { | |
hue: color.querySelector('.shade').textContent.trim(), | |
hex: color.querySelector('.hex').textContent.trim(), | |
contrast: window.getComputedStyle(color).color | |
}; | |
}); | |
}); | |
console.log('Done: colors stored to window.palettes'); | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment