-
Notifications
You must be signed in to change notification settings - Fork 44
/
notificon.min.js
1 lines (1 loc) · 1.67 KB
/
notificon.min.js
1
(function(){var a=!1,b=function(){return a?!1:document.createElement("canvas").getContext?!0:(a=!0,console&&console.log("Notificon: requires canvas support"),!1)},c=function(a){a||(a={});var b={color:"#000000",stroke:"rgba(255,255,255,0.85)",favicon:e()};for(var c in b)a[c]||(a[c]=b[c]);return a},d=function(a){var b=document.getElementsByTagName("link");for(var c=0;c<b.length;c++){if(a&&/\bnotificon\b/i.test(b[c].getAttribute("rel")))return b[c];if(!a&&/\bicon\b/i.test(b[c].getAttribute("rel")))return b[c]}return!1},e=function(){var a=d();return a?a.getAttribute("href"):"/favicon.ico"},f=function p(){var a=d(!0);a&&(a.parentNode.removeChild(a),p())},g=function(a){var b=document.createElement("link");b.type="image/x-icon",b.rel="icon notificon",b.href=a,f(),document.getElementsByTagName("head")[0].appendChild(b)},h=function(a,b,c,d){var e=a.getContext("2d");e.font="10px monospace",e.fillStyle=c,e.textAlign="right",e.textBaseline="top",e.strokeStyle=d,e.lineWidth=4,e.strokeText(b,16,6),e.fillText(b,16,6)},i=function(a){var b=document.createElement("canvas");b.width=a.width,b.height=a.height;var c=b.getContext("2d");return c.drawImage(a,0,0),b},j=function(a,d){if(!b())return!1;var e=c(d);if(!a.length)return g(e.favicon);var f=document.createElement("img");return f.src=e.favicon,f.onload=function(){var b=i(f);a&&h(b,a,e.color,e.stroke);try{return g(b.toDataURL("image/png"))}catch(c){if(console)return console.log("Notificon: cannot use icons located on a different domain ("+favicon+")"),!1}},f.onerror=function(){if(console)return console.log("Notificon: image not found ("+e.favicon+")"),!1},!0},k=function(a,b){j(a,b)};typeof exports!="undefined"?module.exports=k:this.Notificon=k})(this);