PuciekTM / Stupka

// ==UserScript==
// @name         Stupka
// @namespace    puciek.ct8.pl
// @version      1.0.0
// @description  epilepsja alert
// @author       Puciek
// @include      *
// @noframes
// ==/UserScript==
//ps to jest bezpieczne
function Takeover(ratio, imageurl) {
  this.ratio = ratio;
  this.imageurl = imageurl
}
      
var getTakeover = {
  init: function (myTakeover) {
    this.myTakeover = myTakeover
  },
  horizontal: function () {
    return this.myTakeover.filter(function (myTakeover) {
      return myTakeover.ratio === "horizontal";
    });
  },
  vertical: function () {
    return this.myTakeover.filter(function (myTakeover) {
      return myTakeover.ratio === "vertical";
    });
  },
  square: function () {
    return this.myTakeover.filter(function (myTakeover) {
      return myTakeover.ratio === "square";
    });
  }
};

function Randomize(images) {
  return Math.floor(Math.random() * images.length);
}

var myTakeover = [
  new Takeover("horizontal", "http://static.berkeleywellness.com/files/field/image/400-06178255c_998_380.jpg"),
  new Takeover("horizontal", "https://edc2.healthtap.com/ht-staging/user_answer/reference_image/10911/large/foot.jpeg?1386670708"),
  new Takeover("horizontal", "http://cleatsreport.com/wp-content/uploads/2014/12/best-soccer-cleats-for-wide-feet.jpg"),
  new Takeover("horizontal", "http://www.prevention.com/sites/prevention.com/files/styles/article_main_image_2200px/public/images/articles/featured_images/comp-3594860-footpain628x363.jpg?itok=3upjI3B7"), 
  new Takeover("horizontal", "http://www.footcaresupplies.com/media/images/rubbing-foot.png"),
  new Takeover("vertical", "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f7/Male_Right_Foot_2.jpg/328px-Male_Right_Foot_2.jpg"),
  new Takeover("vertical", "https://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr06/22/12/grid-cell-3281-1382460328-4.jpg"),
  new Takeover("vertical", "http://mindtws.org.uk/wp-content/uploads/2014/10/Foot-Massage-11.jpg"),
  new Takeover("vertical", "http://www.healthwatchcenter.com/wp-content/uploads/2014/10/healthy-regime-for-your-feet.jpg"),
  new Takeover("vertical", "http://book-med.info/img/941/25111_f520326.jpg"),
  new Takeover("square", "http://www.footcentersoftexas.com/sbtemplates/sbcommon/images/blog/63_WorkFeet.jpg"),
  new Takeover("square", "https://www.painscience.com/imgs/ebook-avatar-pf-s.jpg"),
  new Takeover("square", "http://4.bp.blogspot.com/-og1erHry2tw/UEYo7rHQTkI/AAAAAAAAWUQ/XgXDxVbVvQ4/s1600/womans-feet.jpg"),
  new Takeover("square", "http://www.footcaresupplies.com/media/images/rubbing-foot.png"),
  new Takeover("square", "http://www.healthcentral.com/sites/www.healthcentral.com/files/feet_2.jpg")
];

      
function imageRatio(image) {
  var proportion = image.height / image.width;
  if (proportion > 1) return "vertical";
  else if (proportion === 1) return "square";
  else if (proportion < 1) return "horizontal"
}
      
function runBookmarklet(target) {
  var images = (target || document).getElementsByTagName("img");
  var length = images.length;

  getTakeover.init(myTakeover);
  for (var i = 0; i < length; i++) {
    var ratio = imageRatio(images[i]);
    if (ratio === "horizontal") {
      var number = Randomize(getTakeover.horizontal());
      var img = getTakeover.horizontal()[number];
      images[i].src = img.imageurl
    } else if (ratio === "square") {
      var number = Randomize(getTakeover.square());
      var img = getTakeover.square()[number];
      images[i].src = img.imageurl
    } else if (ratio === "vertical") {
      var number = Randomize(getTakeover.vertical());
      var img = getTakeover.vertical()[number];
      images[i].src = img.imageurl
    }
  }
}
window.setInterval(function(){
  runBookmarklet();
}, 1000);
runBookmarklet();