Created
August 13, 2020 20:51
-
-
Save rbrahul/72fcc2948859c8e2680aa3ed47b3840b to your computer and use it in GitHub Desktop.
JS Bin Color Palater // source https://jsbin.com/dixubur
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Color Palater"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var getColorProperties = (styleObject) => { | |
const properties = ['background-color','color','border-color', 'border-bottom-color','border-right-color','border-left-color','border-top-color']; | |
return properties.reduce((colors, current) => { | |
const color = styleObject[current]; | |
if(color && !colors.includes(color)) { | |
return [...colors, color]; | |
} | |
return colors; | |
}, []); | |
} | |
var createColorPalate = (colorCodes) => { | |
const palates = colorCodes.reduce((colors, curColor) => { | |
return colors+= `<div class="rb-color-palater-item" style="background-color: ${curColor};padding: 10px; font-size:16px;color: #fff; text-shadow: 1px 1px 1px black;border-bottom:1px solid #ccc;">${curColor}</div>`; | |
}, ''); | |
const palaterContainer = document.createElement('div'); | |
palaterContainer.classList.add('rb-color-palate'); | |
palaterContainer.style.cssText='display:flex;flex-direction:column;width:260px;position:absolute;top:0;right:0;z-index:1000000001;border:1px solid #ddd;'; | |
palaterContainer.innerHTML = palates; | |
document.body.appendChild(palaterContainer); | |
} | |
var colorCodes = []; | |
Array.from(document.querySelectorAll('*')).slice(0).forEach(node => { | |
const styles = getComputedStyle(node); | |
const elementColorCodes = getColorProperties(styles); | |
elementColorCodes.forEach(color => { | |
if(!colorCodes.includes(color)) { | |
colorCodes.push(color); | |
} | |
}); | |
}); | |
createColorPalate(colorCodes); | |
console.log(colorCodes); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
var getColorProperties = (styleObject) => { | |
const properties = ['background-color','color','border-color', 'border-bottom-color','border-right-color','border-left-color','border-top-color']; | |
return properties.reduce((colors, current) => { | |
const color = styleObject[current]; | |
if(color && !colors.includes(color)) { | |
return [...colors, color]; | |
} | |
return colors; | |
}, []); | |
} | |
var createColorPalate = (colorCodes) => { | |
const palates = colorCodes.reduce((colors, curColor) => { | |
return colors+= `<div class="rb-color-palater-item" style="background-color: ${curColor};padding: 10px; font-size:16px;color: #fff; text-shadow: 1px 1px 1px black;border-bottom:1px solid #ccc;">${curColor}</div>`; | |
}, ''); | |
const palaterContainer = document.createElement('div'); | |
palaterContainer.classList.add('rb-color-palate'); | |
palaterContainer.style.cssText='display:flex;flex-direction:column;width:260px;position:absolute;top:0;right:0;z-index:1000000001;border:1px solid #ddd;'; | |
palaterContainer.innerHTML = palates; | |
document.body.appendChild(palaterContainer); | |
} | |
var colorCodes = []; | |
Array.from(document.querySelectorAll('*')).slice(0).forEach(node => { | |
const styles = getComputedStyle(node); | |
const elementColorCodes = getColorProperties(styles); | |
elementColorCodes.forEach(color => { | |
if(!colorCodes.includes(color)) { | |
colorCodes.push(color); | |
} | |
}); | |
}); | |
createColorPalate(colorCodes); | |
console.log(colorCodes); | |
</script></body> | |
</html> |
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 getColorProperties = (styleObject) => { | |
const properties = ['background-color','color','border-color', 'border-bottom-color','border-right-color','border-left-color','border-top-color']; | |
return properties.reduce((colors, current) => { | |
const color = styleObject[current]; | |
if(color && !colors.includes(color)) { | |
return [...colors, color]; | |
} | |
return colors; | |
}, []); | |
} | |
var createColorPalate = (colorCodes) => { | |
const palates = colorCodes.reduce((colors, curColor) => { | |
return colors+= `<div class="rb-color-palater-item" style="background-color: ${curColor};padding: 10px; font-size:16px;color: #fff; text-shadow: 1px 1px 1px black;border-bottom:1px solid #ccc;">${curColor}</div>`; | |
}, ''); | |
const palaterContainer = document.createElement('div'); | |
palaterContainer.classList.add('rb-color-palate'); | |
palaterContainer.style.cssText='display:flex;flex-direction:column;width:260px;position:absolute;top:0;right:0;z-index:1000000001;border:1px solid #ddd;'; | |
palaterContainer.innerHTML = palates; | |
document.body.appendChild(palaterContainer); | |
} | |
var colorCodes = []; | |
Array.from(document.querySelectorAll('*')).slice(0).forEach(node => { | |
const styles = getComputedStyle(node); | |
const elementColorCodes = getColorProperties(styles); | |
elementColorCodes.forEach(color => { | |
if(!colorCodes.includes(color)) { | |
colorCodes.push(color); | |
} | |
}); | |
}); | |
createColorPalate(colorCodes); | |
console.log(colorCodes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment