Simple example for GM.getValue and GM-setValue needed

3,330 views
Skip to first unread message

Plenz

unread,
Nov 22, 2017, 5:30:29 PM11/22/17
to greasemonkey-users
I studied the GM wiki, I studied this group, but I don't get it. To be honest: I never heared about this asynchron stuff until today.

I found here in this group

let sData
= await GM.getValue("serialised") ;
let oData
= JSON.parse(sData) ;

but it does not work for me. Perhaps I have to declare or initialize "await" and "JSON", but I don't know.

Simple example:

GM.setValue("myvar", "foo");
var result = "empty";
var sData = await GM.getValue("myvar");
result = JSON.parse(sData);
alert(result);

What do I have to add and/or correct to get an alert which shows "foo"?

Thank you very much in advance for help. And whatever it is, it should be implemented in the GM wiki ASAP!

Anthony Lieuallen

unread,
Nov 23, 2017, 1:20:22 PM11/23/17
to greasemon...@googlegroups.com
I've just added another example to the end of this wiki section ("Complete end-to-end set and get example"):

https://wiki.greasespot.net/GM.getValue#Examples

Does that help you?  (It specifically calls out that if you set and then later want to get the same value, you must wait for the set to complete before the next get will see that just set value.  And also note that await only works in an async function.)
Message has been deleted

Plenz

unread,
Nov 23, 2017, 6:10:05 PM11/23/17
to greasemonkey-users
Thank you very much, I would never have figured out this async function.
Today it's too late, but tomorrow I will try your code!

Anthony Lieuallen

unread,
Nov 23, 2017, 6:50:38 PM11/23/17
to greasemon...@googlegroups.com
On Thu, Nov 23, 2017 at 6:08 PM, Plenz <pa...@lenz-online.de> wrote:
Thank you very much, I would never have figured out this async function.

Did you not read the announcement?

P.S. If you can't actually try it out, good netiquette would be to wait to respond until you've done so.

Plenz

unread,
Nov 24, 2017, 3:59:21 PM11/24/17
to greasemonkey-users
Thank you very much, the Wiki example works perfectly for me.

Yes, I read the announcement, but only partly. IMHO it is too long and contains too much theoretical stuff. I think, the Wiki is the better place for examples and solutions.

And regarding the nettiquette: I find it more polite to say "thank you" ASAP before you think "I answered to this guy and now 20 hours later I still don't know whether he read it at all".
Reply all
Reply to author
Forward
0 new messages