Hi! I think, I understood it now. Maybe someone can confirm or correct?
Am Samstag, 17. Februar 2018 07:28:38 UTC+1 schrieb Stephan Hradek: > > I'm trying > https://www.greasespot.net/2017/09/greasemonkey-4-for-script-authors.html > > The issues I face are: > It only seems to works inside the async function. Is this intended? > Seems this is correct. So the "boilerplate" layout of a script would be something like // ==UserScript== // @name … // @grant GM.getValue // @grant GM.setValue // ==/UserScript== // Maybe some initialization code here (async function() { let value = *await* GM.getValue('myvariable' /*, a default value */); // do the stuff the script needs to do })(); // usually nothing more here It doesn't seem to work cross-domains, which I thought was one of the > purposes of GM_setValue, Was this dropped for GM.setValue? > As noted in a previous post I did not understand that persisted variables are per-script. So if you need a variable for more sites, make the script work on all of them. So a boilerplate for that could be // ==UserScript== // @name … // @grant GM.getValue // @grant GM.setValue // @include https://site1 // @include https://site2 // @include https://site3 // ==/UserScript== // Maybe some initialization code here var SITE= document.location.host; (async function() { let value = *await* GM.getValue('myvariable' /*, a default value */); switch(SITE) { case "site1": // call function for site1 break; case "site2": // call function for site2 break; case "site1": // call function for site1 break; case "site3": // call function for site3 break; default: // … break } })(); function for_site1() { } function for_site2() { } function for_site3() { } // usually nothing more here -- You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/greasemonkey-users. For more options, visit https://groups.google.com/d/optout.
