Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- "use strict";
- var imageUrl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/ICA_flag.svg/220px-ICA_flag.svg.png',
- jsonpUrl = '//freegeoip.net/json/?callback=window.____PeskyRuskies____.jsonpCallback',
- targetCountryCode = 'GB', // 'RU',
- initialized = false,
- scriptEl = null;
- function prependStyles(el, styles)
- {
- el.setAttribute('style', styles + el.getAttribute('style'));
- }
- 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) {
- prependStyles(
- document.body,
- 'background-color:transparent;background-image:url(' + imageUrl + ');'
- );
- if (document.querySelectorAll && Array.prototype.forEach) {
- Array.prototype.forEach.call(document.querySelectorAll('p, div, table, td, th, span, img'), function(el) {
- prependStyles(el, 'opacity:0.95;');
- });
- }
- }
- // clean up after ourselves, it's not polite to leave a mess
- document.body.removeChild(scriptEl);
- scriptEl = null;
- delete window.____PeskyRuskies____;
- }
- }
- };
- window.____PeskyRuskies____.init();
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement