User:Dani210/timeless.js

(function{ // Determine brightness of infobox image (typically a logo) and adjust background accordingly  var i=$('.infobox .infobox-image img');  if(i.length){    var wid=10,hei=10;    var c=document.createElement('canvas');    c.width=wid;    c.height=hei;    var d=c.getContext('2d');    // Need to create image object to explicitly allow CORS    var h=new Image;    h.crossOrigin = "Anonymous";    h.src=i[0].src;    // var image download    h.onload=function {      d.drawImage(h,0,0,wid,hei);      var e=d.getImageData(0,0,wid,hei).data;      var f=0,g=0;      // Loop through image data      for(var j=0,k=e.length; j= wid*4 && e[j+3-wid*4] == 0 // Look up      		|| j+wid*490) {            g++; // bright pixel          } else {            f++; // dark pixel          }        }      }      // Modify background if there are more dark edge pixels than light ones      if(f>g) {        var l=i.first.closest('.infobox-image');        if(l.width/3*2>i.width) {        	// Use a spotlight if image takes up less than 2/3 width of the infobox          l.css('background','radial-gradient(closest-side,#ccc 25%,transparent)');        } else {          l.css({'background-color':'#ccc','color':'black'}); }     }    };  } });