Skip to content

Instantly share code, notes, and snippets.

@pravdomil
Created September 8, 2020 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pravdomil/be27dcdb284b5fe25d50919f90420964 to your computer and use it in GitHub Desktop.
Save pravdomil/be27dcdb284b5fe25d50919f90420964 to your computer and use it in GitHub Desktop.
function getCssElmClasses() {
const a = [...document.styleSheets]
.map((b) => [...b.cssRules])
.flat()
.map((b) => b instanceof CSSMediaRule ? [...b.cssRules] : [b])
.flat()
.map((b) => b.selectorText)
.filter((b) => b)
.map((b) => b.split(","))
.flat()
.map((b) => b.trim())
.filter((b) => b.match(/^\./))
.map((b) => b.replace(/^\.([a-zA-Z0-9_-]*).*$/, "$1"))
.map((b) => `${b.replace(/-./g, (c) => c.substr(1).toUpperCase())} = class ${JSON.stringify(b)}`)
return [...new Set(a).keys()].join("\n")
}
document.write(getCssElmClasses().replace(/\n/g, "<br>"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment