Created
July 24, 2014 00:59
-
-
Save shuhei/981d16b3e5d58a8c5f0e to your computer and use it in GitHub Desktop.
Extract color palette of Google's Material Design. Run on http://www.google.com/design/spec/style/color.html
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
// Create an Array from an Array-like Object such as NodeList. | |
function toArray(arrayLike) { | |
return Array.prototype.slice.call(arrayLike); | |
} | |
// Create an Object from an Array of objects. | |
function toObject(objects, keyName, valueName) { | |
return objects.reduce(function(acc, obj) { | |
acc[obj[keyName]] = obj[valueName]; | |
return acc; | |
}, {}); | |
} | |
function pickColor(item) { | |
var shade = item.querySelector('.shade').innerText; | |
var hex = item.querySelector('.hex').innerText; | |
return { shade: shade, hex: hex }; | |
} | |
function pickGroupColors(group) { | |
var colorName = group.querySelector('li.main-color .name').innerText; | |
var name = colorName.toLowerCase().split(' ').join('-'); | |
var items = toArray(group.querySelectorAll('li.color:not(.main-color)')); | |
var colors = toObject(items.map(pickColor), 'shade', 'hex'); | |
return { name: name, colors: colors }; | |
} | |
var groups = toArray(document.querySelectorAll('.color-group')); | |
var colorSet = toObject(groups.map(pickGroupColors), 'name', 'colors'); | |
console.log(JSON.stringify(colorSet)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment