Skip to content

Instantly share code, notes, and snippets.

@adrianbj
Created January 31, 2019 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianbj/9b6081e0d846ecb5e8ba4d6457d9b7ad to your computer and use it in GitHub Desktop.
Save adrianbj/9b6081e0d846ecb5e8ba4d6457d9b7ad to your computer and use it in GitHub Desktop.
/*!
* Tinycon - A small library for manipulating the Favicon
* Tom Moor, http://tommoor.com
* Copyright (c) 2015 Tom Moor
* @license MIT Licensed
*/
!function(){var e,t={},n=null,o=null,i=null,r=null,a={},l=Math.ceil(window.devicePixelRatio)||1,c=16*l,u={width:7,height:9,font:10*l+"px arial",color:"#ffffff",background:"#F03D25",fallback:!0,crossOrigin:!0,abbreviate:!0},f=(e=navigator.userAgent.toLowerCase(),function(t){return-1!==e.indexOf(t)}),d=f("trident"),h=(f("chrome"),f("chrome")||f("safari")),g=f("safari")&&!f("chrome"),m=f("mozilla")&&!f("chrome")&&!f("safari"),s=function(){if(!o||!n){var e=function(){for(var e=document.getElementsByTagName("link"),t=0,n=e.length;t<n;t++)if((e[t].getAttribute("rel")||"").match(/\bicon\b/i))return e[t];return!1}();n=e?e.getAttribute("href"):"/favicon.ico",o||(o=n)}return n},b=function(){return r||((r=document.createElement("canvas")).width=c,r.height=c),r},v=function(e){if(e){!function(){for(var e=document.getElementsByTagName("link"),t=0,n=e.length;t<n;t++)void 0!==e[t]&&(e[t].getAttribute("rel")||"").match(/\bicon\b/i)&&e[t].parentNode.removeChild(e[t])}();var t=document.createElement("link");t.type="image/x-icon",t.rel="icon",t.href=e,document.getElementsByTagName("head")[0].appendChild(t)}},T=function(e){if(a.fallback){var t=document.title;"("===t[0]&&(t=t.slice(t.indexOf(" "))),document.title=(e+"").length>0?"("+e+") "+t:t}},k=function(e,t,n){"number"==typeof t&&t>99&&a.abbreviate&&(t=p(t));var o=(t+"").length-1,i=a.width*l+6*l*o,r=a.height*l,u=c-r,f=c-i-l,d=16*l,g=16*l,s=2*l;e.font=(h?"bold ":"")+a.font,e.fillStyle=a.background,e.strokeStyle=a.background,e.lineWidth=l,e.beginPath(),e.moveTo(f+s,u),e.quadraticCurveTo(f,u,f,u+s),e.lineTo(f,d-s),e.quadraticCurveTo(f,d,f+s,d),e.lineTo(g-s,d),e.quadraticCurveTo(g,d,g,d-s),e.lineTo(g,u+s),e.quadraticCurveTo(g,u,g-s,u),e.closePath(),e.fill(),e.beginPath(),e.strokeStyle="rgba(0,0,0,0.3)",e.moveTo(f+s/2,d),e.lineTo(g-s/2,d),e.stroke(),e.fillStyle=a.color,e.textAlign="right",e.textBaseline="top",e.fillText(t,2===l?29:15,m?7*l:6*l)},y=function(){b().getContext&&v(b().toDataURL())},p=function(e){for(var t=[["G",1e9],["M",1e6],["k",1e3]],n=0;n<t.length;++n)if(e>=t[n][1]){e=x(e/t[n][1])+t[n][0];break}return e},x=function(e,t){return new Number(e).toFixed(t)};t.setOptions=function(e){a={},e.colour&&(e.color=e.colour);for(var t in u)a[t]=e.hasOwnProperty(t)?e[t]:u[t];return this},t.setImage=function(e){return n=e,y(),this},t.setBubble=function(e,t){return function(e,t){if(!b().getContext||d||g||"force"===a.fallback)return T(e);var n=b().getContext("2d"),o=(t=t||"#000000",s());(i=document.createElement("img")).onload=function(){n.clearRect(0,0,c,c),n.drawImage(i,0,0,i.width,i.height,0,0,c,c),(e+"").length>0&&k(n,e,t),y()},i.onload(),!o.match(/^data/)&&a.crossOrigin&&(i.crossOrigin="anonymous"),i.src=o}(e=e||"",t),this},t.reset=function(){n=o,v(o)},t.setOptions(u),"function"==typeof define&&define.amd?define(t):"undefined"!=typeof module?module.exports=t:window.Tinycon=t}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment