Skip to content

Instantly share code, notes, and snippets.

@ViliamKopecky
Created November 2, 2021 10:17
Show Gist options
  • Save ViliamKopecky/f60d57150fd08c4e3ee681c4b7008e7f to your computer and use it in GitHub Desktop.
Save ViliamKopecky/f60d57150fd08c4e3ee681c4b7008e7f to your computer and use it in GitHub Desktop.
Find all used font-families and their font-weights on a page
(() => {
const data = {};
document.querySelectorAll("*").forEach((el) => {
const style = window.getComputedStyle(el);
const font = String(style.fontFamily).split(",").shift().replace(/\"/g, '');
data[font] = data[font] ?? {};
data[font][style.fontWeight] = data[font][style.fontWeight] ?? 0;
data[font][style.fontWeight]++;
});
console.log(JSON.stringify(data, null, 2));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment