Get the Greasemonkey addOn
You simply goto the list of Firefox addOns and
from there. You ofcause then need to restart Firefox. After that is done you will see a monkey icon to the lower right of your browser:
To turn on and off left mouse click, to access script right mouse click on the monkey.
Your first script
Let’s do a hello world! You simply right mouse click on the monkey and choose the “New user script..” (here you see it in Danish):
The editor – first time
- Edited/changed scripts require a refresh of any window to work with the new code
- Any change in
@requiredirective will call for you to reinstall your script (more below)
See also below: The editor – how to change it
The basic choises
After you have pressed the “New user script…” you will be prompted with something like this (here in Danish):
Simply fill out the fields, with, name, namespace, short description and important the URLs where the script should and should not be able to execute. The first field will have the current URL of the active tab/window in your firefox filled out. You may remove that and simply choose any website by entering “http://*”.
If you have issues like you dont want this script to run on your local pc, you can enter URLs to exclude.
Here is an example of how a simple hello world script might look like now:
As you can also see, the URLs which you wanted to include and exclude have converted into directives. The
@exclude directives, which you ofcause may change manually in your script file at a later time.
Running the script
After you have enteret a “alert(‘Hello world’);” and saved the script you are ready to run the script. You simply refresh the page by pressing F5 or Ctrl+R.
What you will see is an alert box saying “Hello world”. The code will be called after the page have been rendered (loaded) into the browser window. Nothing advanced here ofcause, but you now have the fundament for developing your own utilities, macroes in the form of Grease monkey scripts.
Adding external resources like jQuery to your script
You have the option to specify any required script libraries (resources) which your script need to have installed. You do that by using the
@require directive in the header of your script. Lets try to add jQuery.
– adding jquery description –
One thing to notice when adding new
@require directives is that you need to reinstall your script again:
As of Greasemonkey 0.8.x, an @require directive added to an already installed script will not be recognized. Reinstall the script to force Greasemonkey to recognize the @require directive. You can simply drag-and-drop the script onto a Firefox browser window, or again in Firefox choose File>Open and select the user script, to reinstall it.
When you want to reinstall I find drag’n’dropping the script from explorer directly onto a firefox window a very convient way. Here is hos it may look (here in Danish):
A nice clean way to reinstall a script! The Greasemonkey folks have even added a short message at the bottom of the status line which displays information about how it succeded in installing the script! Well done Greasemonkey folks!
- Change or Set the Greasemonkey Script Editor in Firefox on www.howtogeek.com
- How to add menu items to Greasemonkey using GM_registerMenuCommand
- Userscripts for Greasemonkey
- Greasefire Shows Which Greasemonkey Scripts Work On Websites You Visit