Skip to content

Instantly share code, notes, and snippets.

@kenchris
Created November 22, 2016 15:24
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 kenchris/ef26b8223654e181ef9e403e3b21f7e1 to your computer and use it in GitHub Desktop.
Save kenchris/ef26b8223654e181ef9e403e3b21f7e1 to your computer and use it in GitHub Desktop.
function parseColor(colorStr) {
if (!this.div) {
this.div = document.createElement('div');
this.div.style.hidden = true;
document.body.appendChild(this.div)
}
this.div.style.color = colorStr;
if (this.div.style.color === "")
this.div.style.color = `#${colorStr}`;
let style = window.getComputedStyle(this.div);
let colors = style.color.match(/\d+/g).map(a => parseInt(a, 10));
return new Uint8Array(colors);
}
function withdelay(values, delay) {
return {
[Symbol.iterator]: function* () {
for (let i of values) {
yield new Promise(resolve => {
setTimeout(_ => resolve(i), delay);
});
}
}
};
}
async function run() {
for (let color of withdelay(["red", "purple", "blue"], 500)) {
console.log(parseColor(await color));
}
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment