HTML Misc

First Greasemonkey Script

Once i was surfing orkut and came to know about greasemonkey. Its name caught my attention and i goggled little to find what exactly it is. I found it really interesting and useful and i started experimenting. Greasemonkey was the only solution i found for one of my problem, see the story and little advanced userscript example here

So what is Greasemonkey ?

Its a firefox plugin which allows you to write scripts to play with look and feel of web page. Install the addon and restart the firefox. If it gets installed properly you should see smiling “monkey” face in right bottom of firefox.


Ok whats next ?

once you installed this addon you need to write userscript.

Now what is this userscript ?

userscript is nothing but peace of javascript code that tells greasemonkey addon when and what to run from this script. These script strictly end up with user.js ex : example.user.js. whenever you will try open any file with .user.js extension, greasemonkey addon will automatically ask you to install it.

userscript is plain javascript code file nothing special. You can use all the features of javascript in userscript. There are few more function provided by Greasemonkey, you can find the list here Greasemonkey Manual:API

Lets start My First Greasemonkey User Script

To create new script right click on “monkey” face and then select New User Script and popup will come up as shown below. enter all the details as shown below in the image and click on ok.

getting started with greasemonkey

getting started with greasemonkey (Click to enlarge)

it should open default text editor for js files. with the default text as shown below

Now add below javascript to it and save the page
or Install it directly from here myfirstscript.user.js

Full source code should look like this

Now we are done with our first greasemonkey script. Now lets test it 😉

To see it in action Refresh the firefox
it will ask for “What is your Name ?” enter your name and click “ok”.

see what happened ? look at title bar of window as shown in image below.

Its not my blog anymore…its your blog now 🙂 🙂 🙂
Just 2 lines of javascript gifted this blog to you. Isn’t it fun ???

You can find detailed information here diveintogreasemonkey.org

Add Comment

Leave a Comment

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Shares

Let your friends know what are you reading

Share this post with your friends!