Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DanielOaks
Created October 27, 2012 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielOaks/3962580 to your computer and use it in GitHub Desktop.
Save DanielOaks/3962580 to your computer and use it in GitHub Desktop.
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