Skip to content

Instantly share code, notes, and snippets.

@rcrowley
Created November 6, 2008 19:46
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 rcrowley/22687 to your computer and use it in GitHub Desktop.
Save rcrowley/22687 to your computer and use it in GitHub Desktop.
Allow Flickr Uploadr Extensions to store extra information for a user
var data = {
_xpcom: Cc['@mozilla.org/preferences-service;1']
.getService(Ci.nsIPrefService)
.getBranch('opendns.'),
get: function(k) {
var t = this._xpcom.getPrefType(k);
var fn;
if (Ci.nsIPrefBranch.PREF_BOOL == t) { fn = 'getBoolPref'; }
else if (Ci.nsIPrefBranch.PREF_INT == t) { fn = 'getIntPref'; }
else { fn = 'getCharPref'; }
try { return this._xpcom[fn](k); }
catch (err) { return null; }
},
set: function(k, v) {
var t = typeof v;
if ('undefined' == t) { return false; }
var fn;
if ('boolean' == t) { fn = 'setBoolPref'; }
else if ('number' == t) { fn = 'setIntPref'; }
else { fn = 'setCharPref'; }
try {
this._xpcom[fn](k, v);
return true;
}
catch (err) { return false; }
},
unset: function(k) {
try { return this._xpcom.clearUserPref(k); }
catch (err) { return null; }
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment