Created
November 2, 2021 10:17
-
-
Save ViliamKopecky/f60d57150fd08c4e3ee681c4b7008e7f to your computer and use it in GitHub Desktop.
Find all used font-families and their font-weights on a page
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 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