Created
December 22, 2022 11:49
-
-
Save najmam/d208f2e96345307a73144206155248f6 to your computer and use it in GitHub Desktop.
Lists all CSS classes referred to in a document. Run this in a web browser 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
(() => { // list all css classes referred to in the document | |
const classes = new Set(); | |
function findClasses(el) { | |
if(el.hasAttribute('class')) { | |
const cls = el.getAttribute('class').split(' '); | |
for(let cl of cls) { | |
classes.add(cl); | |
} | |
} | |
for(let child of el.children) { | |
findClasses(child); | |
} | |
} | |
findClasses(document.querySelector('body')); | |
const sorted = Array.from(classes.values()); | |
sorted.sort(); | |
console.log(sorted.join("\n")); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment