Skip to content

Instantly share code, notes, and snippets.

@rexso
Last active August 29, 2015 14:17
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 rexso/fe00c8521b8158f9ef8d to your computer and use it in GitHub Desktop.
Save rexso/fe00c8521b8158f9ef8d to your computer and use it in GitHub Desktop.
(function(){
function ℓ(c){return(c.toLowerCase()==c);}
String.prototype.ℛ=function(e,s){return this.replace(e,s.length>1?s:function(m){return(ℓ(m[0])?s:s.toUpperCase());});};
function omgz0rify(s) {
return s
.ℛ(/s/ig,'z') // s -> z
.ℛ(/v/ig,'w') // v -> w
.ℛ(/o/ig,'0') // o -> 0
.ℛ(/ae/ig,'æ') // ae -> æ
.ℛ(/er/ig,'r') // er -> r
.ℛ(/en/ig, 'n') // en -> n
.ℛ(/ekz/ig,'x') // eks -> x
.ℛ(/(c|k)u/ig,'q') // cu|ku -> q
.ℛ(/le([\s,.?!-])/g, 'l$1') // le -> l (end of words)
.ℛ(/([a-zæøå]{3})[aeiouyæøå]([\s,.?!-])/gi,'$1'+'0r$2') // replace last vovel with 0r in words longer than 4-letters
.ℛ(/([a-zæøå]{3}[b-df-hj-no-tv-x])([\s,.?!-])/gi,'$1z0r$2') // append z0r to words longer than 4-letters ending with a consonant
//.ℛ(/([a-zæøå]{2,}[aeiouyæøå][bdfgkmnpt]{1,2})[a-zæøå]*/ig, '$1z0r'); // W.I.P
}
var n,a=[],w=document.createTreeWalker(document.body);
while((n=w.nextNode()))a.push(n);
a.forEach(function(n){if(n.data)n.data=omgz0rify(n.data);})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment