Last active
July 10, 2020 13:30
-
-
Save matthewmayer/114570269b1b4e08be4c54c88d8c5683 to your computer and use it in GitHub Desktop.
paste this into Javascript console to see what fonts are being used
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
function walk(node) { | |
// I stole this function from here: | |
// http://is.gd/mwZp7E | |
var child, next; | |
var tagName = node.tagName ? node.tagName.toLowerCase() : ""; | |
if (tagName == 'input' || tagName == 'textarea') { | |
return; | |
} | |
if (node.classList && node.classList.contains('ace_editor')) { | |
return; | |
} | |
switch (node.nodeType) { | |
case 1: // Element | |
case 9: // Document | |
case 11: // Document fragment | |
child = node.firstChild; | |
while (child) { | |
next = child.nextSibling; | |
walk(child); | |
child = next; | |
} | |
break; | |
case 3: // Text node | |
handleText(node); | |
break; | |
} | |
} | |
function handleText(textNode) { | |
var v = textNode.nodeValue; | |
var cs = window.getComputedStyle(textNode.parentNode) | |
if (cs && textNode.parentNode.nodeName != "STYLE" && textNode.parentNode.nodeName != "SCRIPT") { | |
let font = cs.fontFamily || "" | |
let size = cs.fontSize | |
let weight = cs.fontWeight | |
let weights = { | |
100: "Thin", | |
200: "Extra Light", | |
300: "Light", | |
400: "Regular", | |
500: "Medium", | |
600: "Semibold", | |
700: "Bold", | |
800: "Extra Bold", | |
900: "Black" | |
} | |
font = font.replace("sans-serif", "").replace(/[,"]/g, "").trim() | |
font = font.replace("Red Hat Text", "RHT").replace("Red Hat Display", "RHD") | |
textNode.nodeValue = font + " " + size + " " + weights[weight] | |
} | |
} | |
walk(document.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may want to consider using TreeWalker to find textNodes; it's significantly faster, especially for large DOM's. An example is below, written as a DevTools snippet (though you can paste it on the console for use as well).
Note, this won't travel the ShadowDOM (which we don't have a great story for yet on the platform, but it is being discussed).
Similarly, if you just wanted a look at the styles you have defined, you could do so using
new Set()
for storing unique values, which can be useful for quick reports: