Last active
February 1, 2019 07:49
-
-
Save p3t3r67x0/568d5ae0a9cfccf241c4 to your computer and use it in GitHub Desktop.
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 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