Show
Ignore:
Timestamp:
11/27/08 11:41:36 (6 weeks ago)
Author:
drry
Message:
  • fixed a typo. %s/regist\([ \n]\)\@=/&er/g
  • fixed a regex.
  • et cetera.
Files:
1 modified

Legend:

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

    r24976 r25044  
    3838 * 
    3939 */ 
    40 liberator.plugins.RefControl = (function(){ 
     40liberator.plugins.RefControl = (function() { 
    4141 
    4242const Cc = Components.classes; 
     
    7070 
    7171const completer_params = [['', 'send referrer:nothing'], 
    72     ['@FORGE', 'send referrer:top domain url'], 
    73     ['@NORMAL','send referrer:normal']]; 
     72    ['@FORGE', 'send referrer:top domain URL'], 
     73    ['@NORMAL', 'send referrer:normal']]; 
    7474 
    7575// icon manager object 
    76 var Class = function(){ return function(){this.initialize.apply(this, arguments);}}; 
     76var Class = function() function() {this.initialize.apply(this, arguments);}; 
    7777var RefControl = new Class(); 
    7878 
    7979RefControl.prototype = { 
    80   initialize : function(){ 
     80  initialize : function() { 
    8181    this.panel = this.createPanel(); 
    8282    this.isEnable = eval(liberator.globalVariables.refcontrol_enabled) || false; 
    8383  }, 
    84   createPanel: function(){ 
     84  createPanel: function() { 
    8585    var self = this; 
    8686    var panel = document.getElementById('refcontrol-status-panel'); 
    8787    if (panel) { 
    88       var parent = panel.parentNode; 
     88      let parent = panel.parentNode; 
    8989      parent.removeChild(panel); 
    9090    } 
     
    9898    return panel; 
    9999  }, 
    100   get isEnable(){ return _isEnable }, 
    101   set isEnable(val){ 
     100  get isEnable() _isEnable, 
     101  set isEnable(val) { 
    102102    this.panel.setAttribute('src', val ? ENABLE_ICON : DISABLE_ICON); 
    103103    _isEnable = val; 
    104104  }, 
    105 } 
     105}; 
    106106 
    107107// some utilities 
    108 var init = function(){ 
     108var init = function() { 
    109109  // read settings 
    110110  sites = liberator.globalVariables.refcontrol; 
    111111  if (typeof sites == 'undefined') sites = new Object(); 
    112112  if (typeof sites['@DEFAULT'] == 'undefined') sites['@DEFAULT'] = '@NORMAL'; 
    113 } 
    114  
    115 var dump = function(obj){ 
    116   var m=""; 
    117   for (var key in obj){ 
    118     m+=key+":"+obj[key]+"\n"; 
     113}; 
     114 
     115var dump = function(obj) { 
     116  var m = ''; 
     117  for (let key in obj) { 
     118    m+=key+':'+obj[key]+'\n'; 
    119119  } 
    120120  return m; 
    121 } 
     121}; 
    122122 
    123123init(); 
     
    125125 
    126126// add user command 
    127 commands.addUserCommand(['addref'], 'add referrer control setting' , function(args){ 
    128   let domain = args.arguments[0]; 
    129   let perf = args.arguments[1] || ''; 
     127commands.addUserCommand(['addref'], 'add referrer control setting', function(args) { 
     128  var domain = args.arguments[0]; 
     129  var perf = args.arguments[1] || ''; 
    130130  if (!domain || /[:\/]/.test(domain)) { 
    131131    liberator.echo(dump(sites)+'usage: addref [domain] [@NORMAL or @FORGE or empty]'); 
     
    133133  } 
    134134  sites[domain] = perf; 
    135   },{ 
    136     completer: function(context, arg, special){ 
    137       let last = context.contextList.slice(-1)[0]; 
     135  }, { 
     136    completer: function(context, arg, special) { 
     137      //var last = context.contextList.slice(-1)[0]; 
    138138      var args = arg.arguments; 
    139       let list; 
     139      var list; 
    140140      var pos = 0; 
    141141      if (args.length == 2) { 
    142         context.title = ['Params','Description']; 
     142        context.title = ['Params', 'Description']; 
    143143        list = completer_params; 
    144144        //pos = 1; 
    145145      } else if (args.length <= 1) { 
    146         context.title = ['Url','Description']; 
    147         list = [['@DEFAULT','default preference'], [window.content.location.host, '']]; 
     146        context.title = ['URL', 'Description']; 
     147        list = [['@DEFAULT', 'default preference'], [window.content.location.host, '']]; 
    148148      } 
    149149      context.completions = list; 
     
    153153); 
    154154 
    155 commands.addUserCommand(['togglerefcontrol'], 'toggle referrer control on/off',  
     155commands.addUserCommand(['togglerefcontrol'], 'toggle referrer control on/off', 
    156156  function() { 
    157157    manager.isEnable = !manager.isEnable; 
    158   },{} 
     158  }, {} 
    159159); 
    160160 
    161 // regist refcontrol 
    162 var adjustRef = function (http, site) { 
     161// register refcontrol 
     162var adjustRef = function(http, site) { 
     163  var sRef, refAction; 
    163164  try { 
    164     var sRef; 
    165     var refAction = sites[site]; 
     165    refAction = sites[site]; 
    166166    if (refAction == undefined) return false; 
    167     if (refAction.charAt(0) == '@'){ 
    168       switch (refAction){ 
     167    if (refAction.charAt(0) == '@') { 
     168      switch (refAction) { 
    169169        case '@NORMAL': 
    170170          return true; 
    171171        case '@FORGE': 
    172           sRef = http.URI.scheme + "://" + http.URI.hostPort + "/"; 
     172          sRef = http.URI.scheme + '://' + http.URI.hostPort + '/'; 
    173173          break; 
    174174        default: 
     
    176176      } 
    177177    } else if (refAction.length > 0) sRef = refAction; 
    178      
    179     http.setRequestHeader("Referer", sRef, false); 
     178 
     179    http.setRequestHeader('Referer', sRef, false); 
    180180    if (http.referrer) 
    181181      http.referrer.spec = sRef; 
     
    183183  } catch (e) {} 
    184184  return false; 
    185 } 
     185}; 
    186186 
    187187Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService).addObserver({ 
    188   observe: function(subject,topic,data){ 
     188  observe: function(subject, topic, data) { 
    189189    if (topic != 'http-on-modify-request') return; 
    190190    if (!_isEnable) return; 
    191191    var http = subject.QueryInterface(Ci.nsIHttpChannel); 
    192     for (var s = http.URI.host; s != ""; s = s.replace(/^.*?(\.|$)/, "")) 
     192    for (let s = http.URI.host; s != ''; s = s.replace(/^[^.]*(?:\.|$)/, '')) 
    193193      if (adjustRef(http, s)) return; 
    194194    adjustRef( http, '@DEFAULT'); 
    195195  } 
    196 },'http-on-modify-request',false); 
     196}, 'http-on-modify-request', false); 
    197197 
    198198return manager;