Skip to content

Commit bf97b13

Browse files
committed
doc: GM_getValues, GM_setValues, GM_deleteValues
1 parent 246d096 commit bf97b13

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

content/api/gm.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ let value = GM_getValue(key, defaultValue)
118118

119119
The default value to return if no value exists in the storage.
120120

121+
### GM_getValues
122+
123+
Retrieves multiple values for current script from storage.
124+
125+
```js
126+
let values = GM_getValues(['foo', 'bar'])
127+
let values2 = GM_getValues({ foo: 1, bar: [2] })
128+
```
129+
130+
- <Field name="what" type="string[] | Object" />
131+
132+
When providing an array of keys to read, the output will only contain keys that exist in storage:
133+
```js
134+
res = { foo: 123, bar: [1, 2, 3] } // all values were in storage
135+
res = { foo: 123 } // `bar` is missing
136+
```
137+
When providing an object, its keys are names to read from storage and values are the defaults to be used in the output object if the value was not in storage:
138+
```js
139+
res = { foo: 123, bar: [1, 2, 3] } // all values were in storage
140+
res = { foo: 123, bar: [2] } // `bar` is missing, so your default value is used
141+
```
142+
121143
### GM_setValue
122144

123145
Sets a key / value pair for current script to storage.
@@ -134,6 +156,20 @@ GM_setValue(key, value)
134156

135157
The value to be stored, which must be *JSON serializable* (string, number, boolean, null, or an array/object consisting of these types) so for example you can't store DOM elements or objects with cyclic dependencies.
136158
159+
### GM_setValues
160+
161+
Writes multiple values to current script's storage.
162+
163+
```js
164+
GM_setValues({ foo: 1, bar: [1, 2, 3] })
165+
```
166+
167+
- <Field name="data" type="Object" />
168+
169+
Each `key:value` pair in the object will be stored individually, so the example above is basically a more efficient version of `GM_setValue('foo', 1); GM_setValue('bar', [1, 2, 3]);`
170+
171+
Must be *JSON serializable* (see [GM_setValue](#gm_setvalue)).
172+
137173
### GM_deleteValue
138174

139175
Deletes an existing key / value pair for current script from storage.
@@ -146,6 +182,18 @@ GM_deleteValue(key)
146182

147183
The unique name for `value` within this script.
148184

185+
### GM_deleteValues
186+
187+
Deletes values with the specified keys in current script's storage.
188+
189+
```js
190+
GM_deleteValues(['foo', 'bar'])
191+
```
192+
193+
- <Field name="keys" type="string[]" />
194+
195+
Array of keys to delete.
196+
149197
### GM_listValues
150198
151199
Returns an array of keys of all available values within this script.
@@ -705,15 +753,18 @@ Returns a control object with the following properties, same as [GM_xmlhttpReque
705753
* [GM.addElement](#gm_addelement) - *since VM2.13.1*
706754
* [GM.registerMenuCommand](#gm_registermenucommand) - *since VM2.12.10, GM4.11*
707755
* [GM.deleteValue](#gm_deletevalue) *(async)*
756+
* [GM.deleteValues](#gm_deletevalues) *since VM2.19.1 (async)*
708757
* [GM.download](#gm_download) *(async since VM2.18.3)*
709758
* [GM.getResourceUrl](#gm_getresourceurl) *(async)* - in VM2.12.0...2.13.0 it was misspelled as `GM.getResourceURL`
710759
* [GM.getValue](#gm_getvalue) *(async)*
760+
* [GM.getValues](#gm_getvalues) *since VM2.19.1 (async)*
711761
* [GM.info](#gm_info)
712762
* [GM.listValues](#gm_listvalues) *(async)*
713763
* [GM.notification](#gm_notification)
714764
* [GM.openInTab](#gm_openintab)
715765
* [GM.setClipboard](#gm_setclipboard)
716766
* [GM.setValue](#gm_setvalue) *(async)*
767+
* [GM.setValues](#gm_setvalues) *since VM2.19.1 (async)*
717768
* [GM.xmlHttpRequest](#gm_xmlhttprequest) *(async since VM2.18.3)*, `H` is uppercase
718769

719770
```js

0 commit comments

Comments
 (0)