Created
March 21, 2010 01:04
-
-
Save gaarf/339005 to your computer and use it in GitHub Desktop.
Stealth Tweets with Unicode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Stealth Tweets with Unicode</title> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssfonts/fonts-min.css" /> | |
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script> | |
<script> | |
YUI().use('node',function(Y) { | |
/* | |
* STEALTH TWEETS! by @gaarf | |
* | |
* hosted at http://daltonx.net/hacks/stealthtweets.html | |
* source on http://gist.github.com/gists/339005/ | |
* thanks to http://www.alanwood.net/unicode/enclosed_alphanumerics.html | |
*/ | |
function doTransform(input,lmode,dmode) { | |
var output = ''; | |
for(var i=0; i<input.length; i++) { | |
var c = input.charCodeAt(i); | |
if(c>=65 && c <=90 && lmode=='circled') { // uppercase letter | |
c += (9398-65); | |
} | |
else if(c>=97 && c <=122) { // lowercase letter | |
switch(lmode) { | |
case 'circled': | |
c += (9424-97); | |
break; | |
case 'parens': | |
c += (9372-97); | |
} | |
} | |
else if(c>=48 && c<=58) { // digit | |
switch(dmode) { | |
case 'circled': | |
if(c==48) c = 9450; | |
else c += (9312-49); | |
break; | |
case 'double': | |
if(c!=48) c += (9461-49); | |
break; | |
case 'parens': | |
if(c!=48) c += (9332-49); | |
} | |
} | |
output += String.fromCharCode(c); | |
} | |
return output; | |
} | |
// ---------------------------------------------- UI stuff | |
function focusAndSelect(t) { | |
t.set('selectionStart',0).set('selectionEnd',t.get('value').length).focus(); | |
} | |
var body = Y.one(document.body); | |
function createForm(text) { | |
if(!Y.Lang.isString(text)) { text=''; } | |
body.set('innerHTML', "<textarea>"+text+"</textarea> <div> <select class='letters'> <option value='circled'>Circled Letters</option> <option value='parens'>Parenthesized Letters (lowercase only)</option> </select> <select class='digits'> <option value='circled'>Circled Digits</option> <option value='double'>Double-Circled Digits (no zero)</option> <option value='parens'>Parenthesized Digits (no zero)</option> </select> <button>TRANSFORM!</button> <a href='#' class='reset'>reset</a> <a href='http://twitter.com/home' class='tweet'>Tweet it</a></div>"); | |
focusAndSelect(body.get('firstChild')); | |
} | |
body.delegate('click',createForm,'a.reset'); | |
body.delegate( | |
'click', | |
function(ev) { | |
ev.halt(); | |
window.open(this.get('href')+'?status='+encodeURIComponent(Y.one('textarea').get('value')),'TwitterWebClient'); | |
}, | |
'a.tweet' | |
); | |
body.delegate( | |
'click', | |
function() { | |
var elTarea = Y.one('textarea'); | |
var res = doTransform( | |
elTarea.get('value'), | |
Y.one('select.letters').get('value'), | |
Y.one('select.digits').get('value') | |
); | |
elTarea.set('value',res); | |
focusAndSelect(elTarea); | |
}, | |
'button' | |
); | |
Y.on('domready',createForm, null, 'Hell0 Wo3ld!'); | |
}); | |
</script> | |
<style type="text/css"> | |
body {margin:10px; } | |
textarea { width: 100%; font-size:666%; height:2.4em; overflow:auto; } | |
button { font-weight:bold; } | |
</style> | |
</head> | |
<body> | |
<noscript> | |
Turn JS on! | |
</noscript> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment