Created
December 23, 2018 20:05
-
-
Save rickcnagy/d96fa7d2a6b16df6236268a29a6499c1 to your computer and use it in GitHub Desktop.
Logs all the unused style rules in loaded stylesheets.
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 logUnusedStyleRules() { | |
const unusedRules = []; | |
[...document.styleSheets].forEach((sheet) => { | |
[...sheet.rules].forEach((rule) => { | |
if (!document.querySelector(rule.selectorText)) { | |
unusedRules.push(rule); | |
} | |
}); | |
}); | |
console.log(unusedRules); | |
} | |
logUnusedStyleRules(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment