GM.listValues: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Text replace - "{{Samp |1=<pre style="border: none; margin: inherit;">" to "<pre class='sample'>")
(Update for 4.0)
(7 intermediate revisions by the same user not shown)
Line 3: Line 3:
== Description ==
== Description ==


This [[API_reference|API]] method retrieves an array of preference names that start with the branch's root.
This method retrieves an array of preference names that this script has stored.
See [[GM_setValue]] for details on the storage of these values.


Values are retrieved from the [http://developer.mozilla.org/en/docs/Code_snippets:Preferences Firefox preferences] back end and can be manually viewed 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]].</code>".
== Syntax ==


{{Function|GM.listValues|}}


Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]]


== Syntax ==
=== Arguments ===


'''GM_listValues()'''
None.


:Value: Function
=== Returns ===
:Returns: String Array
:Compatibility: [[Version_history#0.8.20090123.1|Greasemonkey 0.8.1+]]


:{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
A [[Promise]], rejected in case of error and otherwise resolved with an <code>Array</code> of <code>String</code>s for previously set values.
|+ Parameters
!style="background:#CC9900;"|'''Properties'''
|-
|}
:* There are currently no properties.


== Examples ==
== Examples ==
<pre class='sample'>
<pre class='sample'>
GM_log(GM_listValues());
console.log(await GM.listValues());
</pre>}}
</pre>


An array of values used by a script:
== See Also ==
{{Good samp |1=<pre style="border: none; margin: inherit;">
var vals = new Array();
for each(var val in GM_listValues())
    vals.push(GM_getValue(val));
</pre>}}


Equivalent:
* [[GM.getValue]]
{{Good samp |1=<pre style="border: none; margin: inherit;">
* [[GM.setValue]]
var vals = GM_listValues().map(GM_getValue);
* [[GM.deleteValue]]
</pre>}}
 
== See Also ==
* [[GM_getValue]]
* [[GM_setValue]]
* [[GM_deleteValue]]


[[Category:API_Reference|L]]
[[Category:API_Reference|L]]

Revision as of 14:29, 3 November 2017


Description

This method retrieves an array of preference names that this script has stored. See GM_setValue for details on the storage of these values.

Syntax

function GM.listValues( )

Compatibility: Greasemonkey 4.0+

Arguments

None.

Returns

A Promise, rejected in case of error and otherwise resolved with an Array of Strings for previously set values.

Examples

console.log(await GM.listValues());

See Also