So, been messing around with userscript lately, in tampermonkey. And hence had a few problems saving and loading with GM_setValue and GM_getValue. There are a couple of scrips out there to sort this for you, but none that i was able to get to work. So I’ve wrapped my own version up, which also compresses via LZstring. (google it).
For my purpose i found it most reliable to include whole libraries inside an anonymous function together with any code. This seem to help som scope issues I had, at a potential cost of performance (none that I have noticed tho). I’ve also included waitForKeyElement, cause it is nice to have at hand.
In principle the functions just wrap anything into an object (which you dont really need to do, but wth), stringifies, saves MD5, compresses, saves. And vice versa.
It does not work as expected with any data. Seems safe for sring, int, float, bool, undefined, null, objects and arrays. Does not work for NaN or functions as far as i can tell. Also not sure about “new Date()” objects and the like.
However for all intents and purposes it seem reliable enough.
The whole ting is included in a file further down, with some examples. Here are the main methods themselves.