Skip to content

Instantly share code, notes, and snippets.

@rockerBOO
Forked from matthewmayer/whatthefont.js
Created October 11, 2019 15:57
Show Gist options
  • Save rockerBOO/1f489c54bf06bc0de4d6db84ba2ba63f to your computer and use it in GitHub Desktop.
Save rockerBOO/1f489c54bf06bc0de4d6db84ba2ba63f to your computer and use it in GitHub Desktop.
paste this into Javascript console to see what fonts are being used
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