// Detector from http://www.lalit.org/lab/javascript-css-font-detect/
// Other code by Alan Hogan
// http://www.apache.org/licenses/LICENSE-2.0
// Compile this to a bookmarklet at http://bookmarklets.org/maker/
// Some code has been previously converted by the Babel REPL to survive
// running in IE11. Avoid ES6 or transpile before committing updates.

var Detector = function Detector() {
  var baseFonts = ['monospace', 'sans-serif', 'serif'];

  var testString = "mmmmmmmmmmlli";

  var testSize = '72px';

  var h = document.getElementsByTagName("body")[0];

  var s = document.createElement("span");
  s.style.fontSize = testSize;
  s.innerHTML = testString;
  var defaultWidth = {};
  var defaultHeight = {};
  for (var index in baseFonts) {
    s.style.fontFamily = baseFonts[index];
    h.appendChild(s);
    defaultWidth[baseFonts[index]] = s.offsetWidth; 
    defaultHeight[baseFonts[index]] = s.offsetHeight; 
    h.removeChild(s);
  }

  function detect(font) {
    var detected = false;
    for (var index in baseFonts) {
      s.style.fontFamily = font + ',' + baseFonts[index];
      h.appendChild(s);
      var matched = s.offsetWidth != defaultWidth[baseFonts[index]] || s.offsetHeight != defaultHeight[baseFonts[index]];
      h.removeChild(s);
      detected = detected || matched;
    }
    return detected;
  }

  this.detect = detect;
};

var d = new Detector();

function guessBodyFont() {
  var body = document.getElementsByTagName('body')[0];
  var stack = body ? window.getComputedStyle(body).fontFamily : '';
  var fonts = stack.split(/\s*,\s*/).map(function (font) {
    return font.replace(/^['"]\s*(.+\S)\s*['"]$/, '$1');
  });

  var probableFont = false;
  var availableFonts = [], unavailableFonts = [];
  fonts.forEach(function (font) {
    if (d.detect(font)) {
      probableFont = probableFont || font;
      availableFonts.push(font);
    } else {
       unavailableFonts.push(font);
    }
  });

  if (probableFont) {
    alert("BODY element is probably using the font family or keyword: \n" + probableFont + "\n\n" + "All matching font names or keywords in the stack: \n" + availableFonts.join("\n") + "\n\n" + "Unavailable fonts: \n" + (unavailableFonts.length > 0 ? unavailableFonts.join("\n") : '(None)') + "\n\n" + "Font stack as reported by getComputedStyle: \n" + stack + "\n\nNote cautions and update this bookmarklet at https://alanhogan.com/bookmarklets#font-stack-guess");
  } else {
    alert('Did not detect a font set for body');
  }
}

guessBodyFont();

@@ -347,16 +347,41 @@
 dates.%0A%0A
+var versionStr = '1.0';%0A%0A
 var Dete
@@ -1080,16 +1080,23 @@
 Family =
+ '%5C'' +
  font + 
@@ -1096,17 +1096,20 @@
 font + '
-,
+%5C', 
 ' + base
@@ -1438,16 +1438,26 @@
 odyFont(
+fullReport
 ) %7B%0A  va
@@ -2000,22 +2000,32 @@
 ) %7B%0A    
-alert(
+var reportStr = 
 %22BODY el
@@ -2094,16 +2094,67 @@
 ableFont
+;%0A    if (fullReport) %7B%0A      reportStr = reportStr
  + %22%5Cn%5Cn
@@ -2419,195 +2419,779 @@
 tack
- + %22%5Cn%5CnNote cautions and update this bookmarklet at https://alanhogan.com/bookmarklets#font-stack-guess%22);%0A  %7D else %7B%0A    alert('Did not detect a font set for body');%0A  %7D%0A%7D%0A%0AguessBodyFon
+;%0A      reportStr = reportStr + %22%5Cn%5CnOnly Latins characters are tested, so detection will fail for Asian fonts, emojis, and system fonts. %22;%0A    %7D else %7B%0A      reportStr = reportStr + %22%5Cn%5Cn%22%0A    %7D%0A%0A    reportStr = reportStr + %22More info and potentially a newer version of this bookmarklet are available at %22%0A      + %22https://alanhogan.com/bookmarklets%22%0A      + (fullReport ? '#font-stack-full' : '#font-stack-guess');%0A    %0A    reportStr = reportStr + %22%5Cn%5CThis is version %22 + versionStr;%0A    %0A    alert(reportStr);%0A  %7D else %7B%0A    alert('Did not detect a font set for body');%0A  %7D%0A%7D%0A%0Afunction fullBodyFontStackReport() %7B%0A  guessBodyFont(true);%0A%7D%0A%0A// Uncomment ONE of these to generate the simple vs full version of the bookmarklet.%0A// guessBodyFont();%0AfullBodyFontStackRepor
 t();

Fix detection of fonts with periods in the name