Skip to content

Instantly share code, notes, and snippets.

@p3t3r67x0
Last active February 1, 2019 07:49
Show Gist options
  • Save p3t3r67x0/568d5ae0a9cfccf241c4 to your computer and use it in GitHub Desktop.
Save p3t3r67x0/568d5ae0a9cfccf241c4 to your computer and use it in GitHub Desktop.
var pseudoClassesAndElementsArray = ['', ':hover', ':focus', ':active', ':first-child', ':first-of-type', ':checked', ':disabled', ':empty', ':enabled', ':invalid', ':last-child', ':last-of-type', ':link', ':only-of-type', ':only-child', ':optional', ':out-of-range', ':read-only', ':read-write', ':required', ':root', ':target', ':valid', ':visited', '::after', '::before', '::first-letter', '::first-line', '::selection', '', ];
var colorListArray = [];
function isArray(data) {
var isArrayBoolean = Object.prototype.toString.call(data) == '[object Array]';
return isArrayBoolean;
}
function inArray(needle, haystack) {
var length = haystack.length;
for (var i = 0; i < length; i++) {
if (haystack[i] == needle) {
return true;
}
}
return false;
}
function inStringRegex(stringData) {
var regex = /rgba?\(.*?\)/g;
var outputMatchedArray;
if (!!stringData) {
outputMatchedArray = stringData.match(regex);
if (isArray(outputMatchedArray)) {
outputMatchedArray.forEach(arrayElements);
}
}
}
function arrayElements(element, index, array) {
if (!inArray(element, colorListArray)) {
colorListArray.push(element);
}
}
function callPseudoClassesAndElements(elementValue, index, array) {
var domObject = document.querySelectorAll("*");
//console.log(element);
//runs through all dom elements
[].forEach.call(domObject, function(element) {
var propertyLength = window.getComputedStyle(element, elementValue).length;
for (var i = 0; i < propertyLength; i++) {
var propertyName = window.getComputedStyle(element, elementValue).item(i);
var propertyValue = window.getComputedStyle(element, elementValue).getPropertyValue(propertyName);
//console.log(propertyValue);
if (typeof propertyValue != 'undefined' && !!propertyValue) {
inStringRegex(propertyValue);
}
}
});
}
//init
if (document.querySelectorAll && window.getComputedStyle) {
pseudoClassesAndElementsArray.forEach(callPseudoClassesAndElements);
console.log(colorListArray);
}
else {
console.log("Es trat ein Fehler auf");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment