使用者:BobChao/Snippets
出自 MozTW Wiki
修改設定
研究 XPI 快速設定精靈時的東西,先丟出來。
<script type="application/x-javascript">
<![CDATA[
const HOMEPAGE = "http://leolo.ath.cx/~bobchao/";
const PROXY_AUTO_CONFIG = "http://proxy.nsysu.edu.tw/proxy.pac";
const prefInt = 0;
const prefBool = 1;
const prefStr = 2;
const nsISupportsString = Components.interfaces.nsISupportsString;
const nsSupportsString_CONTRACTID = "@mozilla.org/supports-string;1";
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsPrefService_CONTRACTID = "@mozilla.org/preferences-service;1";
const gPrefService = Components.classes[nsPrefService_CONTRACTID].getService(nsIPrefService);
const gPrefBranch = PrefService.getBranch(null).QueryInterface(Components.interfaces.nsIPrefBranchInternal);
function doSetProxy(){
doModiftPrefs(prefStr, "network.proxy.autoconfig_url", PROXY_AUTO_CONFIG);
doModiftPrefs(prefInt, "network.proxy.type", 2);
}
function doSetHomepage(){
doModiftPrefs(prefStr, "browser.startup.homepage", HOMEPAGE);
}
function doModiftPrefs(type, entry, value){
try {
switch (type){
case 0:
gPrefBranch.setIntPref(entry, value);
break;
case 1:
gPrefBranch.setBoolPref(entry, value);
break;
case 2:
var supportsString = Components.classes[nsSupportsString_CONTRACTID].createInstance(nsISupportsString);
supportsString.data = value;
gPrefBranch.setComplexValue(entry, nsISupportsString, supportsString);
break;
}
}
catch(e){ alert(e); } //還不知道要怎麼處理
}
]]>
</script>
