my idea is quite simple, but I hope there is already something around that solves it more efficiently. So hopefuly somebody can point me in the right direction...
The Problem:
Quick Hex-Code based verification of Website-Colors.
You have your page; you have a design from your creative guy; now you want to check wheather the colors match without inspecting each element via firebug and manually comparing it.
The Idea:
Instead you use a Browser-PlugIn or some SASS/JS/CSS/PHP Code/Library to display little hexcode-color-indicators for each element.
The important part is to see the page as it is, but also be able to see the colorvalues of the elements too, so you can easily verify them.
The Question:
Is there some tool or library that would help with this task already around?
My approach ideas:
- using selenium
- hacking some JS code to add a string to each element with a background oder color css style
Both would kinda work, but my feeling is that there might be something better already around ...
My Solution:
Well, took a while, but got it working using JS and found some helpful Tools as well:
- advocode.com
- zeplin.io
- colorZilla
- colorPeek
pixelZoomer
$('.debugColorHexCode').detach(); $.each($('[class*=text]'), function () { $(this).text(''); $(this).css('color', '#FFF'); }); var possibilities = ['[style*="background-color:"]'], searchFor = /\bbackground-color:/, cssProp = 'background-color', styles = document.styleSheets, i, j, l, rules, rule, elem, res = []; for (i = 0; i < styles.length; i++) { rules = styles[i].cssRules; l = rules.length; for (j = 0; j < l; j++) { rule = rules[j]; if (searchFor.test(rule.cssText)) { possibilities.push(rule.selectorText); } } } possibilities = possibilities.join(','); possibilities = document.querySelectorAll(possibilities); l = possibilities.length; for (i = 0; i < l; i++) { elem = possibilities[i]; res = (window.getComputedStyle(elem, null).getPropertyValue(cssProp) ); $(possibilities[i]).prepend('<span class="debugColorHexCode">' + rgb2hex(res) + '</span>'); } function rgb2hex (rgb) { rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); if (rgb) { function hex (x) { return ("0" + parseInt(x).toString(16)).slice(-2); } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } return ''; }
Thank You @Rob W and @rsk82, https://stackoverflow.com/a/8769287/1370465
Thank You @Erick Petrucelli, https://stackoverflow.com/a/3627747/1370465
hope this solution helps somebody else too ...