Adding javascript source code into browser's bookmarks

Adding javascript source code into browser's bookmarks


Table of Contents

  • 1 Introducing two awesome web app.
  • 2 How did those buttons works?
  • 3 A hello world example

1 Introducing two awesome web app.

First one, Tumblr is a really popular blog system, it provides mobile clients to post articles anytime and anywhere, that's awesome right, what's more, its customized themes and open API is what I appreciated. It's a fabulous app. 
For web browser users, It provides a share button which can be added to your bookmarks. So when you find some great articles, and you are urgent to share, what you did is just to click the share button in your bookmarks which you just installed. 

This shard button located in http://www.tumblr.com/apps.
The second web app is Instapaper, which is a simple tool to save web pages for reading later. I always search articles in the browser, and sometimes I just get too many results, but I have to power off the PC at midnight, do not work too later, unless it leads to the detriment of your health, huh! 

Instapaper also provides a button named "Read Later". it can also be drag into your bookmarks, just the same way like Tumblr dose. So when you want to save some articles into Instapaper, what you need to do is to click the "Read Later" button.

2 How did those buttons work?

Those buttons are actually javascript source code, which can be executed when you send click event into it. 

Tumblr:

javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://www.tumblr.com/share',l=d.location,e=encodeURIComponent,p='?v=3&u='+e(l.href) +'&t='+e(d.title) +'&s='+e(s),u=f+p;try{if(!/^(.*\.)?tumblr[^.]*$/.test(l.host))throw(0);tstbklt();}catch(z){a =function(){if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=450,height=430'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();}void(0)
after I delete the header statement and add indent the source code, what I get is the following:
// javascript:
var d=document;
var w=window;
var e=w.getSelection,k=d.getSelection,x=d.selection;
var s=(e?e():(k)?k():(x?x.createRange().text:0));
var f='http://www.tumblr.com/share'; 
var l=d.location;
var e=encodeURIComponent;
var p='?v=3&u='+e(l.href) +'&t='+e(d.title) +'&s='+e(s);
var u=f+p;
try {
    if(!/^(.*\.)?tumblr[^.]*$/.test(l.host))
        throw(0);
    tstbklt();
} catch(z) {
    a =function() {
        if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=450,height=430'))l.href=u;};
    if(/Firefox/.test(navigator.userAgent))
        setTimeout(a,0);
    else 
        a();
}
void(0)

what it does is just open http://www.tumblr.com/share in another window, and give it some URI location information of course.
And Instapaper's read later button works just the same way.

3 A hello world example

javascript:alert('hello, world!');void(0)

Add that to bookmarks, what you get is the classic "hello world!" message after you click it.

Comments

Popular posts from this blog

Bluedroid stack in android

How to setup a NAT server?

Network programming in elisp