Created
December 5, 2017 21:52
-
-
Save rdillmanCN/c42fdc3fcd7ec529dbb3fe16e5a0d9e8 to your computer and use it in GitHub Desktop.
Find all colors used on the page and out put to the console.
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
(function() { | |
var h = {}; | |
var e = ["background-color", "color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color"]; | |
var g = { | |
"rgb(0, 0, 0)": 1, | |
"rgba(0, 0, 0, 0)": 1, | |
"rgb(255, 255, 255)": 1 | |
}; | |
[].forEach.call(document.querySelectorAll("*"), function(i) { | |
var j = {}; | |
e.forEach(function(l) { | |
var k = window.getComputedStyle(i, null).getPropertyValue(l); | |
if (k && !g[k]) { | |
if (!h[k]) { | |
h[k] = { | |
count: 0, | |
nodes: [] | |
} | |
} | |
if (!j[k]) { | |
h[k].count++; | |
h[k].nodes.push(i) | |
} | |
j[k] = true | |
} | |
}) | |
}); | |
var b = []; | |
for (var d in h) { | |
b.push({ | |
key: d, | |
value: h[d] | |
}) | |
} | |
b = b.sort(function(j, i) { | |
return i.value.count - j.value.count | |
}); | |
var f = "font-weight:normal;"; | |
var c = "font-weight:bold;"; | |
var a = function(i) { | |
return "background:" + i + ";color:" + i + ";border:1px solid #333;" | |
}; | |
console.group("CSS colors"); | |
b.forEach(function(i) { | |
console.groupCollapsed("%c %c " + i.key + " %c(" + i.value.count + " times)", a(i.key), f, c); | |
i.value.nodes.forEach(function(j) { | |
console.log(j) | |
}); | |
console.groupEnd() | |
}); | |
console.groupEnd("CSS colors") | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment