Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zarino
Last active February 20, 2016 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zarino/8774c74d4595354cf9dd to your computer and use it in GitHub Desktop.
Save zarino/8774c74d4595354cf9dd to your computer and use it in GitHub Desktop.
A simple JavaScript function that doubles every character on a web page – useful when testing layouts for i18n issues
// Paste this function to your browser’s JavaScript console,
// and then run it, passing in a CSS selector, eg:
// > pseudolocalize('body')
var pseudolocalize = function pseudolocalize(arg){
if(typeof arg === 'string'){
var elements = document.querySelectorAll(arg);
for(var i=0, len=elements.length; i<len; i++){
pseudolocalize(elements[i]);
}
} else if(arg.nodeType === 1){
for(var i=0, len=arg.childNodes.length; i<len; i++){
pseudolocalize(arg.childNodes[i]);
}
} else if(arg.nodeType === 3){
arg.nodeValue = arg.nodeValue.replace(/(.)/g, '$1$1');
}
}
var pseudolocalize=function e(l){if("string"==typeof l)for(var o=document.querySelectorAll(l),d=0,n=o.length;n>d;d++)e(o[d]);else if(1===l.nodeType)for(var d=0,n=l.childNodes.length;n>d;d++)e(l.childNodes[d]);else 3===l.nodeType&&(l.nodeValue=l.nodeValue.replace(/(.)/g,"$1$1"))};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment