Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allows userscript files to work both as Greasemonkey scripts, and as BabelExt extensions
// Basically, dynamically selects between BabelExt and Greasemonkey methods,
// depending on what is avalaible at runtime
//
// Simply put this at the top of your userscript, and use BE_set/getValue
// exactly as you would BabelExt.storage.set/get
//
// However, there is also another argument passed to getValue, def, as in the
// default value if none can be retrieved (as in Greasemonkey's GM_getValue)
function BE_setValue(key, val, callback) {
if (typeof(BabelExt) != 'undefined') {
BabelExt.storage.set(key, val, callback);
} else {
GM_setValue(key, val);
callback.call();
}
}
function BE_getValue(key, def, callback) {
if (typeof(BabelExt) != 'undefined') {
BabelExt.storage.get(key, callback);
} else {
callback.call(this, GM_getValue(key, def));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.