Skip to content

Instantly share code, notes, and snippets.

@huonw
Created April 18, 2012 13:09
Show Gist options
  • Save huonw/2413449 to your computer and use it in GitHub Desktop.
Save huonw/2413449 to your computer and use it in GitHub Desktop.
rot13 bookmarklet
javascript:function%20convert(inText){var%20outText='',t;for(i=0;i<inText.length;i++){t=inText.charCodeAt(i);if((t>64&&t<78)||(t>96&&t<110))t%20+=%2013;else%20if((t>77&&t<91)||(t>109&&t<123))t%20-=%2013;outText%20+=%20String.fromCharCode(t);}return%20outText;}var%20sel=window.getSelection().getRangeAt(0);if(sel==''){var%20act=document.activeElement;if(act.type=="textarea"){var%20start=act.selectionStart,end=act.selectionEnd;if(start!=end){var%20prefix=act.value.substring(0,start);var%20middle=convert(act.value.substring(start,end));var%20suffix=act.value.substring(end);act.value=prefix;act.value%20+=%20middle;void(act.value%20+=%20suffix);}}else{void(inText=prompt('Phrase...',''));if(inText)alert(convert(inText));}}else{out=convert(sel.toString());sel.deleteContents();var%20span=document.createElement("span");span.innerHTML=out;sel.insertNode(span);}
@baitisj
Copy link

baitisj commented Dec 5, 2016

Lovely :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment