One of the iPhone's few glaring disappointments is the lack of proper copy and paste. If I'm on a page and I want to send a chunk of it over to Twitter, I have no choice but to memorize it, bring up Twitter's horrific little iPhone interface, and painfully bang it in there with my big fat fingers. After warming up with iClock, a toolbar bookmarklet that contains an entire Web page in a base-64 encoded data: URL, I was ready to try something a bit more useful. Hopefully this is it:
Cleeper will inject itself into the page you're on, wait for you to click an existing block-level element, and copy the text of the element into an entry box, where you can edit it. After you're done editing, click the Cleep button to send your message off to Twitter. You'll still need to hit Twitter's update button, so don't panic; Cleeper's not going to post anything on your behalf.
Click it and try it out here first, just so you know what you're getting into. If you want to try it on your iPhone or iPod Touch, drag it to your Safari bookmarks toolbar, sync bookmarks to your device, and you ought to be off and running. If you need some instruction on exactly how to get Cleeper onto your iPhone, click this:
... it would be that your first Cleeper-assisted tweet looks something like this:
Trying out @kentbrew's Cleeper, an iPhone copy-to-Twitter assistant, from http://bit.ly/pxfu
Go on, cleep it right now. You know you want to! :)
SPAN tags, and only bring in enough to fill the entry box.It's a tiny bit more complicated than iClock, which runs straight from a data: url. In order for Cleeper to work, we need to inject it into the page containing the target text. That's easy; we do something like this:
javascript:(function(d){d.body.appendChild(d.createElement('SCRIPT')).src='http://yourserver.com/yourscript.js';})(document);
Because we don't want the code that does the heavy lifting to come from an outside server--privacy, efficiency, and all that--we need to serve it up locally, using the base-64 encoding method described in iClock. So we write a script, base-64-encode the whole thing, and serve it up as data instead of fetching http://yourserver.com/yourscript.js from a remote URL. Like so:
javascript:(function(d){d.body.appendChild(d.createElement('SCRIPT')).src='data:text/html;charset=utf-8;base64,yourbase64encodedscript';})(document);
(function(){
var d=document;
var e=['P','LI','DIV','DD','TD','TEXTAREA','PRE','INPUT'];
for (var i=0;i<e.length;i++){
var n=d.getElementsByTagName(e[i]);
for (var j=0; j < n.length; j++){
n[j].addEventListener("click", function(e){e.stopPropagation(); load(this);}, false);
}
}
var s=d.createElement('DIV');
var h=d.createElement('P');
h.innerHTML='click some text';
s.appendChild(h);
s.y=s.style;
s.y.backgroundColor='#ffa';
s.y.textAlign='center';
s.y.paddingBottom='5px';
s.y.border='1px solid #000';
s.y.height='50px';
s.y.width='320px';
s.y.position='fixed';
s.y.top='0';
s.y.left='0';
s.y.zIndex='8675309';
var t=d.createElement('TEXTAREA');
t.y=t.style;
t.y.width='300px';
t.y.height='300px';
t.y.fontFamily='Tahoma';
t.y.fontSize='92%';
t.y.margin='20px auto';
t.y.backgroundColor='#fff';
t.y.color='#000';
t.y.display='none';
s.appendChild(t);
var b=d.createElement('BUTTON');
b.innerHTML='Cleep';
b.onclick=function(){d.location='http://twitter.com/home?status=' + encodeURIComponent(t.value);};
s.appendChild(b);
var g=d.createElement('SPAN');
s.appendChild(g);
var c=d.createElement('BUTTON');
c.innerHTML='Cancel';
c.onclick=function(){s.parentNode.removeChild(s);};
s.appendChild(c);
d.body.appendChild(s);
function load(e){
var v=e.innerHTML;
if(e.value){v=e.value;}
t.y.display='';
t.y.height='300px';
t.value=v.replace(/<[^>]*>/g, '').replace(/\s{2,}/g, ' ');
s.y.height='400px';
h.style.display='none';
setInterval(updateLength, 100);
}
function updateLength(){g.innerHTML=t.value.length;}
})();
Sorry this is so compressed; I was running up against a hard number-of-characters-in-a-bookmarklet limit in Safari. It's pretty unremarkable DOM manipulation, and probably could be improved with an axe.
If you find Cleeper to be useful, please follow me at kentbrew, so I can keep you up-to-date. As always, have fun with this, and please let me know how it goes.