From a13cbb754f6c10bd2f55e7bcc0b6990307ec1a7b Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Thu, 7 Nov 2013 21:16:50 +0900 Subject: [PATCH] Update library --- modules/lib/prefs.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/modules/lib/prefs.js b/modules/lib/prefs.js index 89ae97fe..b3f12063 100644 --- a/modules/lib/prefs.js +++ b/modules/lib/prefs.js @@ -42,7 +42,7 @@ if (typeof window == 'undefined' || } (function() { - const currentRevision = 10; + const currentRevision = 13; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; @@ -103,24 +103,50 @@ if (typeof window == 'undefined' || } }, + getLocalizedPref : function(aPrefstring) + { + try { + return this.getPref(aPrefstring, Ci.nsIPrefLocalizedString).data; + } catch(e) { + return this.getPref(aPrefstring); + } + }, + getDefaultPref : function(aPrefstring, aInterface) { return this.getPref(aPrefstring, this.DefaultPrefs, aInterface); }, - setPref : function(aPrefstring, aNewValue, aBranch) + setPref : function(aPrefstring, aNewValue) { - aBranch = aBranch || this.Prefs; + var branch = this.Prefs; + var interface = null; + if (arguments.length > 2) { + for (let i = 2; i < arguments.length; i++) + { + let arg = arguments[i]; + if (!arg) + continue; + if (arg instanceof Ci.nsIPrefBranch) + branch = arg; + else + interface = arg; + } + } + if (interface && + aNewValue instanceof Ci.nsISupports) { + return branch.setComplexValue(aPrefstring, interface, aNewValue); + } switch (typeof aNewValue) { case 'string': - return aBranch.setCharPref(aPrefstring, unescape(encodeURIComponent(aNewValue))); + return branch.setCharPref(aPrefstring, unescape(encodeURIComponent(aNewValue))); case 'number': - return aBranch.setIntPref(aPrefstring, parseInt(aNewValue)); + return branch.setIntPref(aPrefstring, parseInt(aNewValue)); default: - return aBranch.setBoolPref(aPrefstring, !!aNewValue); + return branch.setBoolPref(aPrefstring, !!aNewValue); } }, @@ -145,7 +171,8 @@ if (typeof window == 'undefined' || { var foundChildren = {}; var possibleChildren = []; - var actualChildren = this.getDescendant(aRoot, aBranch) + var actualChildren = []; + this.getDescendant(aRoot, aBranch) .forEach(function(aPrefstring) { var name = aPrefstring.replace(aRoot, ''); if (name.charAt(0) == '.')