GM.deleteValue: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Arantius moved page GM deleteValue to GM.deleteValue: Greasemonkey 4.0)
(Update for 4.0)
 
Line 1: Line 1:
{{DISPLAYTITLE:GM_deleteValue}}
== Description ==
== Description ==


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


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


== Syntax ==
== Syntax ==


{{Function|GM_deleteValue|name}}
{{Function|GM.deleteValue|name}}


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


== Arguments ==
== Arguments ==


; <code>name</code>
; <code>name</code>
: Property name to delete.  See [[GM_setValue#Arguments|GM_setValue]] for details on what names are valid.
: Property name to delete.  See [[GM.setValue#Arguments|GM.setValue]] for details on what names are valid.


== Returns ==
== Returns ==


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


== Examples ==
== Examples ==
Line 26: Line 24:
Delete the stored name / value pair that has the name 'foo':
Delete the stored name / value pair that has the name 'foo':
<pre class='sample'>
<pre class='sample'>
GM_deleteValue("foo");
GM.deleteValue("foo");
</pre>
</pre>


Example showing the use of [[GM_listValues]] to delete ''all'' stored name / value pairs:
Example showing the use of [[GM.listValues]] to delete ''all'' stored name / value pairs:
<pre class='sample'>
<pre class='sample'>
var keys = GM_listValues();
let keys = await GM.listValues();
for (var i=0, key=null; key=keys[i]; i++) {
for (let key of keys) {
   GM_deleteValue(key);
   GM.deleteValue(key);
}
}
</pre>
</pre>
Line 39: Line 37:
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion:  
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion:  
<pre class='sample'>
<pre class='sample'>
var keysToKeep = ['a','foo','bar'];
let keysToKeep = ['a', 'foo', 'bar'];
var keys = GM_listValues();
let keys = await GM.listValues();
for (var i=0, key=null; key=keys[i]; i++) {
for (let key of keys) {
   if(keysToKeep.indexOf(key) >= 0) {
   if (!keysToKeep.includes(key)) {
     continue;
     GM.deleteValue(key);
   }
   }
  GM_deleteValue(key);
}
}
</pre>
</pre>
Line 51: Line 48:
== See Also ==
== See Also ==


* [[GM_getValue]]
* [[GM.getValue]]
* [[GM_setValue]]
* [[GM.setValue]]
* [[GM_listValues]]
* [[GM.listValues]]
 
== Notes ==
 
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.


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