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
