noun_type_proxytype = new CmdUtils.NounType( "Proxy Type", ["manual", "off", "auto", "pac"] ); CmdUtils.CreateCommand({ name: "proxy-set", homepage: "http://blog.monstuff.com/archives/000342.html", author: { name: "Julien Couvreur", email: "julien.couvreur@gmail.com" }, license: "MPL", description: "Toggles the browser's proxy setting on and off.", help: "This command lets you change the Connection Settings without having to open the Options and Proxy Settings windows. Invoke it with 'proxy-set off/manual/auto/pac'.", takes: { proxytype: noun_type_proxytype }, execute: function(proxytype) { var proxycode = this._getProxyCode(proxytype.text); if (proxycode == null) { displayMessage("Command not understood. Use 'proxy-set off/manual/auto/pac'."); return; } Application.prefs.setValue("network.proxy.type", proxycode); var msg = 'Proxy is set to: ${newProxytype}'; displayMessage(CmdUtils.renderTemplate( msg, {newProxytype: this._getProxyType(proxycode)} )); }, preview: function( pblock, proxytype ) { var oldProxycode = Application.prefs.get("network.proxy.type").value; var oldProxytype = this._getProxyType(oldProxycode); if (oldProxytype == null) { return; } var msg = 'Proxy is currently set to ${oldProxytype}'; pblock.innerHTML = CmdUtils.renderTemplate( msg, {oldProxytype: oldProxytype} ); }, _getProxyCode: function(proxyType) { switch (proxyType) { case "off": return 0; case "manual": return 1; case "auto": return 2; case "pac": return 4; default: return null; } }, _getProxyType: function(proxyCode) { switch (proxyCode) { case 0: return "off"; case 1: return "manual"; case 2: return "auto"; case 4: return "pac"; default: return null; } }, // todo: add interactive preview })