Skip to content

Instantly share code, notes, and snippets.

@fgm
Created November 28, 2019 14:52
Show Gist options
  • Save fgm/d9f1806a2ada41501160f995dc8367bb to your computer and use it in GitHub Desktop.
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
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