Skip to content

Instantly share code, notes, and snippets.

@johnmurch
Last active September 19, 2022 15:11
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 johnmurch/9f7f7f3563adb44cbe7da52f51577e23 to your computer and use it in GitHub Desktop.
Save johnmurch/9f7f7f3563adb44cbe7da52f51577e23 to your computer and use it in GitHub Desktop.
Get Fonts from Website
// via https://stackoverflow.com/a/39900099
function listFonts () {
let fonts = []
for (let node of document.querySelectorAll('*')) {
if (!node.style) continue
for (let pseudo of ['', ':before', ':after']) {
let fontFamily = getComputedStyle(node, pseudo).fontFamily
fonts = fonts.concat(fontFamily.split(/\n*,\n*/g))
}
}
return [...new Set(fonts)]
.map(font => font.replace(/^\s*['"]([^'"]*)['"]\s*$/, '$1').trim())
}
listFonts()
//amazon.com
// ['Times', 'Amazon Ember', 'Arial', 'sans-serif', 'Arial', 'Helvetica', 'VideoJS', 'AmazonEmber-Bold', 'Amazon Ember', 'Lucida Sans Unicode', 'Arial Unicode MS']0: "Times"1: "Amazon Ember"2: "Arial"3: "sans-serif"4: "Arial"5: "Helvetica"6: "VideoJS"7: "AmazonEmber-Bold"8: "Amazon Ember"9: "Lucida Sans Unicode"10: "Arial Unicode MS"length: 11[[Prototype]]: Array(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment