a snippet for testing whether you could visit twtter or facebook

Some of you guys like add “Twitter button” or “Facebook Like button” on your website. But if your visitor from china that don’t use VPN or anyother jailbreak the G-F-W tools, it will slow down the page load until the browser’s default timeout time “60s”.
So i wrote this code snippet,now you can use this code snippet to test whether they could visit the Twitter or Facebook, if could then load the “Twitter button” or “Facebook Like button” scripts.

Enjoy it!

var Leeiio = {};
Leeiio.isFucked;
 
Leeiio.fuck = function(){
    var imgUrl = "http://twitter.com/favicon.ico?"; //You can change it to "http://www.facebook.com/favicon.ico?"
    imgUrl += new Date().getTime(); //add Time stamp to prevent the Browser's cache
    function removeElement(_element){
         var _parentElement = _element.parentNode;
         if(_parentElement){
                _parentElement.removeChild(_element);
         }
    }
    function testImg(isrc){
        var fuckimg = document.createElement('iframe'); //I used to createElement('img') but it have some problem in webkit
        fuckimg.src = imgUrl;
        fuckimg.style.cssText = "display:none";
        document.body.appendChild(fuckimg);
        fuckimg.timer = setTimeout(function(){
            alert("Fuck it!(You know fuck what right?)");
            fuckimg.src = null;
            fuckimg.onload = null;
            removeElement(fuckimg);
            Leeiio.isFucked = true;
        }, 3290);   //set timeout to connect to twitter
        fuckimg.onload = function (){
            clearTimeout(this.timer);
            alert("Nice!You are free man!");
            fuckimg.src = null;
            fuckimg.onload = null;
            removeElement(fuckimg);
            Leeiio.isFucked = false;
        }
    }
    testImg(imgUrl);
}
Leeiio.fuck();
 
var timeTest = setTimeout(function(){
    if(!Leeiio.isFucked){
        //add your code here that you want to
        alert('Fuck!');
    }
    clearTimeout(timeTest);
},4000);

See Demo here:http://leeiio.me/demo/fuck_yeah.html

13 Responses to a snippet for testing whether you could visit twtter or facebook

  1. ccaiai says:

    看不懂…但是對於廣大P民來說…連測試也不用測試,肯定上不去。
    昨晚剛訂閱完lz,Google reader就上不去了…哈哈

  2. Kevin Lynx says:

    As a chiness, of course i know what to fuck (in your demo)

  3. Kevin Lynx says:

    – -| 為什麼要用英文寫博客。。。

  4. Kimcool says:

    作為一個經常在牆上行走的人來說,F還是不F已經沒那麼重要了。。。

  5. 硬碟被格 says:

    這樣的確是很有必要,還有像一些外部的統計代碼如果資源載入不進來也悲催的勒~~~

  6. towry says:

    這個真的很有幫助!!Thx.

  7. Anonymous says:

    有 bug 啊,訪問頁面會自動彈出網頁顯示 twitter icon,這麼說你倒是成功繞過了 firefox 9.0.1 的彈窗攔截……

Leave a Reply

Your email address will not be published. Required fields are marked *