Skip to content

Commit 4889029

Browse files
committed
doc: improve clarity for GM_getValues
1 parent f4f8afb commit 4889029

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

content/api/gm.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,30 @@ let value = GM_getValue(key, defaultValue)
124124

125125
Retrieves multiple values for current script from storage.
126126

127-
```js
128-
let values = GM_getValues(['foo', 'bar'])
129-
let values2 = GM_getValues({ foo: 1, bar: [2] })
130-
```
127+
1. **Using an array of keys.**
131128

132-
- <Field name="what" type="string[] | Object" />
133-
134-
When providing an array of keys to read, the output will only contain keys that exist in storage:
135129
```js
136-
res = { foo: 123, bar: [1, 2, 3] } // all values were in storage
137-
res = { foo: 123 } // `bar` is missing
130+
let values = GM_getValues(['foo', 'bar'])
138131
```
139-
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:
132+
133+
| Keys in storage | Result |
134+
|-|-|
135+
| foo, bar | `{ foo: 123, bar: [1, 2, 3] }` |
136+
| foo | `{ foo: 123 }` |
137+
138+
2. **Using an object.**
139+
140+
Each key is a name to read from storage, the value is the default to be used in the result if the key was not in storage.
141+
140142
```js
141-
res = { foo: 123, bar: [1, 2, 3] } // all values were in storage
142-
res = { foo: 123, bar: [2] } // `bar` is missing, so your default value is used
143+
let values = GM_getValues({ foo: 1, bar: [2] })
143144
```
144145

146+
| Keys in storage | Result |
147+
|-|-|
148+
| foo, bar | `{ foo: 123, bar: [1, 2, 3] }` |
149+
| foo | `{ foo: 123, bar: [2] }` |
150+
145151
### GM_setValue
146152

147153
Sets a key / value pair for current script to storage.

0 commit comments

Comments
 (0)