Last active
September 19, 2022 15:11
-
-
Save johnmurch/9f7f7f3563adb44cbe7da52f51577e23 to your computer and use it in GitHub Desktop.
Get Fonts from Website
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
// 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