2011-01-16 12 views
0

次のJavaScriptコードの主な目的は何ですか?JScriptヘルプ?このJavaScriptコードの主な目的は何ですか?

<script> 

var QunarUtil=new function(){var prefix='/scripts/';var suffix='';var host='';if(location.host.indexOf('src.')!=-1){prefix='/scripts/src/';host='http://hstatic.qunar.com';suffix='.js';}else if(location.host.indexOf('enc.')!=-1){prefix='/scripts/';host='http://hstatic.qunar.com';suffix='.js';}else if(location.host.substring(0,10)=='sdev-'){prefix=location.host.substring(5,location.host.indexOf('.'));prefix='/'+prefix.replace(/\-/ig,'/');host='http://hstatic.qunar.com';suffix='.js';}else if(location.host.indexOf("h.qunar.com")!=-1){host='http://hstatic.qunar.com';suffix='';} 
this.getScriptURL=function(name,isList){if(name.charAt(0)!='/') 
return this.getScript(prefix+name,isList);else 
return this.getScript(name,isList);} 
this.getScript=function(src,isList){return'<'+'script type="text/javascript" src="'+host+src+(isList?suffix:'.js')+'?'+__QUNARVER__+'"></'+'script>';} 
this.writeScript=function(name,isList){document.write(this.getScriptURL(name,isList));} 
this.writeScriptList=function(list){for(var i=0;i<list.length;i++) 
document.write(this.getScriptURL(list[i]));} 
var cssRoot='/styles/';this.writeCSS=function(cssList){for(var i=0;i<cssList.length;i++){document.write('<link rel="stylesheet" href="'+cssRoot+cssList[i]+'?'+__QUNARVER__+'">');}} 
this.writeStaticScript=function(src){document.write('<scr'+'ipt type="text/javascript" src="'+src+'"></'+'scr'+'ipt>');} 
this.writeStaticList=function(src){document.write('<scr'+'ipt type="text/javascript" src="'+src+suffix+'?'+__QUNARVER__+'"></'+'scr'+'ipt>');}} 
$include=function(){for(var i=0;i<arguments.length;i++){QunarUtil.writeScript(arguments[i],true);}} 
</script> 

非圧縮バージョン:

<script> 
    var QunarUtil = new 
    function() { 
     var prefix = '/scripts/'; 
     var suffix = ''; 
     var host = ''; 
     if (location.host.indexOf('src.') != -1) { 
      prefix = '/scripts/src/'; 
      host = 'http://hstatic.qunar.com'; 
      suffix = '.js'; 
     } else if (location.host.indexOf('enc.') != -1) { 
      prefix = '/scripts/'; 
      host = 'http://hstatic.qunar.com'; 
      suffix = '.js'; 
     } else if (location.host.substring(0, 10) == 'sdev-') { 
      prefix = location.host.substring(5, location.host.indexOf('.')); 
      prefix = '/' + prefix.replace(/\-/ig, '/'); 
      host = 'http://hstatic.qunar.com'; 
      suffix = '.js'; 
     } else if (location.host.indexOf("h.qunar.com") != -1) { 
      host = 'http://hstatic.qunar.com'; 
      suffix = ''; 
     } 
     this.getScriptURL = function(name, isList) { 
      if (name.charAt(0) != '/') return this.getScript(prefix + name, isList); 
      else 
      return this.getScript(name, isList); 
     } 
     this.getScript = function(src, isList) { 
      return '<' + 'script type="text/javascript" src="' + host + src + (isList ? suffix : '.js') + '?' + __QUNARVER__ + '"></' + 'script>'; 
     } 
     this.writeScript = function(name, isList) { 
      document.write(this.getScriptURL(name, isList)); 
     } 
     this.writeScriptList = function(list) { 
      for (var i = 0; i < list.length; i++) 
      document.write(this.getScriptURL(list[i])); 
     } 
     var cssRoot = '/styles/'; 
     this.writeCSS = function(cssList) { 
      for (var i = 0; i < cssList.length; i++) { 
       document.write('<link rel="stylesheet" href="' + cssRoot + cssList[i] + '?' + __QUNARVER__ + '">'); 
      } 
     } 
     this.writeStaticScript = function(src) { 
      document.write('<scr' + 'ipt type="text/javascript" src="' + src + '"></' + 'scr' + 'ipt>'); 
     } 
     this.writeStaticList = function(src) { 
      document.write('<scr' + 'ipt type="text/javascript" src="' + src + suffix + '?' + __QUNARVER__ + '"></' + 'scr' + 'ipt>'); 
     } 
    } 
    $include = function() { 
     for (var i = 0; i < arguments.length; i++) { 
      QunarUtil.writeScript(arguments[i], true); 
     } 
    } 
</script> 
+0

どこから入手しましたか? – Sarfraz

+2

http://jsbeautifier.org/ – Neutralizer

+0

私は誰かがあなたのためにそのコードを解読するだろうと思う、それは読み込みできません。 –

答えて

4

JavaScriptとCSSファイルをhttp://hstatic.qunar.comから読み込むためのユーティリティです。 AS-IS、それは以下__QUNARVER__

と呼ばれるグローバル変数に依存するため、コードは動作しません

はインラインドキュメントとコードのverisonです。

//Expose the variable QunarUtil into the global namespace, which is an instance of an anonymous function. 
var QunarUtil = new function() { 
    //set up internal variable in QunarUtil 
    var prefix = '/scripts/'; 
    var suffix = ''; 
    var host = ''; 
    //Modify prefix, host & suffix if the current host (think webpage server 
    //address in the browser) has 'src.' as part of it's hostname. 
    if (location.host.indexOf('src.') != -1) { 
     prefix = '/scripts/src/'; 
     host = 'http://hstatic.qunar.com'; 
     suffix = '.js'; 
    //Modify prefix, host & suffix if the current host has 'enc.' as part of it's hostname. 
    } else if (location.host.indexOf('enc.') != -1) { 
     prefix = '/scripts/'; 
     host = 'http://hstatic.qunar.com'; 
     suffix = '.js'; 
    //Modify prefix, host & suffix if the current host is 'sdev-' (and nothing 
    //else since it is comparing a 5 char string with 10 char substring). 
    } else if (location.host.substring(0, 10) == 'sdev-') { 
     prefix = location.host.substring(5, location.host.indexOf('.')); 
     prefix = '/' + prefix.replace(/\-/ig, '/'); 
     host = 'http://hstatic.qunar.com'; 
     suffix = '.js'; 
    //Modify prefix, host & suffix if the current host has 'h.qunar.com' as part of it's hostname. 
    } else if (location.host.indexOf("h.qunar.com") != -1) { 
     host = 'http://hstatic.qunar.com'; 
     suffix = ''; 
    } 
    //Expose a method on the QunarUtil variable called getScriptURL. 
    this.getScriptURL = function(name, isList) { 
     if (name.charAt(0) != '/') 
      return this.getScript(prefix + name, isList); 
     else 
      return this.getScript(name, isList); 
    } 
    //Expose a method on the QunarUtil variable called getScript. 
    this.getScript = function(src, isList) { 
     return '<' + 'script type="text/javascript" src="' + host + 
       src + (isList ? suffix : '.js') + '?' + __QUNARVER__ + '"></' + 'script>'; 
    } 
    //Expose a method on the QunarUtil variable called writeScript. 
    this.writeScript = function(name, isList) { 
     document.write(this.getScriptURL(name, isList)); 
    } 
    //Expose a method on the QunarUtil variable called writeScriptList. 
    this.writeScriptList = function(list) { 
     for (var i = 0; i < list.length; i++) 
     document.write(this.getScriptURL(list[i])); 
    } 
    //Set a new internal QunarUtil variable. 
    var cssRoot = '/styles/'; 
    //Expose a method on the QunarUtil variable called writeCSS. 
    this.writeCSS = function(cssList) { 
     for (var i = 0; i < cssList.length; i++) { 
      document.write('<link rel="stylesheet" href="' + cssRoot + cssList[i] + '?' + __QUNARVER__ + '">'); 
     } 
    } 
    //Expose a method on the QunarUtil variable called writeStaticScript. 
    this.writeStaticScript = function(src) { 
     document.write('<scr' + 'ipt type="text/javascript" src="' + src + '"></' + 'scr' + 'ipt>'); 
    } 
    //Expose a method on the QunarUtil variable called writeStaticList. 
    this.writeStaticList = function(src) { 
     document.write('<scr' + 'ipt type="text/javascript" src="' + src + suffix + 
         '?' + __QUNARVER__ + '"></' + 'scr' + 'ipt>'); 
    } 
} 
//Expose a global variable called $inclue which take an arbitrary number 
//of JavaScript-file URLs as string arguments and loops over them to 
//create a bunch of <script> tags using the QunarUtil.writeScript method. 
$include = function() { 
    for (var i = 0; i < arguments.length; i++) { 
     QunarUtil.writeScript(arguments[i], true); 
    } 
} 

このコードは、好きな浮動Googleマップとは関係ありませんが、おそらくそのコードを読み込むために使用されます。

+0

ありがとう!マーティンしたがって、このスクリプトは、浮動するGoogleマップに関連する多くのjsファイルとcssファイルを「隠す」ためのものです。 – grandproducts

0

は、スクリプトローダのいくつかの種類のように見えます。

+0

こんにちは、このスクリプトはhttp://hotel.qunar.com/city/shenzhen/q-%E5%8D%8E%E4%BE%A8%E5%9F%8E#fromDate=2011-01-18&toDateからコピーされています。 = 2011-01-19&from = qunarHotel%7Cdiv **右側のGoogleマップが大好きなので、どのように動作するか知りたいです。ありがとうございました! – grandproducts

2

特定の場所からのスクリプトとスタイルシートの読み込みを容易にする機能がいくつかあります。

関連する問題