Created
August 1, 2015 15:09
-
-
Save dannvix/df4ff25bc5ed5d15a3c3 to your computer and use it in GitHub Desktop.
Bookmarklet that replaces all fonts with “Hiragino Kaku Gothic Pro” on current webpage
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
/* | |
* 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment