Last active
July 2, 2016 09:48
-
-
Save lackneets/9f98aedc0b756664f9f4a536d2293971 to your computer and use it in GitHub Desktop.
Get all font-family on page
This file contains hidden or 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
(function(){ | |
var fonts = []; | |
Array.from(document.styleSheets).forEach(function(styleSheet){ | |
Array.from(styleSheet.cssRules || []).forEach(function(rule){ | |
String(rule.style && rule.style.fontFamily).split(/\s*,\s*/).forEach(function(font){ | |
font = font.replace(/^["'](.*)["']$/, '$1'); | |
if(font && fonts.indexOf(font) == -1 && !font.match(/undefined|inherit|initial/i)){ | |
fonts.push(font); | |
} | |
}) | |
}); | |
}); | |
console.log(fonts.sort()); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment