Created
December 3, 2021 07:55
-
-
Save jasonreiche/a299620afdb1758b669d8fbda6d64a95 to your computer and use it in GitHub Desktop.
Get unique styles assigned to any element matching a query selector
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
[...document.querySelectorAll("#targets")].forEach(targetEl => { | |
var targetStyles = window.getComputedStyle(targetEl); | |
var comparisonEl = document.createElement(targetEl.tagName); | |
var comparisonStyles = window.getComputedStyle(comparisonEl); | |
var cleanStyles = {}; | |
Object.entries(targetStyles).forEach(style=>{ | |
if(comparisonStyles[style[0]] !== style[1]){ | |
cleanStyles[style[0]] = style[1]; | |
} | |
}); | |
console.log('CLEAN SET (' + Object.keys(cleanStyles).length + ' rules):',cleanStyles); | |
comparisonEl.remove() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment