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 *