Changeset 9231 for lang/javascript

Show
Ignore:
Timestamp:
04/10/08 02:54:47 (5 years ago)
Author:
drry
Message:

lang/javascript/vimperator-plugins/trunk/proxy.js:

  • 整理しました。
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/proxy.js

    r8786 r9231  
    11/** 
    2  * vimperator plugin 
     2 * Vimperator plugin 
    33 * 
    4  * proxy setting plugin (for vimperator-0.6pre) 
     4 * proxy setting plugin (for Vimperator 0.6pre) 
    55 * 
    66 * @author cho45 
    77 * @author halt feits 
    8  * @version 0.6.1 
     8 * @version 0.6 
    99 */ 
    1010 
     
    1212 
    1313    const proxy_settings = [ 
    14     { 
    15         conf_name: 'disable', 
    16         conf_usage: 'direct connection', 
    17         setting: [ 
    18             { 
    19                 label: 'type', 
    20                 param: 0 
    21             } 
    22         ] 
    23     }, 
    24     { 
    25         conf_name: 'polipo', 
    26         conf_usage: 'use polipo cache proxy', 
    27         setting: [ 
    28             { 
    29                 label: 'type', 
    30                 param: 1 
    31             }, 
    32             { 
    33                 label: 'http', 
    34                 param: 'localhost' 
    35             }, 
    36             { 
    37                 label: 'http_port', 
    38                 param: 8123 
    39             } 
    40         ] 
    41     } 
     14        { 
     15            conf_name: 'disable', 
     16            conf_usage: 'direct connection', 
     17            settings: [ 
     18                { 
     19                    label: 'type', 
     20                    param: 0 
     21                } 
     22            ] 
     23        }, 
     24        { 
     25            conf_name: 'polipo', 
     26            conf_usage: 'use polipo cache proxy', 
     27            settings: [ 
     28                { 
     29                    label: 'type', 
     30                    param: 1 
     31                }, 
     32                { 
     33                    label: 'http', 
     34                    param: 'localhost' 
     35                }, 
     36                { 
     37                    label: 'http_port', 
     38                    param: 8123 
     39                } 
     40            ] 
     41        } 
    4242    ]; 
    4343 
    44     liberator.commands.addUserCommand(["proxy"], 'proxy settings', 
    45     function (args) { 
    46         const prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); 
     44    liberator.commands.addUserCommand(["proxy"], 'Proxy settings', function (args) { 
     45        const prefs = Components.classes["@mozilla.org/preferences-service;1"] 
     46                                .getService(Components.interfaces.nsIPrefService); 
    4747        var name = args; 
    4848        if (!name) { 
    4949            liberator.echo("Usage: proxy {setting name}"); 
    5050        } 
    51         for (var i = 0; i < proxy_settings.length; i++) { 
    52             var proxy_setting = proxy_settings[i]; 
    53             if (proxy_setting.conf_name.toLowerCase() == name.toLowerCase()) { 
     51        proxy_settings.some(function (proxy_setting) { 
     52            if (proxy_setting.conf_name.toLowerCase() != name.toLowerCase()) { 
     53                return false; 
     54            } 
    5455 
    55                 //delete setting 
    56                 ['http', 'ssl', 'ftp', 'gopher'].forEach( 
    57                         function (p) { 
    58                             prefs.setCharPref("network.proxy." + p, ''); 
    59                             prefs.setIntPref("network.proxy." + p + "_port", 0); 
    60                         } 
    61                 ); 
     56            //delete setting 
     57            ['http', 'ssl', 'ftp', 'gopher'].forEach(function (scheme_name) { 
     58                prefs.setCharPref("network.proxy." + scheme_name, ''); 
     59                prefs.setIntPref("network.proxy." + scheme_name + "_port", 0); 
     60            }); 
    6261 
    63                 for (var j = 0; j < proxy_setting.setting.length; j++) { 
    64                     var conf = proxy_setting.setting[j]; 
    65                     liberator.options.setPref('network.proxy.' + conf.label, conf.param); 
    66                 } 
     62            proxy_setting.settings.forEach(function (conf) { 
     63                liberator.options.setPref('network.proxy.' + conf.label, conf.param); 
     64            }); 
    6765 
    68                 liberator.echo("set config:" + name); 
    69                 break; 
    70             } 
    71         } 
     66            liberator.echo("Set config: " + name); 
     67            return true; 
     68        }); 
    7269    }, 
    7370    { 
    7471        completer: function (filter) { 
    7572            var completions = []; 
     73            var exp = new RegExp("^" + filter); 
    7674 
    77             for (var i = 0; i < proxy_settings.length; i++) { 
    78                 var name = proxy_settings[i].conf_name; 
    79                 var usage = proxy_settings[i].conf_usage; 
    80                  
    81                 var exp = new RegExp("^" + filter); 
    82  
     75            for each (let { conf_name: name, conf_usage: usage } in proxy_settings) { 
    8376                if (exp.test(name)) { 
    8477                    completions.push([name, usage]); 
     
    8881            return [0, completions]; 
    8982        } 
    90     } 
    91 ); 
     83    }); 
    9284 
    9385})();