Skip Navigation code drift

Fake Germanizer

written  &  updated
in Code, but also JavaScript, & LinkedIn
🆕
2020-02-23: This was rescued from the archives of the old felocity.org. As a result, many links in this piece were left pointing to archive.org destinations.

I ran into a problem where I needed to guess how something would look in German, without knowing a single drop of German. So, I pulled up Mozilla's XPath documents and made a small bookmarklet. It's far from perfect, but it definitely has its uses when you're trying to estimate how items will look before they reach a translation team... even if the first use was messing with my Twitter feed.

Fauxgermanhausen das Pagen! (bookmarklet)
    (function () {
      var prefixes = ["", "glocken", "das", "borfa", "maushe", "uber"],
        suffixes = [
          "",
          "hausen",
          " die vander",
          "gleuten",
          "noshan",
          "flagellan",
          "mek",
          "dak",
          "en das",
          "ga",
        ],
        xPathResult = document.evaluate(
          ".//text()[normalize-space(.)!='']",
          document.body,
          null,
          XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
          null
        ),
        i,
        textNode,
        cnt,
        out,
        j,
        pfx,
        sfx;
      for (i = 0, l = xPathResult.snapshotLength; i < l; i++) {
        textNode = xPathResult.snapshotItem(i);
        if (
          textNode.parentNode.nodeName.toLowerCase() == "script" ||
          textNode.tagName == "style"
        )
          continue;
        cnt = textNode.data.split(/\s/g);
        out = [];
        for (j = 0; j < cnt.length; j++) {
          if (cnt[j].replace(/[\s]/g, "") == "") continue;
          pfx = !Math.floor(Math.random() * 10)
            ? ""
            : prefixes[Math.floor(Math.random() * prefixes.length)];
          sfx = !Math.floor(Math.random() * 10)
            ? ""
            : suffixes[Math.floor(Math.random() * suffixes.length)];
          out.push(pfx + cnt[j] + sfx);
        }
        textNode.data = " " + out.join(" ") + " ";
      }
    })();