Created
November 6, 2008 19:46
-
-
Save rcrowley/22687 to your computer and use it in GitHub Desktop.
Allow Flickr Uploadr Extensions to store extra information for a user
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
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