Skip to content

Instantly share code, notes, and snippets.

@dannvix
Created August 1, 2015 15:09
Show Gist options
  • Save dannvix/df4ff25bc5ed5d15a3c3 to your computer and use it in GitHub Desktop.
Save dannvix/df4ff25bc5ed5d15a3c3 to your computer and use it in GitHub Desktop.

Revisions

  1. dannvix created this gist Aug 1, 2015.
    29 changes: 29 additions & 0 deletions replace-fonts-bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    /*
    * Pack below script via http://jscompress.com/ to generate bookmarklet
    */
    (function(rootNode, fontFamily) {
    var hasChildTextNode = function(parentNode) {
    return [].some.call(parentNode.childNodes, function(node) {
    if (node.nodeType == Node.TEXT_NODE) {
    console.log(node.nodeValue);
    }
    return node.nodeType == Node.TEXT_NODE;
    });
    };

    var OverrideFontFamilyRecursively = function(parentNode) {
    var childNodes = parentNode.childNodes;
    [].forEach.call(childNodes, function(node, index) {
    switch (node.nodeType) {
    case Node.ELEMENT_NODE:
    if (hasChildTextNode(node)) {
    node.style.fontFamily = fontFamily + " " + node.style.fontFamily;
    node.style.webkitFontSmoothing = "subpixel-antialiased";
    }
    OverrideFontFamilyRecursively(node);
    break;
    }
    });
    };
    OverrideFontFamilyRecursively(rootNode);
    })(document.body, "Hiragino Kaku Gothic Pro");