1. 程式人生 > >近期在看的一段JS(誰能看出我想實現什麼功能)

近期在看的一段JS(誰能看出我想實現什麼功能)

示例程式碼:

<script type="text/javascript">
!function(){
    var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,
    r=window.location.href,
    o=document.referrer;
    // console.log(e);
    // console.log(r);
    // console.log(o);
    if(!e.test(r)){ // 為了防止 這個網址是百度自家的產品
        // console.log('a');
var n="//api.share.baidu.com/s.gif"; o?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r); var t=new Image; t.src=n; console.log(t); }; // if(!e.test('http://www.baidu.com/')){ // console.log('a'); // }else{
// console.log('b'); // }; }(window); </script>

深入探討:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="http://127.0.0.1/1/1.html">3.html</a>
<a href="http://127.0.0.1/1/2.html"
>2.html</a> <a href="http://127.0.0.1/1/3.html">1.html</a> <a href="http://127.0.0.1/1/4.html">2.html</a> <a href="http://127.0.0.1/1/5.html">1.html</a> <a href="http://127.0.0.1/1/6.html">2.html</a> <a href="http://127.0.0.1/1/7.html">2.html</a> <a href="http://127.0.0.1/1/8.html">2.html</a> <a href="http://127.0.0.1/1/9.html">2.html</a> <a href="http://127.0.0.1/1/10.html">2.html</a> <a href="http://127.0.0.1/1/11.html">2.html</a> <a href="http://127.0.0.1/1/12.html">2.html</a> <a href="http://127.0.0.1/1/13.html">2.html</a> <a href="http://127.0.0.1/1/14.html">2.html</a> <a href="http://127.0.0.1/1/15.html">2.html</a> <a href="http://127.0.0.1/1/16.html">2.html</a> <a href="http://127.0.0.1/1/17.html">2.html</a> <a href="http://127.0.0.1/1/18.html">2.html</a> <a href="http://127.0.0.1/1/19.html">2.html</a> <a href="http://127.0.0.1/1/20.html">2.html</a> </body> <script type="text/javascript"> var list = document.getElementsByTagName("a"); var n = "//api.share.baidu.com/s.gif"; var r = window.location.href; var url = []; for(var i=0;i<list.length;++i){ url.push(n+'?r='+encodeURIComponent(list[i].href)+'&l='+r); }; for(var i=0;i<5;++i){ var t = new Image; t.src = url[Math.round(Math.random() * list.length)]; }; // var m = Math.round(Math.random() * list.length); // api.share.baidu.com/s.gif?r=http%3A%2F%2F127.0.0.1%2F1%2F3.html&l=http://127.0.0.1/1/3.html // api.share.baidu.com/s.gif?r=http%3A%2F%2F127.0.0.1%2F1%2F3.html&l=http://127.0.0.1/2.html </script> </html>

誰能看出我想要實現什麼功能。