Installing a local script with Greasemonkey

Though greasemonkey is thought to share your scripts with the community, you may prefer to have some script for personal websites, local applications or just very personal customization of a page. Most greasemonkey tutorials show you how to install a script stored online but forget about how to create your own script and install it in local:

Quick guide

Install Greasemonkey

Click on Greasemonkey icon -> Manage scripts -> New User Script…

Create your script following GM rules and save it.

If you already have the script, open it with the browser (you can drag and drop the file into the browser or use “Open with…”) and the install window will appear immediately (install button has a few seconds wait for security issues though).

Writing your own script

If you go to Greasemonkey icon > Add new user script, it will ask you for the basic data and generate a basic template with the minimum properties required (except the @grant, for some reason).

To make your script work you need to be care of some rules:
– The includes and excludes to set for which URLs it should be executed, if this is not done properly it will not execute.
– The global and local variables, access levels, etc. better explained at greasemonkey’s guides. If you are doing a simple “Hello World” this should be fine.
– Greasemonkey’s own libraries you can use. (the @grant keyword). You can just set “@grant none” to get rid of this.

Assuming you want to create a basic script without any GM library and for a unique page:

// ==UserScript==
// @name MyPersonalScript
// @namespace rc_some_irrepeteable_name
// @description A mere Hello World
// @include http://www.rubencanton.com/index.html
// @version 1
// @grant none
// ==/UserScript==

console.log('Hello World!');

And that would work. Now if you want a script to exec for a full domain or a full section inside a domain, you need to set that include a bit better and manage excludes if necessary. To include all urls inside a domain just use the *:

// @include http://www.rubencanton.com/*

That will exec for every page inside my domain.

Using jQuery

If the website you are accessing already has it, just use this at the top of the script to gain access to it:
this.$ = this.jQuery = jQuery.noConflict(true);

Example:

this.$ = this.jQuery = jQuery.noConflict(true);

$(document).ready(function() {
// Do some stuff
});

If the website is not using jQuery, you can include that script using greasemonkey’s config keywords.

Saving a script for future use

If you want to have your scripts in a safe place so you can backup them or take them with you just click on Greasemonkey’s icon -> manage scripts. Right click over the script -> Open in Containing folder.

Now you can save the scripts you want to keep wherever you prefer.