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
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,24 +124,30 @@ let value = GM_getValue(key, defaultValue)
124
124
125
125
Retrieves multiple values for current script from storage.
126
126
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.**
131
128
132
-
- <Fieldname="what"type="string[] | Object" />
133
-
134
-
When providing an array of keys to read, the output will only contain keys that exist in storage:
135
129
```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'])
138
131
```
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
+
140
142
```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] })
143
144
```
144
145
146
+
| Keys in storage | Result |
147
+
|-|-|
148
+
| foo, bar |`{ foo: 123, bar: [1, 2, 3] }`|
149
+
| foo |`{ foo: 123, bar: [2] }`|
150
+
145
151
### GM_setValue
146
152
147
153
Sets a key / value pair for current script to storage.
0 commit comments