GM.setValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Arantius moved page GM setValue to GM.setValue: Greasemonkey 4.0)
(replace _ with .)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:GM_setValue}}
== Description ==
== Description ==


This method allows user script authors to persist simple values across page-loads.
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.  


Since [[Version_history#1.13|Greasemonkey 1.13]] values are saved per userscript in a [https://developer.mozilla.org/en-US/docs/Storage SQLite] database <ref>Corresponding ticket for moving to SQLite: {{GitTicket|1798}}.</ref>. You can find the corresponding database by the userscript <code>basedir</code> as defined in the <code>[[config.xml]]</code>. The values are only accessible by opening the database is an SQLite reader, like add-on [https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/ SQLite Manager].
== Syntax ==
 
Compatibility: [[Version_history#0.3_beta|Greasemonkey 0.3b+]]


== Syntax ==
{{Function|GM.setValue|name, value}}


{{Function|GM_setValue|name, value}}
Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]]


=== Arguments ===
=== Arguments ===
Line 24: Line 20:
=== Returns ===
=== Returns ===


<code>undefined</code>
A [[Promise]], resolved successfully with no value on success, rejected with no value on failure.


== Examples ==
== Examples ==


Set the name foo to hold the value bar:
Set the name foo to hold the value bar:
<pre class='sample'>
<pre class='sample'>
GM_setValue("foo", "bar");
GM.setValue("foo", "bar");
</pre>
</pre>


== See Also ==
== See Also ==


* [[GM_getValue]]
* [[GM.getValue]]
* [[GM_deleteValue]]
* [[GM.deleteValue]]
* [[GM_listValues]]
* [[GM.listValues]]
* [[:Category:Coding Tips:Persistence]]
 
== References ==
 
<references/>


[[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