What is the Greasemonkey namespace needed for?

I'm learning how to use Greasemonkey, and was wondering what the @namespace metadata id is for.

Does it have to be a web address? Or can it be a folder/directory on my computer?

Does it even need to be filled in?


It's used to avoid naming collisions. If you called your script foobar and someone else did as well, then central repositories would have a hard time knowing them apart.

Therefore you should provide some URL that you control (i.e. you own it or can administrate it) that basically means "everything with that URL is by me". Now those central repositories can distinguish between foobar from http://somesite.com/ and foobar from http://anothersite.com.

It's not necessary for basic operation, but strongly suggested if you want to share your scripts.

One place you can see the practical effect of namespaces is in storing preferences. Nampsaces are used to uniquely identify scripts for any script-specific stored preferences.

For example, if you have a script like this:

// ==UserScript==
// @name            Script Name
// @namespace       http://example.com
// @include         *
// ==/UserScript==

GM_setValue("key", "value");

That would be stored in your preferences (accessible in prefs.js, and about:config) like so:

greasemonkey.scriptvals.http://example.com/Script Name.key

Note the format: greasemonkey.scriptvals . namespace . scriptname . key/variablename

In general, a namespace is an abstract container providing context for the items (names, or technical terms, or words) it holds and allowing disambiguation of items having the same name (residing in different namespaces).

Source: Namespace - Wikipedia

And more specific:

This is a URL, and Greasemonkey uses it to distinguish user scripts that have the same name but are written by different authors. If you have a domain name, you can use it (or a subdirectory) as your namespace. Otherwise you can use a tag: URI.

@namespace is optional. If present, it may appear only once. If not present, it defaults to the domain from which the user downloaded the user script.

Source: Dive Into Greasemonkey - Metadata

Namespace can be a URL, but not only. You can use as namespace some words as your username or real name.

Need Your Help

Grails Acegi manual login

security authentication grails spring-security grails-plugin

Is there a way to do that without using a POST request to "j_spring_security_check"?

Including JNA code in project - compile error

java windows jna

I am working with sample code from another StackOverflow post - Java - How to take a screenshot fast, but I'm having some issues.