GM.getValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (→‎Syntax: Including both possibilities for now... Thanks Gingerhendrix :))
(Explain what happens without a default.)
Line 4: Line 4:
== Description ==
== Description ==


This [[API_reference|API]] method retrieves a value that is set with [[GM_setValue]].
This [[API_reference|API]] method retrieves a value that was set with [[GM_setValue]]. If nothing was set and a default value is passed, it returns that default. Failing that, it returns undefined.


Values are saved in the [http://developer.mozilla.org/en/docs/Code_snippets:Preferences Firefox preferences] back end and can be manually changed by typing [[mozillazine:About:config|about:config]] in the address bar and searching for the preference name "greasemonkey.scriptval.''script-namespace''/''script-name''".
Values are saved in the [http://developer.mozilla.org/en/docs/Code_snippets:Preferences Firefox preferences] back end and can be manually changed by typing [[mozillazine:About:config|about:config]] in the address bar and searching for the preference name "greasemonkey.scriptval.''script-namespace''/''script-name''".
Line 26: Line 26:
|<code><span style="background:#FFFFE0;">[[#default |default]]</span></code>
|<code><span style="background:#FFFFE0;">[[#default |default]]</span></code>
|}
|}
:* All properties are optional except [[#name|name]].
:* All parameters are optional except [[#name|name]].


[[#top|top]]
[[#top|top]]
=== Properties ===
=== Parameters ===
----
----
==== <code>name</code> ====
==== <code>name</code> ====
Line 43: Line 43:
:Usage: <code>'''default''' = 5;</code>
:Usage: <code>'''default''' = 5;</code>


:* If [[GM_getValue#name|name]] is not found, then use this property to return a default value.
:* If [[GM_getValue#name|name]] is not found, default is returned. (With no default, 'undefined' is returned.)
: Note: Using this property does not call [[GM_setValue]] and is by design.
: Note: [[GM_setValue]] won't be called to set the value to the default, this is by design.


[[#top|top]] | [[#Syntax|back]]
[[#top|top]] | [[#Syntax|back]]

Revision as of 20:11, 21 August 2008

Template:Underscore


Description

This API method retrieves a value that was set with GM_setValue. If nothing was set and a default value is passed, it returns that default. Failing that, it returns undefined.

Values are saved in the Firefox preferences back end and can be manually changed by typing about:config in the address bar and searching for the preference name "greasemonkey.scriptval.script-namespace/script-name".

Examples | See Also | Notes

Syntax

GM_getValue( name, default )

Value: Function
Returns: String, Integer, Boolean, undefined and null[1]
Compatibility: Greasemonkey 0.3b+
Parameters
Properties
name
default
  • All parameters are optional except name.

top

Parameters


name

Value: String
Usage: name = "PropertyName";
  • Property name to retrieve.

top | back

default

Value: String, Integer or Boolean
Usage: default = 5;
  • If name is not found, default is returned. (With no default, 'undefined' is returned.)
Note: GM_setValue won't be called to set the value to the default, this is by design.

top | back

Examples

alert(GM_getValue("foo"));

top

See Also

top

Notes

top