Skip to content

Instantly share code, notes, and snippets.

@ThatGuySam
Created April 5, 2021 20:01
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 ThatGuySam/87dd4743ea92927e1cdb998865d1cdf9 to your computer and use it in GitHub Desktop.
Save ThatGuySam/87dd4743ea92927e1cdb998865d1cdf9 to your computer and use it in GitHub Desktop.
Find all unique font weight and style combinations in Javascript
const fontVariationsUsed = new Set()
Array.from(document.querySelectorAll('*')).forEach( element => {
const computedStyle = window.getComputedStyle( element )
const hasFontFamily = computedStyle.fontFamily.includes('Montserrat')
if ( hasFontFamily ) {
// Add variation to list
fontVariationsUsed.add(`${computedStyle.fontWeight} ${computedStyle.fontStyle}`)
}
})
console.log('fontVariationsUsed', fontVariationsUsed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment