I wrote one Greasemonkey/Tampermonkey script for Facebook . I needed to store data to retrieve it later. For that I used localStorage
.
That was working fine. But I noticed that after few hours all data which I stored was removed automagically. Probably Facebook itself deletes all localStorage data.
I searched for alternatives.
I want to store the data in the client system. What options do I have? Should I use FileSystem to store data?
Go to Chromes extensions page, enable the Allow access to file URLs checkbox at the Tampermonkey item, create a file with the file extensions . tamper. js and drag-and-drop it to Chrome.
The localStorage read-only property of the window interface allows you to access a Storage object for the Document 's origin; the stored data is saved across browser sessions.
Since you are using Tampermonkey (Chrome) and Greasemonkey (Firefox). Go ahead and use GM_setValue()
. It cannot be cleared by Facebook or by any other website.
It has the advantage of storing values cross-domain, as well.
~~~
Beware that the bog-standard GM_setValue()
is somewhat problematic on Firefox. It can cause a script instance to crash on invalid values -- So it's best to use a serializer, such as GM_SuperValue, to store anything but strings. Even innocent-looking integers can cause the default GM_setValue()
to crash.
Currently, only GM_setValue()
, cookies, localStorage, and IndexedDB are available for persistent data on both browsers.
IndexedDB would also probably do what you want, but it is nowhere as easy to use as GM_setValue()
.
Update:
Nowadays, don't forget to use:
// @grant GM_setValue
// @grant GM_getValue
Also, if you do use the GM_SuperValue library, you would now add it with:
// @require http://userscripts-mirror.org/scripts/source/107941.user.js
in the metadata block. (Since userscripts.org is long dead.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With