Skip to content

Instantly share code, notes, and snippets.

@dannvix
Created August 1, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannvix/df4ff25bc5ed5d15a3c3 to your computer and use it in GitHub Desktop.
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
/*
* 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