UserScript and greasemonkey an Easy Way to Modify Web Pages

Do you want to see a web page as you like? Do you want to add some extra functions to a web page that will work for you? Do you want to make these changes On-the-Fly to a web page? Do you want these to a web page that you haven’t developed by you or you have no modification access to it? Then here is UserScript and greasemonkey.

You can achieve those goals easily in Mozilla Firefox. You are needed only five basic steps:

1.  Add the gresemonkey [a Mozilla Firefox] extension to your Firefox browser

2. Write your desired functionality/features to a UserScript. Include/Exclude the web address(es) in your UserScript that you want/doesn’t want to have the feature(s)

3. Then add your UserScript to the greasemonkey

4. Enable(if not) the greasemonkey into your browser

5. Finally open your desired web page into the Firefox web browser.

Here I’m not going to explain more about the greasemonkey and UserScript. but the basic idea of UserScript is:
UserScript is nothing but JavaScript code. It has two main sections: a) Header: where you will provide the Name/Description of the script, include/exclude the web pages that you want/doesn’t want to have this UserScript and b) Body: where you will write your desired feature in JavaScript code.

Once you write a UserScript then greasemonkey will provide you option to attach the file into it. An important point is that a UserScript file will have the extension .user.js [e.g. MyFeature.user.js]

Here is a sample UserScript:

// ==UserScript==
// @name SayHelo
// @description Whenever a page of google will be loaded then it will say Helo to user

// @include *google.com*
// ==/UserScript==

function SayHeloToUser()
{
alert(“Helo I’m from UserScript”);
}
SayHeloToUser();

After adding this UserScript if you open any page that has google.com in address bar then the message Helo I’m from UserScript will be shown by the browser.

> To know about greasemonkey follow the links greasemonkey and greasemonkey wiki.

> To know about how to add/delete/manage UserScript please click this link. Also don’t miss out to read the article from this diveintogreasemonkey, especially the PDF doc.

> To find existing UserScript that might work for you, follow the link www.userscript.org. This is a huge resource of UserScripts.

I hope you enjoyed this article! 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s