GM.setValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Marti (talk | contribs)
m Undo revision 4131 by Aavindraa (Talk) Restored "sensical" statement
Lil Devil (talk | contribs)
replace _ with .
 
(24 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{underscore|title=GM_setValue}}
__NOTOC__
{{Greasemonkey Manual TOC}}
== Description ==
== Description ==


This [[API_reference|API]] method allows user script authors to persist simple values locally.
This method allows user script authors to persist simple values across page loads and across origins.


Strings, booleans, and integers are currently the only allowed data types.  
Strings, booleans, and integers are currently the only allowed data types.  
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 "<code>greasemonkey.scriptvals.[[Metadata_block#.40namespace|namespace]]/[[Metadata_block#.40name|name]].foo</code>".
The Firefox preference store is not designed for storing large amounts of data. There are no hard limits, but very large amounts of data may cause Firefox to consume more memory and/or run more slowly.<sup>[[#Notes|[1]]]</sup>
[[#Examples|Examples]] | [[#See_Also|See Also]] | [[#Notes|Notes]]


== Syntax ==
== Syntax ==


'''GM_setValue(''' ''name'', ''value'' ''')'''
{{Function|GM.setValue|name, value}}


:Value: Function
Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]]
:Returns: undefined<sup>[[Talk:GM_setValue|[2]]]</sup>
:Compatibility: [[Version_history#0.3_beta|Greasemonkey 0.3b+]]


:{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
=== Arguments ===
|+ Parameters
!style="background:#CC9900;"|'''Properties'''
|-
| <code><span style="background:#FFFFE0;">[[#name |name]]</span></code>
|-
|<code><span style="background:#FFFFE0;">[[#value |value]]</span></code>
|}
:* All properties are optional except [[#name|name]] and [[#value|value]].


[[#top|top]]
; <code>name</code>
=== Properties ===
: <code>String</code> The unique (within this script) name for this value.  Should be restricted to valid Javascript identifier characters.
----
; <code>value</code>
==== <code>name</code> ====
: <code>String</code>, <code>Integer</code> or <code>Boolean</code> Any valid value of these types.  Any other type may cause undefined behavior, including crashes.
:Value: String
:Usage: <code>'''name''' = "PropertyName";</code>


:* Property name to retrieve or create.
=== Returns ===


[[#top|top]] | [[#Syntax|back]]''
A [[Promise]], resolved successfully with no value on success, rejected with no value on failure.


==== <code>value</code> ====
== Examples ==
:Value: String, Integer or Boolean
:Usage: <code>'''value''' = 5;</code>


[[#top|top]] | [[#Syntax|back]]
Set the name foo to hold the value bar:


== Examples ==
<pre class='sample'>
{{Core samp |1=<pre style="border: none; margin: inherit;">
GM.setValue("foo", "bar");
GM_setValue("foo", "bar");
</pre>
</pre>}}
 
[[#top|top]]


== See Also ==
== See Also ==
* [[GM_getValue]]
* [[GM_deleteValue]]
* [[GM_listValues]]
[[#top|top]]


== Notes ==
* [[GM.getValue]]
<sup>[[GM_setValue#top|[1]]]</sup> Please see [http://groups.google.com/group/greasemonkey-users/t/ca5a0dfac5c5998b this mailing list thread] for details.
* [[GM.deleteValue]]
* [[GM.listValues]]


[[#top|top]]
[[Category:API_Reference|S]]
[[Category:API_Reference|S]]

Latest revision as of 00:26, 19 September 2018

Description

This method allows user script authors to persist simple values across page loads and across origins.

Strings, booleans, and integers are currently the only allowed data types.

Syntax

function GM.setValue( name, value )

Compatibility: Greasemonkey 4.0+

Arguments

name
String The unique (within this script) name for this value. Should be restricted to valid Javascript identifier characters.
value
String, Integer or Boolean Any valid value of these types. Any other type may cause undefined behavior, including crashes.

Returns

A Promise, resolved successfully with no value on success, rejected with no value on failure.

Examples

Set the name foo to hold the value bar:

GM.setValue("foo", "bar");

See Also