forked from lipka/piecon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiecon.min.js
5 lines (5 loc) · 2.05 KB
/
piecon.min.js
1
2
3
4
5
(function(){var i={},j=null,k=null,h=null,g=null,f={},l={color:"#ff0084",background:"#bbb",shadow:"#fff",fallback:!1},e,p=navigator.userAgent.toLowerCase();e=function(c){return-1!==p.indexOf(c)};var q=e("msie");e("chrome");e("chrome")||e("safari");var r=e("safari")&&!e("chrome");e("mozilla")&&!e("chrome")&&e("safari");var m=function(c){for(var a=document.getElementsByTagName("link"),e=document.getElementsByTagName("head")[0],f=0,h=a.length;f<h;f++)"undefined"!==typeof a[f]&&"icon"===a[f].getAttribute("rel")&&
e.removeChild(a[f]);a=document.createElement("link");a.type="image/x-icon";a.rel="icon";a.href=c;document.getElementsByTagName("head")[0].appendChild(a)},n=function(){g||(g=document.createElement("canvas"),g.width=16,g.height=16);return g},o=function(c){f.fallback&&(document.title=0<c?"("+c+"%) "+h:h)};i.setOptions=function(c){f={};for(var a in l)f[a]=c.hasOwnProperty(a)?c[a]:l[a];return this};i.setProgress=function(c){h||(h=document.title);if(!k||!j){var a;a:{a=document.getElementsByTagName("link");
for(var e=0,i=a.length;e<i;e++)if((a[e].getAttribute("rel")||"").match(/\bicon\b/)){a=a[e];break a}a=!1}k=j=a?a.getAttribute("href"):"/favicon.ico"}if(!isNaN(parseFloat(c))&&isFinite(c)){if(!n().getContext||q||r||!0==f.fallback)return o(c);"force"===f.fallback&&o(c);var g=c,b=n(),d=b.getContext("2d"),g=g||0,c=j;a=new Image;a.onload=function(){d.clearRect(0,0,16,16);d.beginPath();d.moveTo(b.width/2,b.height/2);d.arc(b.width/2,b.height/2,Math.min(b.width/2,b.height/2),0,Math.PI*2,false);d.fillStyle=
f.shadow;d.fill();d.beginPath();d.moveTo(b.width/2,b.height/2);d.arc(b.width/2,b.height/2,Math.min(b.width/2,b.height/2)-2,0,Math.PI*2,false);d.fillStyle=f.background;d.fill();if(g>0){d.beginPath();d.moveTo(b.width/2,b.height/2);d.arc(b.width/2,b.height/2,Math.min(b.width/2,b.height/2)-2,-0.5*Math.PI,(-0.5+2*g/100)*Math.PI,false);d.lineTo(b.width/2,b.height/2);d.fillStyle=f.color;d.fill()}d&&m(b.toDataURL())};c.match(/^data/)||(a.crossOrigin="anonymous");a.src=c}else return!1};i.reset=function(){h&&
(document.title=h);k&&(j=k,m(j))};i.setOptions(l);window.Piecon=i})();