Created
November 28, 2019 14:52
-
-
Save fgm/d9f1806a2ada41501160f995dc8367bb to your computer and use it in GitHub Desktop.
Build a list of the font families and weights on a web page, with the number of elements using them
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
const nodes = document.body.getElementsByTagName('*'); | |
const styles = {}; | |
for (const node of nodes) { | |
const s = getComputedStyle(node); | |
if (!styles[s.fontFamily]) { | |
styles[s.fontFamily] = {}; | |
} | |
if (!styles[s.fontFamily][s.fontWeight]) { | |
styles[s.fontFamily][s.fontWeight] = 1; | |
} | |
styles[s.fontFamily][s.fontWeight]++ | |
} | |
let count = 0; | |
for (const fam in styles) { | |
for (const w in styles[fam]) { | |
count++; | |
console.log(count, fam, w, styles[fam][w]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment