Created
October 27, 2012 01:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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