Skip to content

Instantly share code, notes, and snippets.

@gpspake
Last active August 29, 2015 14:10
Show Gist options
  • Save gpspake/c8f05ecd6bcbddd65d89 to your computer and use it in GitHub Desktop.
Save gpspake/c8f05ecd6bcbddd65d89 to your computer and use it in GitHub Desktop.
Sanseref
// ==UserScript==
// @name Sanseref
// @namespace sanseref
// @description Replaces instances of "San Serif" with "Sanseref". Ported from and Inspired by panicsteve's cloud-to-butt extension for Google Chrome, and DaveRandom's ports thereof.
// @include *
// @version 1.0.1
// @grant none
// @updateURL https://gist.github.com/gpspake/c8f05ecd6bcbddd65d89
// ==/UserScript==
(function() {
function walk(node)
{
// I stole this function from here:
// http://is.gd/mwZp7E
var child, next;
switch ( node.nodeType )
{
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while ( child )
{
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // Text node
handleText(node);
break;
}
}
function handleText(textNode)
{
var v = textNode.nodeValue;
v = v.replace(/\bsans serif\b/gi, "sanseref");
v = v.replace(/\bSans Serif\b/gi, "Sanseref");
v = v.replace(/\bSans serif\b/gi, "Sanseref");
v = v.replace(/\bsans Serif\b/gi, "sanseref");
v = v.replace(/\bSANS SERIF\b/gi, "Sanseref");
v = v.replace(/\bsans-serif\b/gi, "sanseref");
v = v.replace(/\bSans-Serif\b/gi, "Sanseref");
v = v.replace(/\bSans-serif\b/gi, "Sanseref");
textNode.nodeValue = v;
}
walk(document.getElementsByTagName('body')[0]);
walk(document.getElementsByTagName('title')[0]);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment