I've written a Greasemonkey script that saves preferences using GM_SetValue
. Sometimes, if there's an issue with the script, I advise users to reload the script by removing it and re-installing. This blows away the stored values for the script, which is very inconvenient for the user.
Is there a better way to store this information? The state I need to store is per-page, using the URL as a key for GM_SetValue
, if that makes any difference.
Yes, you can copy the SQLite file that stores GM_setValue
data and preserve that information.
To find the data:
gm_scripts
folder therein..db
.// @name _Zombie GM_setValue fun
_Zombie_GM_setValue_fun.db
If you move or copy this file to a safe place, then do whatever to the script, then copy the file back; your data will be preserved. (As long as you don't change the script's @name
or @namespace
.)
You don't have to close Firefox while you do this, but I would -- to guard against edge-case mishaps.
Example script:
// ==UserScript==
// @name _Zombie GM_setValue fun
// @include https://stackoverflow.com/questions/28498610/*
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
var lastVal = GM_getValue ("LastValue");
var newVal = prompt (
'The last value was "' + (lastVal || "{not set}") + '". Enter a new value:',
''
);
if (newVal)
GM_setValue ("LastValue", newVal);
Test sequence:
The last value was "{not set}". Enter a new value:
.Save me
.The last value was "Save me". Enter a new value:
_Zombie_GM_setValue_fun.db
to a safe place."{not set}"
as in step 3._Zombie_GM_setValue_fun.db
back to the gm_scripts
folder, overwriting the newer _Zombie_GM_setValue_fun.db
if it is present.Save me
as in step 6.