Tuesday, June 03, 2008

iPhone Bookmarklets

The Safari browser on the iPhone is probably the best mobile web browser out there. It does however some shortcoming and some of these can be addressed by using bookmarklets. Bookmarklets are snippets of JavaScript code that you can run in a browser to perform certain functions. To add a bookmarklet to your iPhone, create a bookmark/favourite in Safari/IE (on your Mac/PC)pointing to any web site (I use www.google.com)  and then edit its address to the bookmarklet's JavaScript code.  Here are the bookmarklets that I am currently using on my iPhone:

1. Bare Bones: This little gem I wrote myself and basically prompts the user for a web site address. Once that's gathered, it passes the address through Google and returns a lighter version of the web site. This is especially great when using GPRS/Edge as the data connection is slower. Hopefully this will be retired when the 3G iPhone comes out :-)

javascript:var%20url%20=%20prompt%20(%22Please%20enter%20the%20url%22,%22%22);var%20google%20=%20%22http://google.com/gwt/n?u=%22;var%20result%20=%20google%20+%20url;window.location%20=%20result;

2. Bare Bonsify: In the same vein as the Bare Bones bookmarklet, this one will convert all links on any web site to return a light version of the linked web site

javascript:var%20as;var%20google;var%20i;google='http://google.com/gwt/n?u=';as=document.getElementsByTagName('a');for%20(i=0;i%3Cas.length;i++)%7Bvar%20org;var%20result;org%20=%20as%5Bi%5D.href;result%20=%20google%20+%20org;as%5Bi%5D.href%20=%20result;%7Dalert('all%20links%20have%20been%20bare-boned');

3. iTransgromify: The clever bookmarklet will analyse a web page and convert any links to YouTube flash video to return the .H264 encoded equivalent which can then be played straight on the iPhone!

javascript:if%20(typeof%20iTransmogrify%20==%20%27undefined%27)%20%7Bd%20=%20document;s%20=%20d.createElement(%27script%27);s.setAttribute(%27src%27,%20%27http://itransmogrify.googlecode.com/files/iTransmogrify.js?q=%27%20+%20(new%20Date).getTime());d.getElementsByTagName(%27head%27)%5B0%5D.appendChild(s);%7Dvoid%200;

4. Find on this page: will prompt for text to find on the current page. The matches are then highlighted in yellow.

javascript:void%28s%3Dprompt%28%27Find%20text%3A%27%2C%27%27%29%29%3Bs%3D%27%28%27+s+%27%29%27%3Bx%3Dnew%20RegExp%28s%2C%27gi%27%29%3Brn%3DMath.floor%28Math.random%28%29*100%29%3Brid%3D%27z%27%20+%20rn%3Bb%20%3D%20document.body.innerHTML%3Bb%3Db.replace%28x%2C%27%3Cspan%20name%3D%27%20+%20rid%20+%20%27%20id%3D%27%20+%20rid%20+%20%27%20style%3D%5C%27color%3A%23000%3Bbackground-color%3Ayellow%3B%20font-weight%3Abold%3B%5C%27%3E%241%3C/span%3E%27%29%3Bvoid%28document.body.innerHTML%3Db%29%3Balert%28%27Found%20%27%20+%20document.getElementsByName%28rid%29.length%20+%20%27%20matches.%27%29%3Bwindow.scrollTo%280%2Cdocument.getElementsByName%28rid%29%5B0%5D.offsetTop%29%3B

5. Open links in new window: converts all links on a web page to open in a new window.

javascript:(function()%7Bvar%20a=doc.comument.getElementsByTagName('a');for(var%20i=0,j=a.length;i%3Cj;i++)%7Ba%5Bi%5D.setAttribute('target','_blank');var%20img=document.createElement('img');img.setAttribute('class',%20'new-window');img.setAttribute('src','data:image/gif;base64,'+'R0lGODlhEAAMALMLAL66tBISEjExMdTQyBoaGjs7OyUlJWZmZgAAAMzMzP///////wAAAAAAAAAAAAAA'+'ACH5BAEAAAsALAAAAAAQAAwAAAQ/cMlZqr2Tps13yVJBjOT4gYairqohCTDMsu4iHHgwr7UA/LqdopZS'+'DBBIpGG5lBQH0GgtU9xNJ9XZ1cnsNicRADs=');img.setAttribute('style','width:16px!important;height:12px!important;border:none!important;');a%5Bi%5D.appendChild(img);%7D%7D)();

2 Comments:

Anonymous Anonymous said...

I like the bare bones script very much, I'm going to see if this works on Windows Mobile also.

Occasionally I'm in the country (well, quite a bit actually) with very low signal and a script like this can be a real saver in a GPRS / lofi situation :)

Nice work :P

6:26 PM  
Anonymous CallumReality said...

Actually I changed the bare bones code and replaced the entire prompt command with location.host now the bookmarklet changes the current page which is more useful.

5:09 AM  

Post a Comment

<< Home