What is the Greasemonkey namespace for?

I am learning how to use Greasemonkey, and wondered what the metadata identifier @namespace .

Should it be a web address? Or could it be a folder / directory on my computer?

Do I need to fill it out?

+59
namespaces greasemonkey metadata
Dec 22 '08 at 16:07
source share
4 answers

The namespace is used to avoid name conflicts. If you called your script foobar and someone else did the same, then it would be difficult for central repositories to distinguish them.

Therefore, you must provide some URL that you control (that is, you own or can control it), which basically means "everything with this URL belongs to me." Now these central repositories can distinguish between foobar from http://somesite.com/ and foobar from http://anothersite.com .

This is not necessary for the basic operation, but is highly recommended if you want to share your scripts.

Remember that mailto:someone@example.com also a valid URL and may be a possible option if you do not own or manage your own domain.

+58
Dec 22 '08 at 16:10
source share

In one place, you can see the practical effect of namespaces in preserving preferences. Nampsaces are used to uniquely identify scripts for any saved script settings.

For example, if you have a script like this:

 // ==UserScript== // @name Script Name // @namespace http://example.com // @include * // ==/UserScript== GM_setValue("key", "value"); 

This will be saved in your preferences (available in prefs.js and about: config) as follows:

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

Pay attention to the format: greasemonkey.scriptvals. namespace . scriptname . key/variablename

+14
Dec 22 '08 at 16:28
source share

In the general case, a namespace is an abstract container that provides a context for the elements (names or technical terms or words) that it contains, and that are ambiguous elements that have the same name (located in different namespaces).

Source: Namespace - Wikipedia

And more specifically:

This is a URL, and Greasemonkey uses it to distinguish custom 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 the tag: URI.

@namespace is optional. If present, it can only appear once. If not, the default domain is the domain from which the user loaded the user script.

Source: Greasemonkey Dive - Metadata

+9
Dec 22 '08 at 16:10
source share

The namespace can be a URL, but not only. You can use several words as a namespace as your username or name.

+1
03 Sep '15 at 21:56
source share



All Articles