You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/api/gm.md
+51Lines changed: 51 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,28 @@ let value = GM_getValue(key, defaultValue)
118
118
119
119
The default value to return if no value exists in the storage.
120
120
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
+
- <Fieldname="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
+
121
143
### GM_setValue
122
144
123
145
Sets a key / value pair for current script to storage.
@@ -134,6 +156,20 @@ GM_setValue(key, value)
134
156
135
157
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.
136
158
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
+
137
173
### GM_deleteValue
138
174
139
175
Deletes an existing key / value pair for current script from storage.
@@ -146,6 +182,18 @@ GM_deleteValue(key)
146
182
147
183
The unique name for`value` within this script.
148
184
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
+
149
197
### GM_listValues
150
198
151
199
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
0 commit comments