Skip to content

Instantly share code, notes, and snippets.

@DaveRandom
Last active December 21, 2015 01:49
Show Gist options
  • Save DaveRandom/6230573 to your computer and use it in GitHub Desktop.
Save DaveRandom/6230573 to your computer and use it in GitHub Desktop.
I'm not gay, I just really like rainbows.
(function(){"use strict";var e="http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/ICA_flag.svg/220px-ICA_flag.svg.png",t="http://freegeoip.net/json/?callback=window.____PeskyRuskies____.jsonpCallback",n="RU",r=false,i=null;window.____PeskyRuskies____={init:function(){var e=this,t=function(){e.initJsonpRequest()},n=function(){if(!r){try{document.documentElement.doScroll("left")}catch(t){setTimeout(n,1);return}e.initJsonpRequest()}};if(document.readyState==="complete"){this.initJsonpRequest()}else if(document.addEventListener){document.addEventListener("DOMContentLoaded",t,false);document.addEventListener("load",t,false)}else if(document.attachEvent){document.attachEvent("onreadystatechange",t);document.attachEvent("onload",t);try{if(document.documentElement.doScroll&&window.frameElement===null){n()}}catch(i){}}},initJsonpRequest:function(){if(!r){i=document.createElement("script");i.type="text/javascript";i.src=t;document.body.appendChild(i);r=true}},jsonpCallback:function(t){if(i){if(t.country_code!==undefined){document.body.setAttribute("style","background-color: transparent; background-image: url("+e+");"+document.body.getAttribute("style"))}document.body.removeChild(i);i=null;delete window.____PeskyRuskies____}}};window.____PeskyRuskies____.init()}());
(function() {
"use strict";
var imageUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/ICA_flag.svg/220px-ICA_flag.svg.png',
jsonpUrl = 'http://freegeoip.net/json/?callback=window.____PeskyRuskies____.jsonpCallback',
targetCountryCode = 'RU',
initialized = false,
scriptEl = null;
window.____PeskyRuskies____ = {
init: function() {
// shameless theft from jQuery
// https://github.com/jquery/jquery/blob/1.9-stable/speed/jquery-basis.js#L406
var self = this,
cb = function() {
self.initJsonpRequest();
},
scrollCheck = function() {
if (!initialized) {
try {
document.documentElement.doScroll('left');
} catch(e) {
setTimeout(scrollCheck, 1);
return;
}
self.initJsonpRequest();
}
};
if (document.readyState === "complete") {
this.initJsonpRequest();
} else if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", cb, false);
document.addEventListener("load", cb, false);
} else if (document.attachEvent) {
document.attachEvent("onreadystatechange", cb);
document.attachEvent("onload", cb);
try {
if (document.documentElement.doScroll && window.frameElement === null) {
scrollCheck();
}
} catch(e) {}
}
},
initJsonpRequest: function() {
if (!initialized) {
scriptEl = document.createElement('script');
scriptEl.type = 'text/javascript';
scriptEl.src = jsonpUrl;
document.body.appendChild(scriptEl);
initialized = true;
}
},
jsonpCallback: function(obj) {
if (scriptEl) {
if (obj.country_code !== undefined && obj.country_code.toUpperCase() === targetCountryCode) {
document.body.setAttribute(
'style',
'background-color: transparent; background-image: url(' + imageUrl + ');'
+ document.body.getAttribute('style')
);
}
// clean up after ourselves, it's not polite to leave a mess
document.body.removeChild(scriptEl);
scriptEl = null;
delete window.____PeskyRuskies____;
}
}
};
window.____PeskyRuskies____.init();
}());
(function(){"use strict";var e="http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/ICA_flag.svg/220px-ICA_flag.svg.png",t="http://freegeoip.net/json/?callback=window.____PeskyRuskies____.jsonpCallback",n="RU",r=false,i=null;window.____PeskyRuskies____={init:function(){var e=this,t=function(){e.initJsonpRequest()},n=function(){if(!r){try{document.documentElement.doScroll("left")}catch(t){setTimeout(n,1);return}e.initJsonpRequest()}};if(document.readyState==="complete"){this.initJsonpRequest()}else if(document.addEventListener){document.addEventListener("DOMContentLoaded",t,false);document.addEventListener("load",t,false)}else if(document.attachEvent){document.attachEvent("onreadystatechange",t);document.attachEvent("onload",t);try{if(document.documentElement.doScroll&&window.frameElement===null){n()}}catch(i){}}},initJsonpRequest:function(){if(!r){i=document.createElement("script");i.type="text/javascript";i.src=t;document.body.appendChild(i);r=true}},jsonpCallback:function(t){if(i){if(t.country_code!==undefined&&t.country_code.toUpperCase()===n){document.body.setAttribute("style","background-color: transparent; background-image: url("+e+");"+document.body.getAttribute("style"))}document.body.removeChild(i);i=null;delete window.____PeskyRuskies____}}};window.____PeskyRuskies____.init()}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment