3

Engrish Javascript

Posted in JavaScript at October 20th, 2006 / 3 Comments »

In what I can think of as the most important JavaScript that I have ever written, I have made something which will parse the DOM and replace all of the ‘l’s with ‘r’s. This idea came about after watching Team America: World Police about 1,000 times and after Kim Jong Il gave his apology for doing some nuke testing. Back to the script:

function engrish(n) {
	if(n.nodeType == document.TEXT_NODE) {
		n.nodeValue = n.nodeValue.replace(/l/g, 'r').replace(/L/g, 'R');
	} else if(n.hasChildNodes()) {
		for(var i=0; i<n.childNodes.length; i++) {
			engrish(n.childNodes[i]);
		}
	}
}

To execute this code, simply call engrish(document.documentElement);. Using recursion, this function goes through the DOM, finds text nodes and replaces the characters.

Read the rest of this entry »