GM.deleteValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Marti (talk | contribs)
m →‎Notes: Reply for VBm and altered note for the "workaround"... I've encountered this for quite some time and it's annoying in FF but manageable... sb
Update for 4.0
 
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{underscore|title=GM_deleteValue}}
__NOTOC__
{{Greasemonkey Manual TOC}}
== Description ==
== Description ==
This [[API_reference|API]] method deletes an existing preference set by [[GM_setValue]].


Values are deleted 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]].foo</code>".
This method deletes an existing name / value pair from storage.


[[#Examples|Examples]] | [[#See_Also|See Also]] | [[#Notes|Notes]]
See [[GM.setValue]] for details regarding the storage of these values.


== Syntax ==
== Syntax ==


'''GM_deleteValue(''' ''name'' ''')'''
{{Function|GM.deleteValue|name}}


:Value: Function
Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]]
:Returns: undefined
:Compatibility: [[Version_history#0.8.20090123.1|Greasemonkey 0.8.1+]]


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


[[#top|top]]
; <code>name</code>
=== Properties ===
: Property name to delete.  See [[GM.setValue#Arguments|GM.setValue]] for details on what names are valid.
----
==== <code>name</code> ====
:Value: String
:Usage: <code>'''name''' = "PropertyName";</code>


:* Property name to delete.
== Returns ==


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


== Examples ==
== Examples ==
{{Core samp |1=<pre style="border: none; margin: inherit;">
GM_deleteValue("foo");
</pre>}}


[[#top|top]]
Delete the stored name / value pair that has the name 'foo':
<pre class='sample'>
GM.deleteValue("foo");
</pre>


== See Also ==
Example showing the use of [[GM.listValues]] to delete ''all'' stored name / value pairs:
* [[GM_getValue]]
<pre class='sample'>
* [[GM_setValue]]
let keys = await GM.listValues();
* [[GM_listValues]]
for (let key of keys) {
  GM.deleteValue(key);
}
</pre>


[[#top|top]]
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion:
<pre class='sample'>
let keysToKeep = ['a', 'foo', 'bar'];
let keys = await GM.listValues();
for (let key of keys) {
  if (!keysToKeep.includes(key)) {
    GM.deleteValue(key);
  }
}
</pre>


== Notes ==
== See Also ==


An issue that some may encounter on some platforms is that the values appear to not be deleted or set. This is usually due to a refreshing issue in the browser. If about:config is refreshed in the window/tab this should resolve any questions about stability of setting and deleting system preferences.
* [[GM.getValue]]
* [[GM.setValue]]
* [[GM.listValues]]


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

Latest revision as of 14:23, 3 November 2017

Description

This method deletes an existing name / value pair from storage.

See GM.setValue for details regarding the storage of these values.

Syntax

function GM.deleteValue( name )

Compatibility: Greasemonkey 4.0+

Arguments

name
Property name to delete. See GM.setValue for details on what names are valid.

Returns

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

Examples

Delete the stored name / value pair that has the name 'foo':

GM.deleteValue("foo");

Example showing the use of GM.listValues to delete all stored name / value pairs:

let keys = await GM.listValues();
for (let key of keys) {
  GM.deleteValue(key);
}

Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion:

let keysToKeep = ['a', 'foo', 'bar'];
let keys = await GM.listValues();
for (let key of keys) {
  if (!keysToKeep.includes(key)) {
    GM.deleteValue(key);
  }
}

See Also