Jscript help? What is the main purpose of this Javascript?

Posted by user577363 on Stack Overflow See other posts from Stack Overflow or by user577363
Published on 2011-01-16T08:31:37Z Indexed on 2011/01/16 8:53 UTC
Read the original article Hit count: 160

Filed under:

Dear All, I don't know Javascript, can you please show me the main purpose of this Javascript?

Many Thanks!!

<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>

Uncompressed version:

<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>

© Stack Overflow or respective owner

Related posts about JavaScript